forked from ChamplainBrent/ArduinoExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusicWithArduino
More file actions
57 lines (49 loc) · 1.13 KB
/
Copy pathMusicWithArduino
File metadata and controls
57 lines (49 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//Made By Cole and Jacky
/*
Esplora Music
Press SWITCH 1 and slide the slider at the same time
Created on 22 november 2012
By Enrico Gueli, [email protected]
modified 22 Dec 2012
by Tom Igoe
*/
#include <Esplora.h>
// these are the frequencies for the notes from middle C
// to one octave above middle C:
const int note[] = {
262, // C
277, // C#
294, // D
311, // D#
330, // E
349, // F
370, // F#
392, // G
415, // G#
440, // A
466, // A#
494, // B
523 // C next octave
};
void setup()
{
}
void loop()
{
// read the button labeled SWITCH_DOWN. If it's low,
// then play a note:
if ((Esplora.readButton(SWITCH_UP) == LOW)||(Esplora.readButton(SWITCH_DOWN) == LOW)||(Esplora.readButton(SWITCH_LEFT) == LOW)||(Esplora.readButton(SWITCH_RIGHT) == LOW)) {
int slider = Esplora.readSlider();
Esplora.writeRGB(0, 0, 255);
// use map() to map the slider's range to the
// range of notes you have:
byte thisNote = map(slider, 0, 1023, 0, 13);
// play the note corresponding to the slider's position:
Esplora.tone(note[thisNote]);
}
else {
// if the button isn't pressed, turn the note off:
Esplora.noTone();
Esplora.writeRGB(0, 0, 0);
}
}