3 in one – RGB diodes
Our blog has received support – a new writer (attentive reader probably know already who it is :) ), so new interesting posts are being prepared, while I am preparing, as usual, some colorful lights :) .
Let’s begin from the end – a short movie. It isn’t impressing, because mobile phone camera doesn’t reproduct the colours well.
What to do… Well, maybe pictures of the assembled circuit.
Now it’s already known what the title RGB diode is – three LED diodes in one: Red, Green, Blue.
Common cathode, so easily controlled from Arduino – only connection (through 220 Ohm resistor) between proper terminal and Arduino digital pin is required to control one colour.
Which terminal is which? The following picture will be helpful:
Describing from the left side, we have: blue, green, ground, red. The longest terminal of it is ground and this lets us see how to connect the diode.
What gives us such a diode? Well, we can produce every colour by mixing three base colours in varying amount. To illustrate this, I will present the code used in first example. The idea is to light every single colour with different intensity (using PWM) and different frequency.
We are getting a mixing colours effect in this way:
int LED1 = 9; int s1 = 255; int LED2 = 10; int s2 = 255; int LED3 = 11; int s3 = 255; unsigned long int tme; void setup() { pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); }; void loop() { analogWrite(LED1, s1); s1 = sin(tme*tme/50000.0)*128+128; analogWrite(LED3, s3); s3 = sin(tme*tme/100000.0)*128+128; analogWrite(LED2, s2); s2 = sin(tme*tme/70000.0)*128+128; delay(15); tme++; };
tme
is variable representing the time elapsed. In loop, tme square value is divided by a sort of values and sinus is calculated from them. Thanks to it we have three different waves (of different frequencies) and every controls one colour. Since square is a non-linear increasing function, the phase offset of every wave should vary across time (I think so, but maybe this should be checked out precisely). Because of that the colours are mixed differently and not in a fixed sequence.
The side effect is that with time, the changes become more frequent and the diode is blinking faster and faster…
If someone needs such a diode – it’s available in Nettigo.