So, I've written my first program, designed to operate an RGB LED and display the primary colors in sequence. I assembed the board and resistors on the breadboard and uploaded the program and......... nothing. Nada. So I uploaded the trusty old Blinky example and used Pin 13. Still nothing. Kept playing and found my LED is a common Positive (anode, cathode, I can never remember which). I could drive to Radio Shack and buy a common negative, but that will teach me nothing. Is there a way to turn the I/O pins to ground?
[color=#7E7E7E]/*My First Project[/color]
[color=#7E7E7E]Uses a single RGB to cycle through three colors.[/color]
[color=#7E7E7E]*/[/color]
[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]() {
[color=#CC6600]pinMode[/color](9, [color=#006699]OUTPUT[/color]);
[color=#CC6600]pinMode[/color](10, [color=#006699]OUTPUT[/color]);
[color=#CC6600]pinMode[/color] (11, [color=#006699]OUTPUT[/color]);
}
[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]() {
[color=#CC6600]digitalWrite[/color](9, [color=#006699]HIGH[/color]);
[color=#CC6600]digitalWrite[/color](11, [color=#006699]LOW[/color]);
[color=#CC6600]delay[/color](500);
[color=#CC6600]digitalWrite[/color](10, [color=#006699]HIGH[/color]);
[color=#CC6600]digitalWrite[/color](9, [color=#006699]LOW[/color]);
[color=#CC6600]delay[/color](500);
[color=#CC6600]digitalWrite[/color](11, [color=#006699]HIGH[/color]);
[color=#CC6600]digitalWrite[/color](10, [color=#006699]LOW[/color]);
[color=#CC6600]delay[/color](500);
}
With a common anode ("common positive"), the LED turns on with a LOW; with analogWrite brightest is with '0' and '255' is 'off'.
Put the CA to +5 and each color to an output pin (via a resistor, each ).
One more question, if I may; I tried dimming the leds by running the "on" value from 0 to 200 and I noticed no change. But I taught my self variables!! Code follows:
/*RGB Cycle
Makes RGB LED cycle through colors continuously.
Written By JohnnyRocket
*/
const int red = 9;
const int green = 10;
const int blue = 11;
rocketman247:
One more question, if I may; I tried dimming the leds by running the "on" value from 0 to 200 and I noticed no change. But I taught my self variables!! Code follows:
/*RGB Cycle
Makes RGB LED cycle through colors continuously.
Written By JohnnyRocket
*/
const int red = 9;
const int green = 10;
const int blue = 11;