Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- #include <LiquidCrystal.h>
- const int rs =12, en = 11, d4 = 5, d5 = 4, d6 =3, d7 = 2;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
- #define RED 10
- #define YELLOW 9
- #define GREEN 8
- void setup()
- {
- pinMode(RED, OUTPUT);
- pinMode(YELLOW, OUTPUT);
- pinMode(GREEN, OUTPUT);
- Serial.begin(9600);
- lcd.begin(16,2);
- }
- void loop()
- {
- int COUNTER = 0;
- int REMAININGTIME = 0;
- int REDTIME = 20;
- int YELLOWTIME = 5;
- int GREENTIME = 20;
- digitalWrite(RED, LOW);
- digitalWrite(YELLOW, LOW);
- digitalWrite(GREEN, HIGH);
- for (COUNTER = 0; COUNTER < GREENTIME; COUNTER++)
- {
- REMAININGTIME = GREENTIME - COUNTER;
- lcd.setCursor(0,0);
- lcd.print("GREEN for ");
- if (REMAININGTIME > 9) lcd.setCursor(10,0);
- if (REMAININGTIME < 10) lcd.setCursor(11,0);
- lcd.print(REMAININGTIME);
- lcd.setCursor(8,1);
- lcd.print("seconds.");
- lcd.display();
- if (REMAININGTIME <= YELLOWTIME)
- {
- digitalWrite(YELLOW, HIGH);
- digitalWrite(GREEN, HIGH);
- digitalWrite(RED, LOW);
- }
- Serial.println(REMAININGTIME);
- delay(1000);
- lcd.noDisplay();
- lcd.clear();
- }
- digitalWrite(RED, HIGH);
- digitalWrite(YELLOW, LOW);
- digitalWrite(GREEN, LOW);
- for (COUNTER = 0; COUNTER < REDTIME; COUNTER++)
- {
- REMAININGTIME = REDTIME - COUNTER;
- lcd.setCursor(0,0);
- lcd.print("RED for ");
- if (REMAININGTIME > 9) lcd.setCursor(8,0);
- if (REMAININGTIME < 10) lcd.setCursor(9,0);
- lcd.print(REMAININGTIME);
- lcd.setCursor(8,1);
- lcd.print("seconds.");
- lcd.display();
- if (REMAININGTIME <= YELLOWTIME)
- {
- digitalWrite(YELLOW, HIGH);
- digitalWrite(RED, HIGH);
- digitalWrite(GREEN, LOW);
- }
- Serial.println(REMAININGTIME);
- delay(1000);
- lcd.noDisplay();
- lcd.clear();
- }
- }
Add Comment
Please, Sign In to add comment