Question: Demonstrate External Interrupt, Audio: Use the NewTone Library. READ the syntax to learn how to use the NewTone() command. Hookup an LED to a digital

Demonstrate External Interrupt, Audio: Use the NewTone Library. READ the syntax to learn how to use the NewTone() command. Hookup an LED to a digital pin (dont forget the resistor). Hookup a passive piezo speaker (the one with NO white label) to a digital pin. Hook up a pushbutton to an interrupt pin. In the loop() function, blink the LED twice per second using the delay() function.

Using an interrupt, in the ISR make a 1kHz tone for two seconds (using the NewTone library) whenever the pushbutton is pushed. The LED should keep blinking (which is the whole idea of using an interrupt)!

What you are learning from this: Everything from #1 and how to hookup a pin to make an external interrupt (your pushbutton).

*I have the code where the led lights up and the speaker is making a tone I'll post it below*

#include

byte led = 8; volatile boolean state = HIGH; byte buzzer = 9; //Associate the buzzer to pin 4 void setup() { pinMode(led, OUTPUT);

// timerISR runs every 2 sec // initialize value in uS Timer1.initialize(500000); Timer1.attachInterrupt(timerISR); pinMode(buzzer, OUTPUT); //Set it up for output pinMode(led, OUTPUT); }

void loop() {

digitalWrite(buzzer, HIGH); // makes a 1kHz tone delayMicroseconds(500); digitalWrite(buzzer, LOW); delayMicroseconds(500);

}

void timerISR() { state = ! state; digitalWrite(led, state); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!