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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started