Advertisement
RuiViana

Niveis de menu

Dec 7th, 2015
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #define sensor 0
  3. #define BotUp 4
  4. #define BotDn 5
  5.  
  6. int Ventrada;
  7. float pressao;
  8. float voltagem;
  9. unsigned int BotOn = 0;
  10. LiquidCrystal lcd (12, 11, 5, 4, 3, 2);
  11. //---------------------------------------------------
  12. void setup()
  13. {
  14. pinMode(BotUp,INPUT_PULLUP); // Define pino como entrada e liga pullup resistor
  15. pinMode(BotDn,INPUT_PULLUP); // Define pino como entrada e liga pullup resistor
  16. lcd.begin(16, 2);
  17. lcd.setCursor(3, 0);
  18. lcd.print("MRS autos");
  19. delay(2000);
  20. lcd.setCursor(2, 1);
  21. lcd.print("Rail Tester!");
  22. delay(2000);
  23. }
  24. //---------------------------------------------------
  25. void loop()
  26. {
  27. Ventrada = analogRead (sensor);
  28. pressao = map(Ventrada, 102.3, 1023, 0, 2000);
  29. voltagem = map(Ventrada, 0, 1023, 0, 5000);
  30.  
  31. if (digitalRead(BotUp) == LOW) // Se botão foi apertado
  32. {
  33. while(digitalRead(BotUp) == LOW) // Enquanto tiver apertado
  34. {
  35. delay(20); // Evita debouncing
  36. BotOn++; // Identifica com botão foi apertado
  37. if (BotOn>7) BotOn = 0; // Estabelece o nivel maximo de menu (Usei 7)
  38. }
  39. }
  40.  
  41. if (digitalRead(BotDn) == LOW) // Se botão foi apertado
  42. {
  43. while(digitalRead(BotDn) == LOW) // Enquanto tiver apertado
  44. {
  45. delay(20); // Evita debouncing
  46. BotOn--; // Identifica com botão foi apertado
  47. if (BotOn<0) BotOn = 7;
  48. }
  49. }
  50. switch (BotOn)
  51. {
  52. case 0:
  53. {
  54. lcd.setCursor(0, 1);
  55. lcd.print(pressao);
  56. lcd.setCursor(4, 1);
  57. lcd.print("bar");
  58. lcd.setCursor(9, 1);
  59. lcd.print(voltagem);
  60. lcd.setCursor(13, 1);
  61. lcd.print("mvs");
  62. lcd.setCursor(7, 1);
  63. lcd.print(" ");
  64. lcd.setCursor(0, 0);
  65. lcd.print("Press. do Rail");
  66. delay(600);
  67. break;
  68. }
  69. case 1:
  70. {
  71. break;
  72. }
  73. case 2:
  74. {
  75. break;
  76. }
  77. case 3:
  78. {
  79. break;
  80. }
  81. case 4:
  82. {
  83. break;
  84. }
  85. case 5:
  86. {
  87. break;
  88. }
  89. case 6:
  90. {
  91. break;
  92. }
  93. case 7:
  94. {
  95. break;
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement