#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
const uint8_t btns[] = {26, 27};
const uint8_t leds[] = {32, 33, 34, 35};
byte buttonState = LOW;
byte lastButtonState = LOW;
byte last_btn_state[2] = {LOW, LOW};
unsigned long lastDebounceTime = 0;
const unsigned long debounceDelay = 50;
byte pressCount = 0;
byte btn_press_count[2] = {0, 0};
void setup() {
Serial.begin(115200);
dht.begin();
lcd.init();
lcd.backlight();
for (const uint8_t& btn : btns) pinMode(btn, INPUT_PULLUP);
for (const uint8_t& led : leds) pinMode(led, OUTPUT);
}
void loop() {
delay(10); // this speeds up the simulation
uint8_t btn_states[2];
for (uint8_t i = 0; i < 2; i++)
btn_states[i] = digitalRead(btns[i]);
Serial.println(btn_states);
return;
// Debounce tombol
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) <= debounceDelay) {
lastButtonState = reading; return;
}
if (reading == buttonState) return;
buttonState = reading;
if (buttonState != LOW) return;
pressCount++;
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// lcd.setCursor(0, 1);
// lcd.println("Connection Err");
if (pressCount == 1) {digitalWrite(LAMPU, HIGH); return;}
}
Tombol 1
Tombol 2