Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidTWI.h>
- const int analogInPin = A3;
- const int buttonPin = 2;
- int buttonState = 0;
- LiquidTWI lcd(0);
- int sensorValue = 0;
- int convertedValue = 0;
- static int countValue = 0;
- void setup() {
- Serial.begin(57600);
- lcd.begin(16, 2);
- pinMode(buttonPin, INPUT);
- lcd.setBacklight(HIGH);
- }
- void loop() {
- lcd.setCursor(0,0);
- lcd.print("Timer set to:");
- lcd.setCursor(0, 1);
- sensorValue = analogRead(analogInPin);
- convertedValue = map(sensorValue, 0, 1023, 0, 10);
- lcd.print(convertedValue);
- lcd.print(" Seconds ");
- buttonState = digitalRead(buttonPin);
- if (buttonState == LOW)
- {
- if (convertedValue == 10)
- {
- Serial.println("x");
- timer();
- }
- else if (buttonState == LOW)
- {
- Serial.println(convertedValue);
- timer();
- }
- else{}
- }
- delay(80);
- }
- void timer(){
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Countdown:");
- for (int x = convertedValue; x > -1; x--) {
- lcd.setCursor(0,1);
- lcd.print(x);
- lcd.print(" ");
- delay(990);}
- lcd.clear();}
Advertisement
Add Comment
Please, Sign In to add comment