Advertisement
Dani_info

uv lamp

Feb 2nd, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1.  
  2.  
  3. #include <LiquidCrystal.h>
  4.  
  5. const int rs = 8, en = 9, d4 =4, d5 = 5, d6 = 6, d7 = 7;
  6. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  7.  
  8.  
  9. int verifyButton (int);
  10.  
  11.  int minutes=0;
  12.  
  13.  
  14. void setup() {
  15.   // set up the LCD's number of columns and rows:
  16.   lcd.begin(16, 2);
  17.   // Print a message to the LCD.
  18.   lcd.print(minutes);
  19.   lcd.setCursor(0, 1);
  20.   lcd.print("minutes");
  21.   pinMode (2, OUTPUT);
  22.   digitalWrite (2, HIGH);
  23. }
  24.  
  25. void loop() {
  26.   int value = analogRead (A0);
  27.   int result = verifyButton(value);
  28.   lcd.setCursor (0,0);
  29.   switch (result){
  30.     case 2:{
  31.         minutes++;
  32.         delay (300);
  33.         break;
  34.         }
  35.     case 3:{
  36.         minutes--;
  37.         delay (300);
  38.         break;
  39.     }
  40.   }
  41.   lcd.print(minutes);
  42.   lcd.print("         ");
  43.   if (value==0)
  44.   {
  45.     lcd.clear();
  46.     delay (500);
  47.     digitalWrite (2, LOW);
  48.     while (1){
  49.       for (int i=minutes*60; i>=0; i--){
  50.             lcd.setCursor(0,0);
  51.             lcd.print(i);
  52.             lcd.print("  ");
  53.             delay (1000);
  54.       }
  55.       lcd.setCursor(0,0);
  56.       lcd.clear();
  57.       digitalWrite(2, HIGH);
  58.       lcd.print("Exposure finished");
  59.       while (1){
  60.         lcd.setCursor(0,1);
  61.         lcd.print("");
  62.       }
  63.       }
  64.  }
  65. }
  66.  
  67. int verifyButton (int val){
  68.   if (val<10) return 1;
  69.   if (val<150) return 2;
  70.   if (val<350) return 3;
  71.   if (val<500) return 4;
  72.   if (val<750)return 5;
  73.   else return -2;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement