Datasheet
Chapter 3 • Assemble and Test your BOE Shield-Bot
92 • Robotics with the BOE Shield-Bot
Verify that, after each reset, the piezospeaker makes a clearly audible tone for
one second, and then the “Waiting for reset…” messages resumes.
Try disconnecting and reconnecting your battery supply and programming cable,
and then plugging them back in. This should also trigger the start-alert tone.
/*
* Robotics with the BOE Shield - StartResetIndicator
* Test the piezospeaker circuit.
*/
void setup() // Built in initialization block
{
Serial.begin(9600);
Serial.println("Beep!");
tone(4, 3000, 1000); // Play tone for 1 second
delay(1000); // Delay to finish tone
}
void loop() // Main loop auto-repeats
{
Serial.println("Waiting for reset...");
delay(1000);
}
How StartResetIndicator Works
StartResetIndicator begins by displaying the message “Beep!” in the Serial Monitor. Then,
immediately after printing the message, the
tone function plays a 3 kHz tone on the
piezoelectric speaker for 1 second. Because the instructions are executed so rapidly by the
Arduino, it should seem as though the message is displayed at the same instant the
piezospeaker starts to play the tone.
When the tone is done, the sketch enters the
loop function, which displays the same
“Waiting for reset…” message over and over again. Each time the reset button on the BOE
Shield is pressed or the power is disconnected and reconnected, the sketch starts over again
with the “Beep!” message and the 3 kHz tone.
Your Turn – Adding StartResetIndicator to a Different Sketch
We'll use tone at the beginning of every example sketch from here onward. So, it’s a good
idea to get in the habit of putting
tone and delay statements at the beginning of every
sketch’s
setup function.
Copy the
tone and delay function calls from the StartResetIndicator sketch into
the beginning of the RightServoTest sketch’s
setup function.
Run the modified sketch and verify that it responds with the “sketch starting”
tone every time the Arduino is reset.