-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTones.ino
More file actions
30 lines (26 loc) · 1.13 KB
/
Copy pathTones.ino
File metadata and controls
30 lines (26 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Play the selected tone
// This is a synchronous (blocking) call. The function doesn't return until the
// tone has been played. This works fine for this application, but it could be
// done using a timer interrupt and a lot more (complicated) code.
#include "pitches.h"
const int tones[MAX_TUNES][17] = {
{NOTE_C5,8,NOTE_G4,8,-1}, // TUNE_STARTUP
{NOTE_F5,30,-1}, // TUNE_TOP_BUTTON_PRESS
{NOTE_B5,20,-1}, // TUNE_BOTTOM_BUTTON_PRESS
{NOTE_C5,4,NOTE_G4,8,NOTE_G4,8, NOTE_A4,4,NOTE_G4,4,0,4,NOTE_B4,4,NOTE_C5,4,-1}, // TUNE_REFLOW_DONE
{NOTE_C5,4,NOTE_B4,4,NOTE_E4,2,-1} // TUNE_REMOVE_BOARDS
};
// Play a tone
// Parameter: tone - an array containing alternating notes and note duration, terminated by -1
void playTones(int tune) {
if (tune >= MAX_TUNES)
return;
const int *tonesToPlay = tones[tune];
for (int i=0; tonesToPlay[i] != -1; i+=2) {
// Note durations: 4 = quarter note, 8 = eighth note, etc.:
int duration = 1000/tonesToPlay[i+1];
tone(CONTROLEO_BUZZER_PIN, tonesToPlay[i], duration);
delay(duration * 1.1);
}
noTone(CONTROLEO_BUZZER_PIN);
}