Introduction: Lab 4 - Millis
This is a step by step process on how to set up a series of blinking LEDs that blink at differing intervals with a potentiometer that controls brightness and two buttons, the first of which increases the blink intervals of the LEDs up to a maximum of 3 times and the second of which decreases the blink intervals of the LEDs down to a minimum multiplier of 1.
You will need the following:
1. Arduino UNO
3. 3 LEDs
4. A Potentiometer
5. 2 Pushbuttons
6. 3 100 Ω resistors
7. 2 2 kΩ resistors
Step 1: Add LEDs
1. Place 3 LEDs on the breadboard.
2. Connect each LED to the ground (+).
3. Connect the first LED to port 9, the second to port 10, and the third to port 11 each with a resistor of at least 100 Ohms to protect the LED.
4. Connect the GND port to the ground on the breadboard where the LEDs are connected.
Step 2: Add Potentiometer
1. Place a Potentiometer on the breadboard.
2. Connect the left column of the potentiometer to the same ground as the LEDs.
3. Connect the right column of the potentiometer to the current (-).
4. Connect the 5V port to the same current.
5. Connect the middle column of the potentiometer to the A0 analog port.
Step 3: Add Buttons
1. Place two Pushbuttons onto the breadboard.
2. Connect the top left column of each to the ground.
3. Connect the bottom right column of each to the current.
4. Connect the bottom left column of the first pushbutton to port 7 and the bottom left column of the second pushbutton to port 8.
Step 4: Code and Possible Errors
Buttons should not allow for the multiplier variable to go below 0 or above 3 and can easily be stopped by restricting the code from interacting with the multiplier variable when it is detected as being pressed.
Buttons should also come with the standard 50 millisecond delay when it is detected as being pressed.
Arrays and for loops should be used when able to simplify code for both efficiency and readability.
The Potentiometer should do nothing but restrict the voltage being provided to the LEDs, thus restricting their brightness and allowing for analog adjustments as they update.
The multiplier variable should be set to 1 by default and directly multiply the variables that determine the delay for each LED within the for loop that updates the state of the LEDs for simplicity.
If a Button is not reacting correctly it may be due to the voltage causing the UNO board to have issues reading its state. A resistor on each with about 2 kΩ should fix this issue.