Syehaji93

countdown_alarm

Oct 14th, 2020
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.99 KB | None | 0 0
  1. #include <LiquidCrystal_I2C.h>
  2.  
  3. LiquidCrystal_I2C lcd(0x27,20,4);  // Kalau gagal ganti 0x3F ke 0x27 for a 16 chars and 2 line display
  4.  
  5. // digital pin 2 has a pushbutton attached to it. Give it a name:
  6. int pushButton = 3;
  7. int alarm = 8;
  8. int S = 60; // count seconds
  9. boolean Start = false;
  10.  
  11. // the setup routine runs once when you press reset:
  12. void setup() {
  13.   lcd.init(); // initialize the lcd
  14.   // initialize serial communication at 9600 bits per second:
  15.   Serial.begin(9600);
  16.   // make the pushbutton's pin an input:
  17.   pinMode(pushButton, INPUT_PULLUP);
  18.   pinMode(alarm, OUTPUT);
  19. }
  20.  
  21. // the loop routine runs over and over again forever:
  22. void loop(void) {
  23.  
  24.   // read the input pin:
  25.   int buttonState = digitalRead(pushButton);
  26.   if(int buttonState = digitalRead(pushButton) == 1)
  27.   {
  28.     S--;
  29.     delay(1000);
  30.    
  31.     if(S>9)
  32.     {
  33.       lcd.backlight();
  34.       lcd.clear();
  35.       lcd.setCursor(0,3);
  36.       lcd.print("Awas Pintu Terbuka.!");
  37.       lcd.setCursor(0,2);
  38.       lcd.print(S);
  39.       alarmBip();
  40.     }
  41.     else
  42.     {
  43.       lcd.backlight();
  44.       lcd.clear();
  45.       lcd.setCursor(0,3);
  46.       lcd.print("Awas Pintu Terbuka.!");
  47.       lcd.setCursor(0,2);
  48.       lcd.print("0");
  49.       lcd.setCursor(1,2);
  50.       lcd.print(S);
  51.       lcd.setCursor(2,2);
  52.       lcd.print(" ");
  53.       alarmBip();
  54.     }
  55.  
  56.     if(S == 0 && S<9)
  57.     {
  58.       lcd.backlight();
  59.       lcd.clear();
  60. //      lcd.setCursor(0,3);
  61. //      lcd.print("Segera Tutup Pintu.!");
  62.       lcd.setCursor(0,2);
  63.       lcd.print("0");
  64.       alarmConstant();
  65.     }
  66.   }
  67.  
  68.   if(int buttonState = digitalRead(pushButton) == 0)
  69.   {
  70.     lcd.backlight();
  71.     lcd.clear();
  72.     lcd.setCursor(0,3);
  73.     lcd.print("Pintu Tertutup");
  74.     delay(1000);
  75.     S = 60;
  76.     alarmOff();
  77.    
  78.   }
  79. }
  80.  
  81. void alarmBip()
  82. {
  83.   digitalWrite(alarm, HIGH);
  84.   delay(100);
  85.   digitalWrite(alarm, LOW);
  86.   delay(100);
  87. }
  88.  
  89. void alarmConstant()
  90. {
  91.   digitalWrite(alarm, HIGH);
  92. }
  93.  
  94. void alarmOff()
  95. {
  96.   digitalWrite(alarm, LOW);
  97. }
Advertisement
Add Comment
Please, Sign In to add comment