Advertisement
safwan092

Untitled

Dec 13th, 2021
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3.  
  4. LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
  5.  
  6. #define button 2
  7.  
  8. int timerMode = 0;
  9. long startTime;
  10.  
  11. void setup() {
  12. lcd.init();
  13. lcd.init();
  14. lcd.backlight();
  15. lcd.setCursor(0, 0);
  16. lcd.print("Press To Start");
  17. pinMode(button, INPUT);
  18.  
  19. }
  20.  
  21. void loop() {
  22. lcd.setCursor(0, 1);
  23. if (digitalRead(button) == HIGH) {
  24. startTime = millis();
  25. timerMode++;
  26. delay(400);
  27. }
  28. if (timerMode == 1) {
  29. lcd.setCursor(0, 1);
  30. lcd.print((millis() - startTime) / 1000.0);
  31. }
  32. if (timerMode > 1) {
  33. delay(2000);
  34. timerMode = 0;
  35. lcd.clear();
  36. lcd.setCursor(0,0);
  37. lcd.print("Press To Start");
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement