/*
  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);
}
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
bz1:1
bz1:2
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r