#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int tempPin = A0; // Pin sensor suhu
const int button1Pin = 2; // Kembali
const int button2Pin = 3; // Celsius
const int button3Pin = 4; // Fahrenheit
int menuState = 0; // 0: menu utama, 1: suhu Celsius, 2: suhu Fahrenheit
float suhu = 0;
void setup() {
lcd.begin();
lcd.backlight();
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(button3Pin, INPUT_PULLUP);
}
void loop() {
suhu = analogRead(tempPin) * (5.0 / 1023.0) * 100;
if (digitalRead(button1Pin) == LOW) {
menuState = 0;
delay(300);
}
if (digitalRead(button2Pin) == LOW) {
menuState = 1;
delay(300);
}
if (digitalRead(button3Pin) == LOW) {
menuState = 2;
delay(300);
}
lcd.clear();
if (menuState == 0) {
lcd.setCursor(0, 0);
lcd.print("Menu Suhu");
lcd.setCursor(0, 1);
lcd.print("1: C 2: F");
}
else if (menuState == 1) {
lcd.setCursor(0, 0);
lcd.print("Suhu: ");
lcd.print(suhu);
lcd.print(" C");
}
else if (menuState == 2) {
float fahrenheit = (suhu * 9.0 / 5.0) + 32.0;
lcd.setCursor(0, 0);
lcd.print("Suhu: ");
lcd.print(fahrenheit);
lcd.print(" F");
}
delay(100);
}