Hi all,
I've been trying to get a 4-way traffic light working for my 4-year-old (scaled for his small cars running on a Digispark ATTINY85 board), but something isn't working right. I thought it might be my board, but I have tried 2 boards now & both act the same way. In a nutshell, it's 6 LEDs (12 technically, but N/S and E/W are the same) that cycle through a simple rotation.
Here's the code:
void setup() {
pinMode(0, OUTPUT); // Green
pinMode(1, OUTPUT); // Yellow
pinMode(2, OUTPUT); // Red
pinMode(3, OUTPUT); // Green
pinMode(4, OUTPUT); // Yellow
pinMode(5, OUTPUT); // Red
}
void loop() {
digitalWrite(2, HIGH); // Opposing Red On
digitalWrite(3, HIGH); // Green On
delay(4000); // 4 Seconds
digitalWrite(3, LOW); // Green Off
digitalWrite(4, HIGH); // Yellow On
delay(1500); // 1.5 Seconds
digitalWrite(4, LOW); // Yellow Off
digitalWrite(5, HIGH); // Red On (overlap)
delay(1000); // 1 Second
digitalWrite(5, LOW); // Red Off
digitalWrite(2, LOW); // Opposing Red Off
digitalWrite(5, HIGH); // Opposing Red On
digitalWrite(0, HIGH); // Green On
delay(4000); // 4 Seconds
digitalWrite(0, LOW); // Green Off
digitalWrite(1, HIGH); // Yellow On
delay(1500); // 1.5 Seconds
digitalWrite(1, LOW); // Yellow Off
digitalWrite(2, HIGH); // Red On (overlap)
delay(1000); // 1 Second
digitalWrite(2, LOW); // Red Off
digitalWrite(5, LOW); // Opposing Red Off
}
If I only connect one set of 3 (or 6) LEDs, it's fine, and the green on 3 is ok, but the yellow on 4 does nothing & when I connect the red on 5 it seems to crash. I'm using appropriate resisters (I'd have to look it up, I bought 100 when I bought my LEDs & my memory thinks they are 200ohm, but my memory isn't always reliable ;-) ) & the LEDs work on 0,1,2 that don't work on 3,4,5 (so it's not the wiring).
Ideas?