I want to make 2 LEDs blink back and forth continuously, but they only do so once, and the second one is very dim.
code:
int ledone = 12;
int ledtwo = 10;
int keepgoing = 1;
void setup() {
pinMode(ledone, OUTPUT);
pinMode(ledtwo, OUTPUT);
}
void loop() {
while (keepgoing == 1) {
digitalWrite(ledone, HIGH);
delay(80);
digitalWrite(ledone, LOW);
digitalWrite(ledtwo, HIGH);
delay(80);
digitalWrite(ledtwo, LOW);
delay(500);
}
}
I am using an Arduino Uno and one 220 ohm resistor for each LED.
ledtwo = 10toledtwo = 9, ie to some other pin, and rewire accordingly – maybe one of your IO pins has a problem or your wires are loose. Also try changing those fairly-short 80-ms delays to perhaps twice or three times as long.if,keepgoing = 1will always evaluate as true,which will keep thewhilestatement going.keepgoing == 1also will evaluate as true, given thatkeepgoingwas initialized to 1.