const int buzzerPin = 8;
const int buttonPin = 2;
volatile byte state = LOW;
void setup() {
Serial.begin(9600);
pinMode(buzzerPin, OUTPUT);
pinMode(buttonPin, INPUT);
attachInterrupt(digitalPinToInterrupt(buttonPin), tocar, CHANGE);
}
void loop() {
Serial.print(state);
}
void tocar() {
tone(buzzerPin, 440, 500);
state = !state;
}