Advertisement
RuiViana

Untitled

Jun 5th, 2015
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. //http://pastebin.com/0V5vXFAe#
  2. //http://labdegaragem.com/forum/topics/arduino-criar-menu-no-arduino
  3.  
  4. /* CONTADOR COM DOIS BOTÕES (INCREMENTO E DECREMENTO) COM DEBOUNCING E DISPLAY LCD */
  5. const int button1 = 7;
  6. const int button2 = 8;
  7.  
  8. unsigned int debounceDelay_button = 100; // Tempo de debounce do Botao
  9. unsigned int Flagbutton2; // Variavel que identifica o "status" do botao
  10. unsigned int Flagbutton1; // Variavel que identifica o "status" do botao
  11.  
  12. int Soma = 1;
  13. int conta = 0;
  14.  
  15. #include <LiquidCrystal.h>
  16. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  17.  
  18. void setup()
  19. {
  20. lcd.begin(16, 2);
  21. lcd.print("CONTADOR: SOMA ");
  22. pinMode(button1, INPUT_PULLUP);
  23. pinMode(button2, INPUT_PULLUP);
  24. }
  25.  
  26. void loop()
  27. {
  28.  
  29. delay(debounceDelay_button); // espere um tempo
  30. if(!digitalRead(button1)) // se continua apertado
  31. {
  32. if (Soma == 1) // Se for 1
  33. conta++; // incrementa
  34. else // E se for 0
  35. conta--; // Decrementa
  36. delayMicroseconds(1); // Espera 1 us só
  37. }
  38.  
  39.  
  40. delay(debounceDelay_button); // espere um tempo
  41. if(!digitalRead(button2)) // se continua apertado
  42. {
  43. Flagbutton2 = !Flagbutton2; // Inverte estado do botão
  44. if (Flagbutton2 == 1) // Se for 1
  45. {
  46. Soma = 1; // Operação soma
  47. lcd.begin(16, 2);
  48. lcd.print("CONTADOR: SOMA ");
  49. }
  50. else // E se for 0
  51. {
  52. Soma = 0; // Operação subtração
  53. lcd.begin(16, 2);
  54. lcd.print("CONTADOR: SUBTRAI ");
  55. }
  56. while(!digitalRead(button2)) // Espera pela liberação do switch
  57. delayMicroseconds(1); // Espera 1 us só
  58.  
  59. }
  60. lcd.setCursor(0, 1);
  61. lcd.print(conta);
  62. lcd.print(" ");
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement