that_one_nigga_you_k

nao funcionando projeto gang

Sep 28th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.92 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2.  
  3. int val;
  4. int tempPin = 15;
  5. int lcd_key = 0;
  6. int adc_key_in = 0;
  7.  
  8. #define btnRIGHT  0
  9. #define btnUP     1
  10. #define btnDOWN   2
  11. #define btnLEFT   3
  12. #define btnSELECT 4
  13. #define btnNONE   5
  14.  
  15. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  16.  
  17. int read_LCD_buttons(){               // read the buttons
  18.     adc_key_in = analogRead(0);       // read the value from the sensor
  19.  
  20.     // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
  21.     // we add approx 50 to those values and check to see if we are close
  22.     // We make this the 1st option for speed reasons since it will be the most likely result
  23.  
  24.     if (adc_key_in > 1000) return btnNONE;
  25.  
  26.     // For V1.1 us this threshold
  27.     if (adc_key_in < 50)   return btnRIGHT;  
  28.     if (adc_key_in < 250)  return btnUP;
  29.     if (adc_key_in < 450)  return btnDOWN;
  30.     if (adc_key_in < 650)  return btnLEFT;
  31.     if (adc_key_in < 850)  return btnSELECT;  
  32.  
  33.    // For V1.0 comment the other threshold and use the one below:
  34.    /*
  35.      if (adc_key_in < 50)   return btnRIGHT;  
  36.      if (adc_key_in < 195)  return btnUP;
  37.      if (adc_key_in < 380)  return btnDOWN;
  38.      if (adc_key_in < 555)  return btnLEFT;
  39.      if (adc_key_in < 790)  return btnSELECT;  
  40.    */
  41.  
  42.     return btnNONE;                // when all others fail, return this.
  43. }
  44.  
  45. void setup() {
  46.   lcd.begin(16, 2);
  47.   Serial.begin(9600);
  48. }
  49. void loop()
  50. {
  51.   lcd.setCursor(0,0);
  52.   val = analogRead(tempPin);
  53.   float cel = val * 0.48828125;
  54.   float farh = (cel*9)/5 + 32;
  55.  
  56.   lcd.print("gang = ");
  57.   lcd.print(cel);
  58.   lcd.print("oC");
  59.   Serial.print(cel);
  60.   delay(300);
  61.  
  62.   if(cel>0){
  63.     analogWrite(13, 255);
  64.     digitalWrite(22, 1);
  65.     digitalWrite(23, 0);
  66.   }
  67.  
  68.   else{
  69.     analogWrite(13, 0);
  70.     digitalWrite(22, 1);
  71.     digitalWrite(23, 1);
  72.   }
  73.  
  74.    lcd.setCursor(0,1);             // move to the begining of the second line
  75.    lcd_key = read_LCD_buttons();   // read the buttons
  76.  
  77.    switch (lcd_key){               // depending on which button was pushed, we perform an action
  78.    
  79.        case btnRIGHT:{             //  push button "RIGHT" and show the word on the screen
  80.             lcd.print("RIGHT ");
  81.             break;
  82.        }
  83.        case btnLEFT:{
  84.              lcd.print("LEFT   "); //  push button "LEFT" and show the word on the screen
  85.              break;
  86.        }    
  87.        case btnUP:{
  88.              lcd.print("UP    ");  //  push button "UP" and show the word on the screen
  89.              break;
  90.        }
  91.        case btnDOWN:{
  92.              lcd.print("DOWN  ");  //  push button "DOWN" and show the word on the screen
  93.              break;
  94.        }
  95.        case btnSELECT:{
  96.              lcd.print("SELECT");  //  push button "SELECT" and show the word on the screen
  97.              break;
  98.        }
  99.        case btnNONE:{
  100.              lcd.print("NONE  ");  //  No action  will show "None" on the screen
  101.              break;
  102.        }
  103.    }
  104. }
Add Comment
Please, Sign In to add comment