The Four-Note Tune In the movie, The Hunger Games, the character Rue who befrien
ID: 3871409 • Letter: T
Question
The Four-Note Tune In the movie, The Hunger Games, the character Rue who befriends the main character Katniss uses a four-note tune as a signal. The tune would be whistled and the birds (mocking-jays) would repeat the tune thus sending the signal out for some distance in many directions. The four-note tune thus becomes an important signal. The four notes are in the order: G4B5-A5 -D4 Laboratory Project The objectives of the lab are to be able to play an important tune on the Arduino . Write a program to read in all four pushbuttons on the EduShield. When any of the four buttons is pressed, output a tone as long as the button is pressed. When the button is released, stop the tone. Use a frequency of A4 (440Hz) for the tone. Note that the buttons are on Digital pins 4,7,8, and 12 2. Write a program that allows you to play the four-note tune mentioned above. Note that the speaker on the EduShield is connected to pin 5. Use the four pushbuttons on the EduShield for this. Assign each note to a push button. The frequencies may be obtained from the header file in the tutorialExplanation / Answer
void setup()
{
pinMode(4,INPUT)
pinMode(7,INPUT)
pinMode(8,INPUT)
pinMode(12,INPUT)
}
void loop()
{
if(digitalRead(4)==HIGH || digitalRead(7)==HIGH || digitalRead(8)==HIGH || digitalRead(12)==HIGH)
tone(5, 440);
}
The above arduino program simply reads the input from digital pins 4,7,8,12 and plays a tone on a piezo speaker connected to pin 5. Frequency is predefined as 440Hz . For each pin we have the same tone.
For the second program we can have different frequencies for each button and play it as per the button pressed.
void setup()
{
pinMode(4,INPUT)
pinMode(7,INPUT)
pinMode(8,INPUT)
pinMode(12,INPUT)
}
void loop()
{
if(digitalRead(4)==HIGH)
tone(5, 660);
if(digitalRead(7)==HIGH)
tone(5, 440);
if(digitalRead(8)==HIGH)
tone(5, 200);
if(digitalRead(12)==HIGH)
tone(5, 880);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.