Examples & Challenges: Nano-Shield.zip
Start each stage by reading and uploading the example (A), then modify it or write your own program to replicate the challenge.
The “answer key” is provided (B), but try to figure out each challenge before you read the program provided.
Flash all LEDs on and off.
Light up, then turn off LEDs one at a time.
Beep on and off, while also using the potentiometer to set speaker tone.
Create a siren that cycles through tones 80Hz – 4000Hz up and down.
Beep at random frequency, for a random length of time, at random intervals.
Turn on random LEDs one at a time for a random period of time.
4. Functions Example
setup() and loop() are functions, but you can also create your own. This becomes essential when writing larger programs to keep them organized and greatly reduce the amount of text.
Using functions in combination with the techniques covered in previous exercises, create the three simple games below using the Nano Shield.
4A. Timing Game
LEDs are illuminated up and down. One button stops, the other resumes, and the pot adjusts game speed. The objective is for the player to stop the LEDs as close to the top as possible.
4B. Random Reaction
LEDs light up randomly, for random periods of time. The objective is for the player to press the button when the top LED is illuminated (win). The player will have to wait through a countdown if they miss the top LED.
4C. Reflex Tester
After the starting tone, there will be a delay (random period of time) before the reflex tone. The objective is to react as quickly as possible. Score will be displayed with LEDs and corrosponding tone from the speaker. If the player presses the button too early, or not at all, they will receive a zero score.