Advertisement
rogerin

Untitled

Nov 5th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.69 KB | None | 0 0
  1. int menu = 0;
  2.  
  3. bool editMenu = false;
  4. int maximaTempratura = 0;
  5.  
  6. int temp;
  7.  
  8.  
  9. int botaoEsquerda;
  10. int botaoCima;
  11. int botaoDireita;
  12. int botaoOk;
  13. int botaoBaixo;
  14.  
  15. int buttonState;             // the current reading from the input pin
  16. int lastButtonState = LOW;   // the previous reading from the input pin
  17. long lastDebounceTime = 0;  // the last time the output pin was toggled
  18. long debounceDelay = 200;    // the debounce time; increase if the output flickers
  19.  
  20.  
  21. // include the library code:
  22. #include <LiquidCrystal.h>
  23.  
  24. // initialize the library with the numbers of the interface pins
  25. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  26.  
  27. void setup() {
  28.   // set up the LCD's number of columns and rows:
  29.   lcd.begin(16, 2);
  30.   // Print a message to the LCD.
  31.   lcd.print("hello, world!");
  32.  
  33.  
  34.   // put your setup code here, to run once:
  35.   Serial.begin(9600);
  36.   pinMode(2, INPUT);
  37.   pinMode(3, INPUT);
  38.   pinMode(4, INPUT);
  39.   pinMode(5, INPUT);
  40.  
  41.   digitalWrite(2, LOW);
  42.   digitalWrite(3, LOW);
  43.   digitalWrite(4, LOW);
  44.   digitalWrite(5, LOW);
  45.  
  46.   Serial.println('Inicando projeto');
  47. }
  48.  
  49. void loop() {
  50.  
  51.   botaoEsquerda  = digitalRead(2);
  52.   botaoCima      = digitalRead(3);
  53.   botaoDireita         = digitalRead(4);
  54.   botaoOk     = digitalRead(5);
  55.  
  56.  
  57.   if(!editMenu){
  58.  
  59.   // temp - analogREad(3)
  60.     if(botaoEsquerda){
  61.       delay(200);
  62.       if(menu == 0) {
  63.           menu = 3;
  64.         } else {
  65.           menu = menu - 1;
  66.         }
  67.     }
  68.    
  69.    
  70.     if(botaoDireita){
  71.       delay(200);
  72.       if(menu == 3) {
  73.         menu = 0;
  74.       } else {
  75.         menu = menu + 1;
  76.       }
  77.     }
  78.   }
  79.  
  80.  
  81.  
  82.   temp = analogRead(A5);
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.   switch(menu){
  91.     case 0:
  92.       MostraMenu0();
  93.     break;
  94.     case 1:
  95.       MostraMenu1();
  96.     break;
  97.     case 2:
  98.       MostraMenu2();
  99.     break;
  100.     case 3:
  101.       MostraMenu3();
  102.     break;
  103.    
  104.     default:
  105.       MostraMenuDefault();
  106.    
  107.   }
  108.  
  109. }
  110.  
  111. void MostraMenu0() {
  112.   //lcd.setCursor(0, 1);
  113.   //lcd.print(millis() / 1000);
  114.  
  115. }
  116.  
  117. void MostraMenu1() {
  118.     //lcd.setCursor(0, 1);
  119.     //lcd.print(maximaTempratura);
  120.     Serial.println(1);
  121.     if(botaoOk) {
  122.         // reseta a hora
  123.         editMenu = true;
  124.     }
  125.    
  126.     if(botaoBaixo){
  127.       editMenu = false;
  128.     }
  129.    
  130.     if(editMenu) {
  131.       if(botaoEsquerda) {
  132.         maximaTempratura = maximaTempratura - 1;
  133.       }
  134.      
  135.       if(botaoDireita) {
  136.         maximaTempratura = maximaTempratura + 1;
  137.       }
  138.     }
  139.    
  140.    
  141.    
  142.     Serial.println(maximaTempratura);
  143.    
  144.    
  145. }
  146.  
  147. void MostraMenu2() {
  148.   Serial.println(2);
  149.  
  150. }
  151. void MostraMenu3() {
  152.   Serial.println(3);
  153.  
  154. }
  155.  
  156. void MostraMenuDefault(){
  157.   Serial.println(4);
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement