Let's suppose you have to get funding for a building project and your potential funder(s) is coming to see a prototype. One of the best ways to convince them is to, after explaining everything, turn off the lights and have the building beautifully lit. Why not use a small Linkit 7688 Duo for the cause.
Setup:Once you have your prototype (or lego building etc.) all you have to do is connect the pins as follows:
Red -> 9, Green -> 10, Blue -> 11, and Ground -> GND.
Code:In the code; r, g, and b; are the pins used for setting the color of the led. And re, ge, and be; are variables used for the operations. i.e. analogWrite(r, re);
is write variable re on pin r.
The fading starts by going from red to green. Just increase green and decrease red.
while (ge < 255) {
ge++;
re--;
analogWrite(r, re);
analogWrite(g, ge);
analogWrite(b, be);
delay(20);
}
Then green to blue.
while (be < 255) {
be++;
ge--;
analogWrite(r, re);
analogWrite(g, ge);
analogWrite(b, be);
delay(20);
}
And finally from blue back to red.
while (re < 255) {
re++;
be--;
analogWrite(r, re);
analogWrite(g, ge);
analogWrite(b, be);
delay(20);
}
Then just repeat!
Comments