const int LampuMerah = 1;
const int LampuKuning = 2;
const int LampuHijau = 3;
#include <LiquidCrystal.h>
#include "DHT.h"
#define DHTPIN 4
LiquidCrystal lcd(7,8,9,10,11,12);
#define DHTTYPE DHT22
DHT dht(DHTPIN,DHTTYPE);
void setup() {
dht.begin();
pinMode(LampuMerah, OUTPUT);
pinMode(LampuKuning, OUTPUT);
pinMode(LampuHijau, OUTPUT);
lcd.begin(16,2);
lcd.print("Lampu LaluLintas");
// delay(1000);
// put your setup code here, to run once:
}
void loop() {
float t = dht.readTemperature();
if(isnan(t)){
lcd.setCursor (1,0);
lcd.print("Failed to read from DHT");
} else {
lcd.setCursor(1,1);
DisplayTemp(t);
lcd.setCursor(1,0);
digitalWrite(LampuMerah, HIGH);
lcd.print("Tolong Berhenti");
for(int PositionCounter = 1; PositionCounter < 15;
PositionCounter++){
lcd.scrollDisplayLeft();
delay(715);
}
lcd.clear();
lcd.setCursor(15,0);
lcd.print("Tolong Berhenti");
lcd.setCursor(15,1);
DisplayTemp(t);
for(int PositionCounter = 1; PositionCounter < 15;
PositionCounter++){
lcd.scrollDisplayLeft();
delay(715);
}
lcd.clear();
delay(500);
lcd.setCursor(1,0);
lcd.print("Hati Hati");
lcd.setCursor(1,1);
DisplayTemp(t);
digitalWrite(LampuMerah, LOW);
digitalWrite(LampuKuning, HIGH);
for(int PositionCounter = 1; PositionCounter < 15;
PositionCounter++){
lcd.scrollDisplayLeft();
delay(150);
}
lcd.clear();
lcd.setCursor(15,0);
lcd.print("Hati Hati");
lcd.setCursor(15,1);
DisplayTemp(t);
for(int PositionCounter = 1; PositionCounter < 15;
PositionCounter++){
lcd.scrollDisplayLeft();
delay(150);
}
lcd.clear();
delay(500);
lcd.setCursor(1,0);
lcd.print("Selamat jalan");
lcd.setCursor(1,1);
DisplayTemp(t);
digitalWrite(LampuKuning, LOW);
digitalWrite(LampuHijau, HIGH);
for(int PositionCounter = 1; PositionCounter < 15;
PositionCounter++){
lcd.scrollDisplayLeft();
delay(715);
}
lcd.clear();
lcd.setCursor(15,0);
lcd.print("Selamat Jalan");
lcd.setCursor(15,1);
DisplayTemp(t);
for(int PositionCounter = 1; PositionCounter < 15;
PositionCounter++){
lcd.scrollDisplayLeft();
delay(715);
}
delay(500);
}
// put your main code here, to run repeatedly:
}
void DisplayTemp(float t) {
lcd.print("Temp: ");
lcd.print(t);
lcd.print("c");
}