Using a simple setup involving a joystick, an LED, a beeper, and a positional servo, first write a set of functions as follow:
- blinkLED(int delay): blink LED
- wiggleServo(int delay): wiggle servo back and forth
- pulseSound(int frequency, int delay): turn beeper on and off
Once you have completed the above functions, write code in the main loop to choose which function to call:
- if the joystick is left, blink the LED. The further to the left the joystick is, the faster it should blink.
- If the joystick is right, pulse the beeper. The further to the right the joystick is, the faster it should pulse. Also use the up/down position of the joystick to determine the frequency. The further up the joystick is, the higher the frequency should be.
- if the joystick is up or down, wiggle the servo, Use some sort of small tolerance around the center so that if the joystick is approximately neither up nor down, the servo does not move.
Notice that the above directions allow for overlap. For example, if the joystick is left and up, the LED should blink and the servo should wiggle.
The most important part of this assignment is learning about functions on how they work. If you make the Arduino do the task we've asked without using functions, you've missed the point!
Be prepared to demonstrate your creation, and submit your code via Moodle.