// === CompartR ====
// Module #5 project
const int EW_RED = 14; // The east-west red LED is wired to ESP32 board pin GPIO14
const int EW_YELLOW =12; // The east-west yellow LED is wired to ESP32 board pin GPIO12
const int EW_GREEN = 13; // The east-west green LED is wired to ESP32 board pin GPIO13
const int NS_RED = 25; // The north-south red LED is wired to Mega board pin GPIO25
const int NS_YELLOW = 26; // The north-south yellow LED is wired to Mega board pin GPIO 26
const int NS_GREEN = 27; // The north-south green LED is wired to Mega board pin GPIO 27
int Xw_value;
const int XW_MOM_SW = 19; //Cross Walk button
// the setup function runs once when you press reset or power the board
void setup() {
pinMode(XW_MOM_SW, INPUT_PULLUP); // 0=pressed, 1 = unpressed button
Serial.begin(115200);
pinMode(EW_RED, OUTPUT); // initialize digital pin 14 (east-west red LED) as an output.
pinMode(EW_YELLOW, OUTPUT); // initialize digital pin 12 (east-west yellow LED) as an output.
pinMode(EW_GREEN, OUTPUT); // initialize digital pin 13 (east-west green LED) as an output.
pinMode(NS_RED, OUTPUT); // initialize digital pin 25(north-south red LED) as an output.
pinMode(NS_YELLOW, OUTPUT); // initialize digital pin 26 (north-south yellow LED) as an output.
pinMode(NS_GREEN, OUTPUT); // initialize digital pin 27 (north-south green LED) as an output.
}
// the loop function runs over and over again forever
void loop() {
// read the cross walk button value:
Xw_value=digitalRead(XW_MOM_SW);
if (Xw_value == LOW ){ // if crosswalk button (X-button) pressed
digitalWrite(EW_YELLOW , LOW); // This should turn off the east-west yellow LED
digitalWrite(EW_GREEN, LOW); // This should turn off the east-west green LED
digitalWrite(NS_YELLOW , LOW); // This should turn off the north-south yellow LED
digitalWrite(NS_GREEN, LOW); // This should turn off the north-south green LED
for (int i=10; i>0; i--)
{
Serial.print(" Count = "); Serial.print(i);
Serial.println(" == Walk == ");
digitalWrite(EW_RED, HIGH); // This should turn on the east-west red LED
digitalWrite(NS_RED, HIGH); // This should turn on the north-south red LED
delay(500); //wait 0.5 seconds
digitalWrite(EW_RED, LOW); // This should turn off the east-west red LED
digitalWrite(NS_RED, LOW); // This should turn off the north-south red LED
delay(500); //wait 0.5 seconds
} // End of counter
} //
else // No Emergency ===
{
Serial.println(" == Do Not Walk == ");
// The next three lines of code turn on the east-west red LED
digitalWrite(EW_RED, HIGH); // This should turn on the east-west red LED
digitalWrite(EW_YELLOW , LOW); // This should turn off the east-west yellow LED
digitalWrite(EW_GREEN, LOW); // This should turn off the east-west green LED
delay(1000); //Extended time for Red light#1 before the Green of the other side turns ON
// The next three lines of code turn on the north-south red LED
digitalWrite(NS_RED, LOW); // This should turn off the north-south red LED
digitalWrite(NS_YELLOW , LOW); // This should turn off the north-south yellow LED
digitalWrite(NS_GREEN, HIGH); // This should turn on the north-south green LED
delay(2000); // wait for 1 second
// The next three lines of code turn on the east-west red LED
digitalWrite(EW_RED, HIGH); // This should turn on the east-west red LED
digitalWrite(EW_YELLOW , LOW); // This should turn off the east-west yellow LED
digitalWrite(EW_GREEN, LOW); // This should turn off the east-west green LED
// The next three lines of code turn on the north-south red LED
digitalWrite(NS_RED, LOW); // This should turn off the north-south red LED
digitalWrite(NS_YELLOW , HIGH); // This should turn on the north-south yellow LED
digitalWrite(NS_GREEN, LOW); // This should turn off the north-south green LED
delay(2000); // wait for 1 second
// The next three lines of code turn on the north-south red LED
digitalWrite(NS_RED, HIGH); // This should turn on the north-south red LED
digitalWrite(NS_YELLOW , LOW); // This should turn off the north-south yellow LED
digitalWrite(NS_GREEN, LOW); // This should turn off the north-south green LED
delay(1000); //Extended time for Red light#2 before the Green of the other side turns
// The next three lines of code turn on the east-west yellow LED
digitalWrite(EW_RED, LOW); // This should turn off the east-west red LED
digitalWrite(EW_YELLOW , LOW); // This should turn off the east-west yellow LED
digitalWrite(EW_GREEN, HIGH); // This should turn on the east-west green LED
delay(2000); // wait for 1 second
// The next three lines of code turn on the east-west yellow LED
digitalWrite(EW_RED, LOW); // This should turn off the east-west red LED
digitalWrite(EW_YELLOW , HIGH); // This should turn on the east-west yellow LED
digitalWrite(EW_GREEN, LOW); // This should turn off the east-west green LED
// The next three lines of code turn on the north-south red LED
digitalWrite(NS_RED, HIGH); // This should turn on the north-south red LED
digitalWrite(NS_YELLOW , LOW); // This should turn off the north-south yellow LED
digitalWrite(NS_GREEN, LOW); // This should turn off the north-south green LED
delay(2000); // wait for 1 second
}// Emergency Button closing ============
}