// === Rudolph Compart ====
// Module #6 project #include <Wire.h> //lcd
#include <LiquidCrystal_I2C.h> //lcd
LiquidCrystal_I2C lcd(0x27,16,2); //set the LCD address to 0x3F for a 16 chars and 2-line display
// if it does not work then try 0x3F, if both addresses do not work then run the scan code below
const int bzr=32; // GPIO32 to connect the Buzzer
//==================== LCD ====================
const int EW_RED = 14; // The east-west red is wired to ESP32 board pin GPIO14
const int EW_YELLOW =12; // The east-west yellow is wired to ESP32 board pin GPIO12
const int EW_GREEN = 13; // The east-west green is wired to ESP32 board pin GPIO13
const int NS_RED = 25; // The north-south red is wired to Mega board pin GPIO25
const int NS_YELLOW = 26; // The north-south yellow is wired to Mega board pin GPIO 26
const int NS_GREEN = 27; // The north-south green is wired to Mega board pin GPIO 27
int Xw_value;
const int Xw_button = 19; //Cross Walk button
void setup()
{
Serial.begin(115200);
pinMode(Xw_button, INPUT_PULLUP); // 0=pressed, 1 = unpressed button
lcd.init(); // initialize the lcd lcd.backlight();
lcd.setCursor(0,0); // column#4 and Row #1
lcd.print(" === CEIS114 ===");
pinMode(bzr,OUTPUT);
pinMode(EW_RED, OUTPUT); // initialize digital pin 14 (east-west red) as an output.
pinMode(EW_YELLOW, OUTPUT); // initialize digital pin12 (east-west yellow) as an output.
pinMode(EW_GREEN, OUTPUT); // initialize digital pin 13 (east-west green) as an output.
pinMode(NS_RED, OUTPUT); // initialize digital pin 25(north-south red) as an output.
pinMode(NS_YELLOW, OUTPUT); // initialize digital pin 26 (north-south yellow) as an output.
pinMode(NS_GREEN, OUTPUT); // initialize digital pin 27 (north-south green) as an output.
}
// the loop function runs over and over again forever
void loop()
{
// read the cross walk button value:
Xw_value=digitalRead(Xw_button);
if (Xw_value == LOW ){ // if crosswalk button (X-button) pressed
digitalWrite(EW_YELLOW , LOW); // This should turn off the east-west yellow
digitalWrite(EW_GREEN, LOW); // This should turn off the east-west green
digitalWrite(NS_YELLOW , LOW); // This should turn off the north-south yellow
digitalWrite(NS_GREEN, LOW); // This should turn off the north-south green
for (int i=10; i>= 0; i--)
{
Serial.print(" Count = ");
Serial.print(i);
Serial.println(" == Walk == ");
lcd.setCursor(0,1); // set the cursor to column 1, line 2
// lcd.clear(); // clears the display to print new message
lcd.print(" ");
lcd.setCursor(0,1); // set the cursor to column 1, line 2
lcd.print(" == Walk == "); // Walk characters to the LCD.
lcd.print(i); // Print the count to the LCD
digitalWrite(EW_RED, HIGH); // This should turn on the east-west red
digitalWrite(NS_RED, HIGH); // This should turn on the north-south red digitalWrite(bzr, HIGH);
delay(500);
digitalWrite(EW_RED, LOW); // This should turn off the east-west red
digitalWrite(NS_RED, LOW); // This should turn off the north-south red digitalWrite(bzr, LOW);
delay(500);
} // End of counter
// clears the display to print new message
// ===== lcd.clear();
lcd.setCursor(0,1); // set the cursor to column 1, line 2
lcd.print(" ");
} //
else // No Emergency ===
{
lcd.setCursor(0,1); // set the cursor to column 1, line 2
lcd.print(" = Do Not Walk ="); // Do Not Walk characters to the LCD.
Serial.println(" == Do Not Walk == ");
// The next three lines of code turn on the east-west red
digitalWrite(EW_RED, HIGH); // This should turn on the east-west red
digitalWrite(EW_YELLOW , LOW); // This should turn off the east-west yellow
digitalWrite(EW_GREEN, LOW); // This should turn off the east-west green
delay(1000); //Extended time for Red light#1 before the Green of the other side turns
// The next three lines of code turn on the north-south red
digitalWrite(NS_RED, LOW); // This should turn off the north-south red
digitalWrite(NS_YELLOW , LOW); // This should turn off the north-south yellow
digitalWrite(NS_GREEN, HIGH); // This should turn on the north-south green
delay(2000); // wait for 1 second
// The next three lines of code turn on the east-west red
digitalWrite(EW_RED, HIGH); // This should turn on the east-west red
digitalWrite(EW_YELLOW , LOW); // This should turn off the east-west yellow
digitalWrite(EW_GREEN, LOW); // This should turn off the east-west green
// The next three lines of code turn on the north-south red
digitalWrite(NS_RED, LOW); // This should turn on the north-south red
digitalWrite(NS_YELLOW , HIGH); // This should turn off the north-south yellow
digitalWrite(NS_GREEN, LOW); // This should turn off the north-south green
delay(2000); // wait for 1 second
// The next three lines of code turn on the north-south red
digitalWrite(NS_RED, HIGH); // This should turn on the north-south red
digitalWrite(NS_YELLOW , LOW); // This should turn off the north-south yellow
digitalWrite(NS_GREEN, LOW); // This should turn off the north-south green
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
digitalWrite(EW_RED, LOW); // This should turn off the east-west red
digitalWrite(EW_YELLOW , LOW); // This should turn off the east-west yellow
digitalWrite(EW_GREEN, HIGH); // This should turn off the east-west green
delay(2000); // wait for 1 second
// The next three lines of code turn on the east-west yellow
digitalWrite(EW_RED, LOW); // This should turn off the east-west red
digitalWrite(EW_YELLOW , HIGH); // This should turn on the east-west yellow
digitalWrite(EW_GREEN, LOW); // This should turn off the east-west green
// The next three lines of code turn on the north-south red
digitalWrite(NS_RED, HIGH); // This should turn on the north-south red
digitalWrite(NS_YELLOW , LOW); // This should turn off the north-south yellow
digitalWrite(NS_GREEN, LOW); // This should turn off the north-south green
delay(2000); // wait for 1 second
}// Emergency Button closing ============
}