Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27,20,4); // Kalau gagal ganti 0x3F ke 0x27 for a 16 chars and 2 line display
- // digital pin 2 has a pushbutton attached to it. Give it a name:
- int pushButton = 3;
- int alarm = 8;
- int S = 60; // count seconds
- boolean Start = false;
- // the setup routine runs once when you press reset:
- void setup() {
- lcd.init(); // initialize the lcd
- // initialize serial communication at 9600 bits per second:
- Serial.begin(9600);
- // make the pushbutton's pin an input:
- pinMode(pushButton, INPUT_PULLUP);
- pinMode(alarm, OUTPUT);
- }
- // the loop routine runs over and over again forever:
- void loop(void) {
- // read the input pin:
- int buttonState = digitalRead(pushButton);
- if(int buttonState = digitalRead(pushButton) == 1)
- {
- S--;
- delay(1000);
- if(S>9)
- {
- lcd.backlight();
- lcd.clear();
- lcd.setCursor(0,3);
- lcd.print("Awas Pintu Terbuka.!");
- lcd.setCursor(0,2);
- lcd.print(S);
- alarmBip();
- }
- else
- {
- lcd.backlight();
- lcd.clear();
- lcd.setCursor(0,3);
- lcd.print("Awas Pintu Terbuka.!");
- lcd.setCursor(0,2);
- lcd.print("0");
- lcd.setCursor(1,2);
- lcd.print(S);
- lcd.setCursor(2,2);
- lcd.print(" ");
- alarmBip();
- }
- if(S == 0 && S<9)
- {
- lcd.backlight();
- lcd.clear();
- // lcd.setCursor(0,3);
- // lcd.print("Segera Tutup Pintu.!");
- lcd.setCursor(0,2);
- lcd.print("0");
- alarmConstant();
- }
- }
- if(int buttonState = digitalRead(pushButton) == 0)
- {
- lcd.backlight();
- lcd.clear();
- lcd.setCursor(0,3);
- lcd.print("Pintu Tertutup");
- delay(1000);
- S = 60;
- alarmOff();
- }
- }
- void alarmBip()
- {
- digitalWrite(alarm, HIGH);
- delay(100);
- digitalWrite(alarm, LOW);
- delay(100);
- }
- void alarmConstant()
- {
- digitalWrite(alarm, HIGH);
- }
- void alarmOff()
- {
- digitalWrite(alarm, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment