/************************************************************************************************
* LAB TEST 2025 - TRAFFIC LIGHTS *
* *
* Student Name: Indervir Rai *
* *
* Description: You will need to wire and code the following program: *
* Attach all items (breadboard is optional). When the program runs, *
* a green, yellow then red light should flash (none at the same time). When *
* the red light is on, a STOP! message should be displayed on the LCD screen, a SLOW! *
* message when the yellow light is on and a GO! message when the green light is on. *
* These messages should flash on and off (a blank screen between messages). *
* The speed that you cycle through the lights/delays should be controlled by the *
* potentiometer. The delay between lights should range between 200-500 milliseconds. *
* The program must be properly commented, indented and variables must be created *
* using proper naming procedures. You must use PORTB and DDRB commands when setting up and *
* controlling the LED's. The LiquidCrystal I2C library has been added for you. *
* *
* GOOD LUCK! *
* *
***********************************************************************************************/
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 // defines I2C_ADDR
#define LCD_COLUMNS 16 // defines LCD_COLLUMS
#define LCD_LINES 2 // defines LCD_LINES
int potPin = A0; // potentiometer conneted to A0
int greenLED = 13; // the green LED is connected to pin 13
int yellowLED = 12; // the yellow LED is connected to pin 12
int redLED = 11; // the red LED is connected to pin 11
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 columns and 2 rows
void setup() {
DDRB = B111111; // Numbers 13-8 repersented by 1 for HIGH and 0 for LOW
lcd.init(); // initialize the lcd
lcd.backlight(); // turn on backlight
lcd.setCursor(0,0); // sets the cursor to top left of lcd
lcd.print("*LED FADER v1.0*");
delay(2000);
lcd.setCursor(0,0); // sets the cursor to top left of lcd board
lcd.print(" ");
lcd.setCursor(6,0); // move cursor to (6,0) on lcd board
}
void loop() {
lcd.setCursor(6,0); // move cursor to (6,0) on lcd board
lcd.print("GO! ");
PORTB = B100111; // turn on 13 for green led
delay(500);
lcd.print(" ");
delay(500);
lcd.setCursor(6,0); // move cursor to (6,0) on lcd board
lcd.print("SLOW! ");
PORTB = B010111; // turn on 12 for yellow led
delay(500);
lcd.print(" ");
delay(500);
lcd.setCursor(6,0); // move cursor to (6,0) on lcd board
lcd.print("STOP! ");
PORTB = B001111; // turn on 11 for yellow led
delay(500);
lcd.print(" ");
delay(500);
}