I am looking for help writing software for a puffin crossing (Puffin Crossings use traffic lights to stop vehicle traffic, allowing pedestrians to cross . Pedestrians push a button at the side of the road, and wait for a signal to cross - this is from a standing red man to a walking green man. A beeping sound is usually heard when the walking green man is shown)
I would be massively grateful if someone could help me on this!
Always show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.
In the Arduino IDE, use CtrlT or CMDT to format your code then copy the complete sketch.
Use the </> icon from the ‘reply menu’ to attach the copied sketch.
Thanks for responding. I haven't got an attempt. I had a short amount of experience about 4 months ago but have since had to prioritise other things so I am at a huge brick wall at the moment!
int red = 10;
int yellow = 9;
int green = 8;
int button = 12; // switch is on pin 12
void setup() {
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
pinMode(button, INPUT);
digitalWrite(green, HIGH);
}
void loop() {
if (digitalRead(button) == HIGH) {
delay(15); // software debounce
if (digitalRead(button) == HIGH) {
// if the switch is HIGH, ie. pushed down - change the lights
changeLights();
delay(15000); // wait for 15 seconds
}
}
}
void changeLights() {
// green off, yellow on for 3 seconds
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
delay(3000);
// turn off yellow, then turn red on for 5 seconds
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delay(5000);
// red and yellow on for 2 seconds (red is already on though)
digitalWrite(yellow, HIGH);
delay(2000);
// turn off red and yellow, then turn on green
digitalWrite(yellow, LOW);
digitalWrite(red.LOW);
digitalWrite(green, HIGH);
delay(3000);
}
In file included from sketch/Arrays.ino.cpp:1:0:
/Users/Will/Desktop/Arrays/Arrays.ino: In function 'void changeLights()':
/private/var/folders/k1/jhy9d4r95m1c84q92wt_g40c0000gn/T/AppTranslocation/591A07E0-FEB3-43C1-A99F-8B90A643AC20/d/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h:41:14: error: expected unqualified-id before numeric constant #define LOW 0x0
^
/Users/Will/Desktop/Arrays/Arrays.ino:41:20: note: in expansion of macro 'LOW'
digitalWrite(red.LOW);
^~~
exit status 1
Error compiling for board Arduino Uno.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
What color bands are on your resistances?
I cannot see it from your picture.
You might also add a Serial.print(button); in your loop to see the status of the button (pressed and unpressed). Maybe your switch needs to be turned by 90 degrees.
Also your LED's may be the wrong way around.
The flat side should point to - (the bunch of black wires).
Also it is 'rule' to connect blue to blue and red to red on the long side of your breadboard as already indicated by @runaway_pancake .