OUT_Speaker+2xSwitches03 by yasusanto

Cloned from Sketch OUT_Speaker+2xSwitches04 by yasusanto

This sketch is missing a short description
**Speaker and 2x Momentary Switches 02** This program makes Arduino to read signals (on/off) from two momentary switches (it reads signals as fast as the processor can go). The program then instruct Arduino to select a larger or smaller frequency in the array (list of constants or variables) that contains frequencies that are 10 octaves of musical notes. Frequencies for each note is predefined in the array at the top of the program. The variable “note” keeps the current position of the frequency array. - When both switches are pressed, Arduino switches the frequency to the 48th note in the array. - When switch 1 is pressed, Arduino subtracts “1” from the “note” variable and the speaker plays the frequency just before the one previously selected in the array. When the current frequency is the 0th frequency of the array, pressing switch 1 does not affect the frequency. - When switch 2 is pressed, Arduino adds “1” to the “note” variable and the speaker plays the frequency just after the one previously selected in the array. When the current frequency is the last frequency of the array, pressing switch 2 does not affect the frequency. **playTone** is a custom function to play a tone with the speaker. The first item in the bracket of the function is the pin that the speaker is connected to. The second item is the frequency of the pitch. The third item is the duration of the tone in microseconds. Frequencies this program generates are technically not accurate, but they are good enough for generating sound effects. Arduino has its own function to play a frequency, which is much more accurate, but the problem is that it disables PWM output on pins 3 and 11. This is problematic if you want to combine RGB-LEDs with sound that relies on Arduino’s **tone()** function. If you are interested to learn more about Arduino’s Tone library, see “tone()” in Arduino’s language reference. ![enter image description here](http://coadaptable.com/dnb603/dnh603_light+sound+motion_switches.png "enter image title here")

Embed This Sketch

Use the following HTML code to embed the sketch code above in your blog or website.

<iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/sketch:138807" frameborder="0"></iframe>

Embed The Serial Monitor

You can also embed the Serial Monitor section! Just use this HTML code.

<iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/serialmonitor" frameborder="0"></iframe>