SonicDH

WiCuBoBS - Master

Apr 17th, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidTWI.h>
  3. const int analogInPin = A3;
  4. const int buttonPin = 2;
  5. int buttonState = 0;
  6. LiquidTWI lcd(0);
  7. int sensorValue = 0;
  8. int convertedValue = 0;
  9. static int countValue = 0;
  10. void setup() {
  11.   Serial.begin(57600);
  12.   lcd.begin(16, 2);
  13.   pinMode(buttonPin, INPUT);
  14.   lcd.setBacklight(HIGH);
  15. }
  16. void loop() {
  17.   lcd.setCursor(0,0);
  18.   lcd.print("Timer set to:");
  19.   lcd.setCursor(0, 1);
  20.   sensorValue = analogRead(analogInPin);            
  21.   convertedValue = map(sensorValue, 0, 1023, 0, 10);
  22.   lcd.print(convertedValue);
  23.   lcd.print(" Seconds  ");
  24.   buttonState = digitalRead(buttonPin);
  25.   if (buttonState == LOW)
  26.    {
  27.      if (convertedValue == 10)  
  28.      {
  29.      Serial.println("x");
  30.      timer();
  31.      }
  32.      else if (buttonState == LOW)
  33.      {
  34.      Serial.println(convertedValue);
  35.      timer();    
  36.      }
  37.      else{}
  38.      }    
  39.   delay(80);
  40. }
  41. void timer(){
  42.   lcd.clear();
  43.   lcd.setCursor(0,0);
  44.   lcd.print("Countdown:");
  45.   for (int x = convertedValue; x > -1; x--) {
  46.     lcd.setCursor(0,1);
  47.     lcd.print(x);
  48.     lcd.print("   ");
  49.     delay(990);}
  50.     lcd.clear();}
Advertisement
Add Comment
Please, Sign In to add comment