Right now, for an engineering project, Me and my group have been tasked with the construction of a movable bridge. We've managed to get a large portion of the sensor systems working, but I am having difficulty with the traffic lights
Right now, I'm using a pushbutton to switch between the four states (closed, opening, open, and closing)
for these states we need the following
Closed - CarLED needs to be solid, while BoatLED needs to be flashing
opening - both LED's must be flashing
open - CarLED needs to be flashing, while the BoatLED needs to be solid
Closing - Both must be flashing
The wiring is quite simple, pretty much I have an input from the pushbutton, much like the example provided in http://arduino.cc/en/tutorial/button#.UyPcEVFdUkU and http://arduino.cc/en/Tutorial/ButtonStateChange#.UyOjcVFdUkU
the LEDs are listed as outputs, being hooked up to the pins with 220 ohm resistors
Here is the code
//traffic light Simulation
const int CarLED = 12;
const int BoatLED = 13;
const int BoatSignal = 11;
int ButtonState= 0;
int LastButtonState = 0;
int Count = 0;
void setup()
{
pinMode(CarLED, OUTPUT);
pinMode(BoatLED, OUTPUT);
pinMode(BoatSignal, INPUT);
}
void loop()
{
Serial.println(Count);
Serial.println(Count);
if(Count == 0)
{
digitalWrite(CarLED, HIGH);
digitalWrite(BoatLED, HIGH);
Count = checkcount();
delay(1000);
Serial.println(Count);
digitalWrite(BoatLED, LOW);
}
if(Count == 1)
{
digitalWrite(CarLED, HIGH);
digitalWrite(BoatLED, HIGH);
Count = checkcount();
delay(1000);
digitalWrite(BoatLED, LOW);
digitalWrite(CarLED, LOW);
}
if(Count == 2)
{
digitalWrite(CarLED, HIGH);
digitalWrite(BoatLED, HIGH);
Count = checkcount();
delay(1000);
digitalWrite(CarLED, LOW);
}
if(Count == 3)
{
digitalWrite(CarLED, HIGH);
digitalWrite(BoatLED, HIGH);
Count = checkcount();
delay(1000);
digitalWrite(BoatLED, LOW);
digitalWrite(CarLED, LOW);
}
if(Count == 4)
{
Count = 0;
}
}
int checkcount()
{
ButtonState = digitalRead(BoatSignal); //Checks the state of the right lanes entry button
if (ButtonState != LastButtonState) //If the buttons state has changed (closed or open), then the if statement is triggered
{
if (ButtonState == HIGH) //If the button is now on, then a car is added as "on the bridge"
{
Count++; //Adds 1 to the count
Serial.println(Count); //prints the count to the serial monitor
}
}
LastButtonState = ButtonState; //replaces the old saved state with the new saved state
}
Any help would be appreciated
Also, a sidenote, but my Serial Monitor is not showing any of the serial prints of the count, which makes this really tricky for me to fix, anybody have any idea why this would be doing that?