I was in my room for a good chunk of the day today. Not because, like the title may suggest, I was grounded. But because I have been completely stumped by this tri-color led for a good portion of the past two days.

See, unlike every other LED since the time of the cave man, it’s comes equipped with 4 legs. A common anode, and 3 legs of identical length. The three correspond to each color within the LED head (RGB), and up until 30 minutes ago, I thought the common Anode was to move to ground, because almost every schematic I looked at online used a black wire ‘GND’.

The escapade started when I wanted to continue work on my temperature gauge project. I want to add the functionality of data logging, and cool little rgb led to show blue –> red depending on the temperature. I went online and grabbed the LED mA ratings, and wired everything up according to a schematic I found. Ground to Anode (which was my first tip that something was wrong), and three pulse width pins to the legs. I wrote a quick little program that set each light to ‘255’. And smacked ‘dat upload button.

…darkness.

Hmm, checked my wiring, made sure I had the right resistors ( I used a little higher than recommended because I don’t have a lot of resistors). Everything seemed O.K. I tried again…nothing. What on Earth? I checked again, and again, and again. No, I didn’t doubt for one second that it was in the wiring. Everything seemed so right. I would send the signal through the wire, and it would complete through ground and light up the corresponding color.

In comes Dad. Savior of all things electronic.

“Lets take it downstairs and hook it up to a power supply”

We move downstairs and pull out a nice little 5V supply. We run the signal through a leg to ground, and the light still didn’t come on. But of course, he had this inquisitive look on his face, and said “No, wait, if you want this LED to light up, you need to run power to the anode. No if’s, and’s or but’s.” So he placed the 5v supply on the Anode, and ground to a leg, and for the first time, I saw the majestic blue of the LED shoot me in the face. We had got it, it was all figured out! Game over, Ben – 1 Tri-LED – 0.

Wrong.

Because you can’t ground 3 legs, and control them through a single signal wire on the Anode of the LED. Great, I almost felt right back to where I started. I still needed to run the three legs to pins, and the Anode to power. I popped in the analogWrite(red, 255); line for each color, and ran it with the anode on 5V. Still nothing.

At this point, I’m about ready to give up and just forget this feature. Who really cares? It’s cold, it’s going to be blue. But no, I need to know how to do this. I can’t give up now when I feel like I’m so close .

And I slept on it.

I woke up today, made my coffee in the french press, then plugged right back in. I sat down and booted up my machine, and did the first thing I could think of. If the power was coming from the Anode, I had to resist the signal in order to pull current. In order to draw attention to the legs.

analogWrite(red, 0);

On goes the Red.

So I guess the pins on an Arduino chip can be ground wires? Or, at least so some degree, resistors? I’m definitely going to take my time over the next few days to learn more about the entire Arduino chip, and what it can do exactly.

Seeing that light come on was truly an amazing feeling. There’s no real way to describe how something so insignificant in the universe can bring such pleasure to a single person. But man did I have a grin on my face. =D

The next half hour or so (up until right about now), I’ve been writing a few programs to fart around with the colors. I’ll include my favorite here! Please excuse my poor coding, it’s entirely self taught.

int blue = 3;

int green = 5;

int red = 6;

int cycle = 1;

int intensityR = 255;

int intensityG = 255;

int intensityB = 255;

int flipsign = 1;

int colordelay = 1;

void setup(){

}

void loop(){

//—————————————————

for(int i = 0;i < 510; i++){

if(intensityR == 250){

flipsign = 1;

}

if(intensityR == 0){

flipsign = -1;

}

if (flipsign == 1){

analogWrite(red, intensityR);

intensityR = intensityR – cycle;

}

else{

intensityR = intensityR + cycle;

analogWrite(red, intensityR);

}

delay(colordelay);

}

analogWrite(red, 255);

//—————————————————

for(int i = 0;i < 510; i++){

if(intensityB == 250){

flipsign = 1;

}

if(intensityB == 0){

flipsign = -1;

}

if (flipsign == 1){

intensityB = intensityB – cycle;

analogWrite(blue, intensityB);

}

else{

intensityB = intensityB + cycle;

analogWrite(blue, intensityB);

}

delay(colordelay);

}

analogWrite(blue, 255);

//————————————————–

for(int i = 0;i < 510; i++){

if(intensityG == 250){

flipsign = 1;

}

if(intensityG == 0){

flipsign = -1;

}

if (flipsign == 1){

intensityG = intensityG – cycle;

analogWrite(green, intensityG);

}

else{

intensityG = intensityG + cycle;

analogWrite(green, intensityG);

}

delay(colordelay);

}

analogWrite(green, 255);

//—————————————————–

}

Share this: Twitter

Facebook

Like this: Like Loading...