Jumping back in to Arduino stuff after a few years in another hobby.
I have simple count loop with LEDs turning on with the corresponding count value. I'm not sure why count value 0 does not turn on the LED? It's not a wiring issue or bad LED.
Is it because 0 is not considered a valid value?
Should I begin to count at 1 if 0 is not valid?
Thank you in advance.
const int ledPin0 = 7;
const int ledPin1 = 8;
const int ledPin2 = 9;
const int ledPin3 = 10;
const int ledPin4 = 11;
int count=0;
void setup() {
Serial.begin(9600);
pinMode(ledPin0,OUTPUT);
pinMode(ledPin1,OUTPUT);
pinMode(ledPin2,OUTPUT);
pinMode(ledPin3,OUTPUT);
pinMode(ledPin4,OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
Serial.print("Count Value: ");
Serial.println(count++);
delay(400);
if (count == 0) {
digitalWrite(ledPin0, HIGH);}
else {digitalWrite(ledPin0, LOW);
}
if (count == 1) {
digitalWrite(ledPin1, HIGH);}
else {digitalWrite(ledPin1, LOW);
}
if (count == 2) {
digitalWrite(ledPin2, HIGH);}
else {digitalWrite(ledPin2, LOW);
}
if (count == 3) {
digitalWrite(ledPin3, HIGH);}
else {digitalWrite(ledPin3, LOW);
}
if (count == 4) {
digitalWrite(ledPin4, HIGH);}
else {digitalWrite(ledPin4, LOW);
}
if (count == 5) {count =0;}
}
I see what you are saying, but the other LEDs correctly illuminate when the count equals their corresponding values. It is just count 0 and ledPin0 that do not illuminate However, in the serial monitor I see the 0 as it cycles.