aboutsummaryrefslogtreecommitdiff
path: root/libraries/Esplora/examples/EsploraMusic
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2012-12-10 15:55:05 +0100
committerCristian Maglie <c.maglie@bug.st>2012-12-10 15:55:05 +0100
commit433090f18b6218319fe0a721c24e1dc69285ea3e (patch)
treee7dc4da5b6ff077f1bc255350506dfc0bf87c6c3 /libraries/Esplora/examples/EsploraMusic
parentc453e0a32e7adf5e7bab7bfb7c8f7a21e30ca563 (diff)
parente624b841b3b5d22f6e9cb7ec515beb47f96f46f2 (diff)
Merged 1.0.3
Diffstat (limited to 'libraries/Esplora/examples/EsploraMusic')
-rw-r--r--libraries/Esplora/examples/EsploraMusic/EsploraMusic.ino52
1 files changed, 52 insertions, 0 deletions
diff --git a/libraries/Esplora/examples/EsploraMusic/EsploraMusic.ino b/libraries/Esplora/examples/EsploraMusic/EsploraMusic.ino
new file mode 100644
index 0000000..10c17f7
--- /dev/null
+++ b/libraries/Esplora/examples/EsploraMusic/EsploraMusic.ino
@@ -0,0 +1,52 @@
+/*
+ Esplora Music
+
+ This sketch turns the Esplora in a simple musical instrument.
+ Press the Switch 1 and move the slider to see how it works.
+
+ Created on 22 november 2012
+ By Enrico Gueli <enrico.gueli@gmail.com>
+ modified 24 Nov 2012
+ by Tom Igoe
+*/
+
+
+#include <Esplora.h>
+
+
+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_DOWN) == LOW) {
+ int slider = Esplora.readSlider();
+
+ // 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();
+ }
+}