#include "car_traffic_light.h"
#include "pedistrian_traffic_light.h"
byte button_ped_Pin = 5;
byte pedButtonState;
byte button_bike_Pin = 2;
byte bikeButtonState;
byte CAR_RED_PIN = 6 ;
byte CAR_YELLOW_PIN = 7;
byte CAR_GREEN_PIN = 8;
byte PED_RED_PIN = 10;
byte PED_GREEN_PIN = 9;
unsigned int delay_ped = 4000;
unsigned int delay_to_processing_ped = 5000;
unsigned int processing_time_ped = 1000;
unsigned int delay_bike = 4000;
unsigned int delay_to_processing_bike = 5000;
unsigned int processing_time_bike = 1000;
unsigned long pedTimer;
unsigned long bikeTimer;
unsigned long carTimer;
// These implement the "first come first served" priority rule
unsigned long pedButtonPushedAtMs = 0;
unsigned longButtonPushedAtMs = 0;
// This ensures the cycle and pedistrian workflow are not free simultaneously
bool lock = false;
// This timer is for implementation of the "30 second" rule
unsigned long lastInterruptionOfCarsAtMs = 0;
bool lastPedButtonState = HIGH;
bool lastBikeButtonState = HIGH;
enum State {
IDLE,
WAITING,
PROCESSING
};
State currentPedState = IDLE;
State currentBikeState = IDLE;
void setup() {
Serial.begin(115200) ;
Serial.println(" starting . . .") ;
pinMode(button_ped_Pin, INPUT_PULLUP);
pinMode(button_bike_Pin, INPUT_PULLUP);
pinMode(CAR_RED_PIN, OUTPUT);
pinMode(CAR_YELLOW_PIN, OUTPUT);
pinMode(CAR_GREEN_PIN, OUTPUT);
pinMode(PED_RED_PIN, OUTPUT);
pinMode(PED_GREEN_PIN, OUTPUT);
// pedestrian cycle starts on Stop (RED)
digitalWrite(PED_RED_PIN, HIGH); //!!
digitalWrite(PED_GREEN_PIN, LOW); //!!
// car cycle starts on Stop (RED)
digitalWrite(CAR_GREEN_PIN, LOW);
digitalWrite(CAR_YELLOW_PIN, LOW);
digitalWrite(CAR_RED_PIN, HIGH);
}
void loop() {
carFSM();
pedistrianStateFSM();
}
Car traffic light
bike traffic light
Pedistrian traffic light