OUT_Speaker+2xSwitches01 by yasusanto

This sketch is missing a short description
**Speaker and 2x Momentary Switches 01** This is a simple program to make 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 play a tone with one of 3 predefined pitches according to the combination of switches pressed. - If both switches are pressed, the speaker plays ‘E4’. - If switch 1 is pressed, it plays ‘C4’. - If switch 2 is pressed, it plays “D4”. **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 for each note is predefined at the upper half of the program. You can use any of these constants (e.g. tc, tcs, td…) to assign tones Arduino plays according to each switch combination. 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:106859" 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>