Tuesday, 29 December 2009

PLAYing around

When my order of solenoids arrived, i received a free changing LED thingy so I decided I would learn how to use it and use it as an indicator to show output control on a real time clock.

Wiring up was not too bad, easy to follow instructions came with the LED, finally i might add!

My only problem was actually turning the LED to the correct colour I had programmed.

Each colour had a corressponding pin to turn 'high' or on. When i stated red to come on, all available colours came on, not just red. I quickly realized that if i wanted red to turn on, i would have to ensure that green and blue were off.

digitalWrite(redPin, HIGH); // set red on
digitalWrite(greenPin, LOW); // set green off
digitalWrite(bluePin, LOW); // set blue off

However, when i did this, the red did not come on but one of the others. I PLAYed on the circuit i had made thinking that i might of wired up my pins wrong or got my colours confused.

It took me some time to understand that the LED was in fact inverted. This means when i command 'HIGH' to turn on, i really need to command 'LOW', usually used to command off. So my code simply needed to be turned upside down...

e.g. to turn on red:
digitalWrite(redPin, LOW); // set red on
digitalWrite(greenPin, HIGH); // set green off
digitalWrite(bluePin, HIGH); // set blue off

No comments:

Post a Comment