I'm new to the forum and have come seeking some help. I've been doing the adafruit lessons and have been using various resources from the internet in an attempt to learn and someday master arduino and the C language.
I'm stuck on a project that should be pretty easy but after a couple of days the code has stumped me. Not looking to be given the answer but rather to learn from my mistakes so I can use that knowledge in the future.
Here it goes,
I have a common anode RGB LED that I want to control by using three tactile switches to turn the LED from Red to Yellow to Green with a press of the corresponding button.
The bread board is setup with 5V to anode on LED, 330 ohm resistors on the color cathodes, red cathode to pin 11, green cathode to pin 10, blue cathode to pin 9. Pin 6 to red tactile switch, pin 5 to green tactile switch, pin 3 to blue tactile switch. All tactile switches to ground rail on breadboard.
The idea is when the arduino powers the LED will be off. When the first tactile button is pressed the LED goes to red high, when the center button is pressed the LED turns yellow, and when the last button is pressed the LED goes green high. (with no color mixing on each press from previous button presses, I,E, when red is high the yellow is mixed in. Should be when yellow is pressed the previous color doesn't run at the same time (if that makes any sense))
Here is what I have in the code so far:
int redLEDPin = 11;
int greenLEDPin = 10;
int blueLEDPin = 9;
int redSwitchPin = 5;
int greenSwitchPin = 5;
int blueSwitchPin = 3;
Here is what I cant wrap my head around, in the setup can I add something like digitalWrite (redLEDPin, LOW) on all three colors to start the LED off? or because it common anode does it have to be digitalWrite (redLEDPin, HIGH) on all three?
Or maybe I should be asking how to tell the arduino that it is a common anode so it sets the proper colors?
Next how do I set in the loop something to the effect of "if redSwitchPin goes LOW write redLEDPin to (255,0,0)
"if greenSwitchPin goes LOW set redLEDPin to (0,0,0) and greenLEDPin to (0,255,0)
I think I have the idea of what I want it to do, im just not sure how to translate that into the code. After three days of researching and learning, it's just not coming together for me.
Can anybody offer some advice? Much appreciations your way good sir's!