Makerspace - RGB LED, For Loops and Coding

1. Project:

In this week’s challenge, our goal was to learn how to use the color-changing RGB (red, green, blue) LED and play around with Arduino C coding to learn how to use For loops and Arrays. Then combine that new knowledge to create a project.

2. Code:

The following code combines my experimentation with the potentiometer and my understanding of how the AnalogWrite function can work to control the color of my RGB LED. After briefly running through the range of colors, by LED blinks off. Then the color can be controlled by turning the potentiometer dial.




3. Circuit Design:

For the following circuit design, the potentiometer functions as color selector. The PWM (pulse width modulation) digital output pins control the intensity of each color (red, green and blue) of my RGB LED.

Video of Circuit for Potentiometer as Color Selector (0:49)

4. Electronic Diagram:

The following electronic diagrams were taken from my design journal.

For the following circuit design, the potentiometer functions as a color selector. Turning the knob on the potentiometer will determine which color the RGB LED will shine.



Electronic Diagram for Potentiometer as Color Selector

5. Video of Project:

Combining RGB LED and Potentiometer to Dial in Colors (2:24)

6. Explanation of Project:

I started this week by learning how to use the color-changing RGB (red-green-blue) LED. It's actually a combination of 3 different LED elements. As the brightness of each varies, it produces different colors. After reading the background on how PWM (pulse width modulation) outputs for digital pins work, I was able to successfully manipulate the RGB LED using my Arduino to set it to different colors using the analogWrite() function. From here, I added on to my code.

First, I automated the LED so that it could transition through the whole spectrum of colors. I did this by building two different functions. Since each of the analogWrite() functions for the three input pins could send a value between 0 and 255, I chose to fade each color in or out while holding the 3rd color constant. In total, this gave me a range of 767 unique color combinations. My first function showSpectrum() used a for loop to cycle a variable "x" from 0 to 767. This function referenced my second function showRGB(), which took the variable "x" as an input and then wrote a unique analogWrite() output to each of the RGB LED pins to represent that color.

Extension Challenges:

After getting this project to work, I attempted some of the extension challenges by combining the code I created with some elements of previous projects. I encountered several challenges (see notes in code for some solutions), but was eventually able to get my potentiometer to function as a color selection dial. Each dial position generates a unique RGB LED color!

I accomplished this by writing a third function showPOT(), which reads the analog signal from the potentiometer from 0 (0V) to 1023 (5V). The functions then references the showRGB() function described above to generate a unique color output for my RGB LED!

My final code combines these two projects by first cycling through the color spectrum in 7.67 seconds, then turning off for 1 second, then using the dial location on the potentiometer to select a specific color.

7. Reflection:

I had a lot of fun playing with circuits this week because it was a very open-ended challenge. I learned how to use the PWM and how the digital signal masquerades as an analog output allowing us to analogWrite() with digital pins. Through trial and error, I was able to learn more about how integer variables work, how to use for and while loops, and how to use embedded functions to reduce the amount of repetitive coding I would need to do. It think this will help me be more efficient in the future. 

8. Applications:

In addition to this coding project this week, I also ran the light and sound boards for a student showcase circus performance on Saturday evening. In preparation for the show, I had to program the LED spotlights for each of the aerial points, trampoline and flying trapeze lights to allow me to cue different locations and colors for each act. Similarly to how I coded the separate functions for light color and signals to change the light color, I used separate functions to focus the stage light location and select the color so that I could achieve a broader variety of combinations without specifically programming all of the acts as separate cues. 

Overall, the show was a success! I was able to streamline the process and had a successful tech run with a better understanding of the process. 



Comments

Popular posts from this blog

Web 2.0: Continuing the Journey

Online Learning: Course Management Systems

Online Learning: Wielding Wiki's