Inspiration
I am pretty sure when people saw blue and red LED’s together, many of them thought of police light in some way. So did I. Because there were tight requirements in this assignment, I felt those requirements somewhat limited my options.
Schematics
As shown in the picture, there are 1 button, 1 potentiometer, and two LED’s. The parts were chosen to meet the following requirements:
-
- One analog sensor
- One digital sensor
- LED output in analog fashion
- LED output in digital fashion
Setup Overview
The setup is identical to the schematics.
Code Highlight
In the code, I implemented three different output(LED light) modes. Those modes can be set via a switch, and the speed of progress for each modes can be controlled via potentiometer. The below three functions are responsible for different output modes. Brief descriptions of each mode can be found below.
void blink(); // both turn on&off at the same time void alternate(); // alternate lighting void glow(); // only blue LED; gradually increase and decrease brightness
These different modes are chosen through a switch, which will be processed in the following code:
void manageOutputPattern() { // button press -> change output pattern bool switchState = digitalRead(powerSwitch); if (switchState && !prevSwitchState) { // ensures unique ON signal outputPattern = (outputPattern + 1) % 3; counter = 0; allOff(); } prevSwitchState = switchState; }
If the previous button state was false and the current state is true, the output mode will change to the next one. The previous state has to be tested because a button will keep sending true while it is being pressed. We only want the moment where the signal changes from false to true.
Other parts of the code can be found here.
Operation
The video shows three different output modes and modified progress speeds (slow & fast).
Reflection
Although it took quite a bit of trials and errors, I became familiarized with using circuit components, Arduino IDE, and fritzing. In the future, I would like to learn how to efficiently design my circuit.