#include "pitches.h"
int speaker = 10;
bool button;
bool prevButton;
int counter;
int notes[] = {
NOTE_A2, NOTE_B2, NOTE_C3, NOTE_D3, NOTE_E3, NOTE_F3, NOTE_G3
};
void setup() {
// put your setup code here, to run once:
pinMode(speaker, OUTPUT);
pinMode(button, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
button = digitalRead(8);
if (button != prevButton) {
if(button) {
counter++;
}
}
Serial.println(counter);
tone(speaker, notes[counter%7]);
prevButton = button;
}