// MUHAMMAD FA'IZ DWI ADHISKI
// XI TEK 1
// ================================
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#define R 16
#define G 15
#define B 14
#define dhtPin 12
#define d_type 22
const int Red[] = {255,0,0};
const int Yellow[] = {255,222,0};
const int Green[] = {0,255,9};
const int Blue[] = {0,188,255};
DHT dht(dhtPin, d_type);
LiquidCrystal_I2C lcd(0x27, 16, 2);
namespace Suhu {
void init() {
Serial.begin(9600);
dht.begin();
lcd.init();
lcd.backlight();
pinMode(R, OUTPUT);
pinMode(G, OUTPUT);
pinMode(B, OUTPUT);
}
void led(char* warna) {
if(warna == "hijau") {
analogWrite(R, Green[0]);
analogWrite(G, Green[1]);
analogWrite(B, Green[2]);
}
else if(warna == "biru") {
analogWrite(R, Blue[0]);
analogWrite(G, Blue[1]);
analogWrite(B, Blue[2]);
}
else if(warna == "kuning") {
analogWrite(R, Yellow[0]);
analogWrite(G, Yellow[1]);
analogWrite(B, Yellow[2]);
}
else if(warna == "merah") {
analogWrite(R, Red[0]);
analogWrite(G, Red[1]);
analogWrite(B, Red[2]);
}
}
float cekSuhu() {
return dht.readTemperature();
}
void lcdExec(float suhu, char* status) {
lcd.setCursor(0,0);
lcd.printstr("Suhu: ");
lcd.print(suhu);
lcd.printstr(" ");
lcd.setCursor(0,1);
lcd.printstr("Status: ");
lcd.print(status);
lcd.printstr(" ");
}
void main() {
if(cekSuhu() < 10) {
led("biru");
lcdExec(cekSuhu(), "Dingin");
}
else if(cekSuhu() <= 30) {
led("hijau");
lcdExec(cekSuhu(), "Normal");
}
else if(cekSuhu() <= 36) {
led("kuning");
lcdExec(cekSuhu(), "Sedang");
}
else if(cekSuhu() > 37) {
led("merah");
lcdExec(cekSuhu(), "Panas");
}
}
}
void setup() {
Suhu::init();
}
void loop() {
Suhu::main();
delay(1000);
}