Advertisement
RuiViana

Untitled

Aug 4th, 2015
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. // http://labdegaragem.com/forum/topics/ajuda-com-menu-chocadeira
  2.  
  3. // http://playground.arduino.cc/Code/Menu
  4.  
  5. #include <LiquidCrystal.h>
  6.  
  7. #include <Menu.h>
  8. #include <MenuItem.h>
  9. #include <SubMenu.h>
  10. #include <SubMenuItem.h>
  11.  
  12. LiquidCrystal lcd(9, 8, 7, 6, 5, 4); //Ordem dos pinos RS EN D4 D5 D6 D7
  13. // Pino LCD 4 6 11 12 13 14
  14. //initialize menu
  15. Menu Choco = Menu(menuUsed,menuChanged);
  16.  
  17. //initialize menuitems
  18. MenuItem ChocoItem1 = MenuItem();
  19. MenuItem ChocoItem2 = MenuItem();
  20. SubMenu ChocosubMenu = SubMenu();
  21. SubMenuItem ChocosubMenuItem1 = SubMenuItem();
  22. SubMenuItem ChocosubMenuItem2 = SubMenuItem();
  23. SubMenuItem ChocosubMenuItem3 = SubMenuItem();
  24. MenuItem ChocoItem3 = MenuItem();
  25.  
  26. // ------------------------------ setup ----------------------------
  27. void setup(){
  28. Serial.begin(9600);
  29. lcd.begin(16, 2); //Inicia o LCD com dimensões 16x2(Colunas x Linhas)
  30.  
  31. //configure menu
  32. Choco.addMenuItem(ChocoItem1);
  33. Choco.addMenuItem(ChocoItem2);
  34. ChocoItem2.addSubMenu(ChocosubMenu);
  35. ChocosubMenu.addSubMenuItem(ChocosubMenuItem1);
  36. ChocosubMenu.addSubMenuItem(ChocosubMenuItem2);
  37. ChocosubMenu.addSubMenuItem(ChocosubMenuItem3);
  38. Choco.addMenuItem(ChocoItem3);
  39.  
  40. Choco.select(0);
  41. ChocosubMenu.select(0);
  42. }
  43.  
  44. // ------------------------------ loop ----------------------------
  45. void loop()
  46. {
  47. // lcd.clear();// Limpa do buffer do LCD
  48. // lcd.setCursor(0, 0);
  49. // lcd.print("Imprimindo TXT");
  50. if (Serial.available())
  51. {
  52. switch (Serial.read())
  53. {
  54. case 'w':
  55. if (Choco.isCurrentSubMenu())
  56. {
  57. Serial.println("A ");
  58. ChocosubMenu.down(); //set index closer to 0
  59. }
  60. break;
  61. case 's':
  62. if (Choco.isCurrentSubMenu())
  63. {
  64. ChocosubMenu.up(); //set index closer to maximum
  65. }
  66. break;
  67. case 'a':
  68. Choco.down();
  69. break;
  70. case 'd':
  71. Choco.up();
  72. break;
  73. case ' ':
  74. Choco.use();
  75. break;
  76. case '0':
  77. Choco.select(0);
  78. break;
  79. case '1':
  80. Choco.select(1);
  81. break;
  82. case '2':
  83. Choco.select(2);
  84. break;
  85. case '3':
  86. ChocosubMenu.select(1);
  87. break;
  88. }
  89. }
  90. }
  91. // ------------------------------ menuChanged ----------------------------
  92. void menuChanged(ItemChangeEvent event)
  93. {
  94. // Serial.println("Chocadeira");
  95. if( event == &ChocoItem1 )
  96. {
  97. lcd.setCursor(0, 0);
  98. lcd.print("Inicio");
  99. Serial.println("\tNivel 1"); //user feedback
  100. }
  101. // else
  102. if( event == &ChocoItem2 )
  103. {
  104. Serial.println("\tNivel 2"); //user feedback
  105. }
  106. // else
  107. if( event == &ChocosubMenuItem1 )
  108. {
  109. Serial.println("\tNivel 3"); //user feedback
  110. lcd.setCursor(0, 0);
  111. lcd.print("Temperatura");
  112. }
  113. // else
  114. if( event == &ChocosubMenuItem2 )
  115. {
  116. Serial.println("\tNivel 4"); //user feedback
  117. }
  118. // else
  119. if( event == &ChocosubMenuItem3 )
  120. {
  121. Serial.println("\tNivel 5"); //user feedback
  122. }
  123. // else
  124. if( event == &ChocoItem3 )
  125. {
  126. Serial.println("\tNivel 6"); //user feedback
  127. }
  128. }
  129. // ------------------------------ menuUsed ----------------------------
  130. void menuUsed(ItemUseEvent event)
  131. {
  132. Serial.println("menuUsed");
  133. if( event == &ChocoItem1 )
  134. {
  135. Serial.println("\tmenuItem1 used"); //user feedback
  136. }
  137. else if( event == &ChocosubMenuItem1 )
  138. {
  139. Serial.println("\tsubMenuItem1 used"); //user feedback
  140. }
  141. else if( event == &ChocosubMenuItem2 )
  142. {
  143. Serial.println("\tsubMenuItem2 used"); //user feedback
  144. }
  145. else if( event == &ChocosubMenuItem3 )
  146. {
  147. Serial.println("\tsubMenuItem3 used"); //user feedback
  148. }
  149. else if( event == &ChocoItem3 )
  150. {
  151. Serial.println("\tmenuItem3 used"); //user feedback
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement