#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(A4);
//Reference and guide: https://www.instructables.com/Arduino-Street-Traffic-Light/$0
//Green, Yellow, and PURPLE are the LED colors used for this proof of concept
//The value 3, 4, and 5 are the identified digital pins on the Arduino UNO board
const int BUTTON = 2;
const int GREEN = 3;
const int YELLOW = 4;
const int PINK = 5;
//variables
int buttonValue = 0;
int countValue = 5; //seats already occupied at the time of simulation start, value can be changed.
//Push button is set-up as INPUT
//LED modes are set-up here
//The GREEN, YELLOW, PINK connections from Breadboard to ARDUINO UNO is to send OUTPUT to be sent to the LED bulbs
void setup()
{
pinMode(BUTTON, INPUT_PULLUP);
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(PINK, OUTPUT);
Serial.begin(9600);
//initialize LCD screen
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);//default setting as founf in public available codes
}
//LED bulb operations start here
// buttonValue = LOW means the button is pressed; HIGH is not pressed (and is the setting by default)
// DELAY is the meausure of time for the button "push"
void loop()
{
buttonValue = digitalRead(BUTTON);
//Serial.println(buttonValue);
delay(200);
if (countValue < 15) //This is an INPUT to GREEN LED to remain ON
{
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(PINK, LOW);
}
//This is the initial display in OLED and will change depending on the remaining seat count
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Free Seats");
display.println(25-countValue);
display.display();
if (buttonValue == LOW)
{
countValue++;
Serial.println(countValue);
if(countValue < 15) //To indicate GREEN LED to turn ON
{digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(PINK, LOW);
}
else if(countValue >= 15 && countValue < 21) //To indicate YELLOW LED to turn ON
{digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(PINK, LOW);
}
else if(countValue >= 21 && countValue < 26) //To indicate PINK LED to turn ON
{digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(PINK, HIGH);
}
}
}
//Materials used
//Arduino Uno Rev 3, Half Breadboard
//3x LED bulbs: Green, Yello, Pink
//3x Resistors
//Connectors following LED bulbs' color
//Black connector for grounding
//Pushbutton
//SSD1306 OLED Display
//Connection wires to connect the OLED display and Arduino Board