system
March 12, 2012, 1:27pm
1
Hi
I'm trying to control an common anode RGB led using this code:
const int RED = 6;
const int GREEN = 5;
const int BLUE = 3;
int REDvalue = 0;
void setup()
{
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
Serial.begin(9600);
}
void loop(){
if (Serial.available() > 0) {
int REDvalue = Serial.read();
switch (REDvalue) {
case 'a':
digitalWrite(RED, LOW);
break;
default:
for (int RED = 6; ;) {
digitalWrite(RED, HIGH);
}
}
}
}
But when I write a in the serial monitor and press send nothing happens.
Did you select "No line ending" in Serial Monitor? If not, your 'a' will turn off the red LED and the line ending will immediately turn it back on.
system
March 12, 2012, 2:16pm
4
For some reason I can turn it off now... Which as I see it should be the opposed of what should happen. But I can't turn it back on.
This 'for' loop does nothing at all which might explain why you can't turn the light back on.
for (int RED = 6; ;) {
digitalWrite(RED, HIGH);
}
Try it this way instead:
digitalWrite(RED, HIGH);
system
March 12, 2012, 3:30pm
6
I've asked for help for my entire project in this post:
http://arduino.cc/forum/index.php/topic,96268.0.html
Any help would be appreciated.
I've asked for help for my entire project in this post:
So how does the last comment:-
Ignore the question. Figured it all out a different way around.
Square with this?
system
March 16, 2012, 5:41am
8
Thank you. I had not come across that site and it helped a lot. You were right that I Led Light Accessories really needed to see how diodes worked and when I saw that understanding the LED was easy.