aboutsummaryrefslogtreecommitdiff
path: root/libraries/Esplora/Beginners/EsploraMusic
diff options
context:
space:
mode:
authorFederico Fissore <f.fissore@arduino.cc>2013-01-28 11:37:51 +0100
committerFederico Fissore <f.fissore@arduino.cc>2013-01-28 11:37:51 +0100
commit5c67c7e5c674a572dd99e9d0d8c19c718c9985bc (patch)
tree1f22ba2385ad22eca306d67793c0827451f2b50a /libraries/Esplora/Beginners/EsploraMusic
parentc453e0a32e7adf5e7bab7bfb7c8f7a21e30ca563 (diff)
parentc6287dd6ac33544179a6544b8f3f55a396ec6608 (diff)
Merge branch 'ide-1.5.x' into lib-1.5
Diffstat (limited to 'libraries/Esplora/Beginners/EsploraMusic')
-rw-r--r--libraries/Esplora/Beginners/EsploraMusic/EsploraMusic.ino53
1 files changed, 53 insertions, 0 deletions
diff --git a/libraries/Esplora/Beginners/EsploraMusic/EsploraMusic.ino b/libraries/Esplora/Beginners/EsploraMusic/EsploraMusic.ino
new file mode 100644
index 0000000..7a950fb
--- /dev/null
+++ b/libraries/Esplora/Beginners/EsploraMusic/EsploraMusic.ino
@@ -0,0 +1,53 @@
+/*
+ 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 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_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();
+ }
+}