week 9: analog/digital

My project this week is fairly simple, and my goal was to just get more comfortable using the components with the Arduino (in preparation for following weeks!). I used an RGB LED controlled by a potentiometer, and a regular LED controlled by a momentary switch to do a little light show.

The RGB LED shines red, green, and blue continuously, but the speed is controlled by the voltage at the potentiometer. The mapping is done as such:

delayTime = map(analogRead(potentiometerPin), 0, 1023, 1, 10);
The other LED is always on. When the switch is pressed, it just turns off.
Here’s a little video demo:

One of the challenges was working with the delay() function for the RGB led, while asking the code to do other things, such as reading the potentiometer value. I was going to use the trick for calculating time, so the delay() function wouldn’t block the rest of the program, or even use a library I found for creating a non blocking timer. But I figured that wasn’t the point of this assignment, so I stuck with delay(). This led to some repetition in my code, and I would definitely not do it this way if I wanted cleaner, more robust code.

Leave a Reply