UBC Logo

Worksheet Exercises

  • rotateLEDs

Task

We will write a program that will do the following:
  • starts by turning on LED0
  • once very second, shifts the LED to the right, wrapping around if necessary (e.g. after one second only LED1 is on, after 2 seconds only LED2 is on, etc.)
  • if RESET is pressed, restarts the cycle, turning LED0 on and all others off
arduino hardware

Hardware Setup

We need two switches and three LEDs. For the switches, we can use either DIP switches, or push-buttons. The following schematic uses DIP switches.

hardware layout Fritzing schematic: apsc160_rotateLEDs.fzz

ComponentCount
Full Size Breadboard1
Tactile Switch1
LEDs (5 mm Round, Various)6
220 Ohm Resistor6
10 kOhm Resistor1


Software Implementation

rotateLEDs.ino