• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomeArduinoArduino EsploraArduino Esplora Buzzer Music Example
Previous Next

Arduino Esplora Buzzer Music Example

Posted by: admin , November 11, 2013

[vc_row][vc_column width=”1/1″][vc_column_text]

Hardware:
Arduino Esplora

[/vc_column_text][vc_text_separator title=”Code” title_align=”separator_align_center”][vc_column_text]

/*
Esplora Music

Press SWITCH 1 and slide the slider at the same time

Created on 22 november 2012
By Enrico Gueli <<a href="mailto:enrico.gueli@gmail.com">enrico.gueli@gmail.com</a>>
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();
}
}

[/vc_column_text][/vc_column][/vc_row]

Tags: Arduino Esplora

Share!
Tweet

admin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors