/*
Playing Notes based on the number of fast button presses.
After pressing at least once with the mouse, you can then use the keyboard "A" to
press the button.
The buzzer will not repeat the same note twice in a row.
*/
#include <Toggle.h>
#include <pwmWrite.h>
const int tonePin = 4;
const int buttonPin = 19;
const int notes[9] = {10, 262, 294, 330, 349, 392, 440, 494, 523};
const int duration = 500; // note duration ms
const int interval = 0; // pause between notes ms
uint8_t note;
Pwm pwm = Pwm();
Toggle button(buttonPin);
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
button.begin(buttonPin);
}
void loop() {
button.poll();
uint8_t code = button.pressCode(); // print: (1) on () off;
if (code > 0xF0 && code < 0xF9) note = code - 0xF0;
pwm.tone(tonePin, notes[note], duration, interval);
delay(10);
}