Menu

07 Embedded Programming

NOV 01, 2015 ||| Skills: Eagle, Arduino ||| Material: Copperboard, RGB LEDs

Because I had to make up this week later, so I wanted to work with the hacked board that I made from the Output week and try to write a fade code for the light strip. It was a little tricky at first because after taking a look at the fade example code from the arduino library, I realized that the brightness command doesn't work for an RGB light because there are three different colors that make up the light and the colors is dependent on the brightness of each individual color. So I started out setting the G and B as constant, and using the fadeAmount in relation to R as a way to cycle through the fade. At first I got the lights to just fade out.

 

The result was acceptable but I found it to be problematic when I started to try to make it fade in as well. After comparing the example code I decided that I had to include an if statement that basically toggles the fadeAmount from negative to positive ever. " if (R == 100 || R == 0 && G == 255 || G == 0 && B == 255 || B ==0) {

fadeAmount = -fadeAmount;

}"

 

However when I messed with different values of G and B that's not 255. This is a problem because for my final project I need the colors to change responding to the distance between the magnet and the sensor. Another problem with this code is that the value R is tied to the fadeAmount, which means as if B and G were set at amount that doesnt produce white, dimming the R value could also have the effect of altering the color. So these are all issues I hope to solve in my final project.

 

Arduino Code