Advertisement
RuiViana

Menu_Meu

Aug 6th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1.  
  2. #include <SubMenuItem.h>
  3. #include <SubMenu.h>
  4. #include <MenuItem.h>
  5. #include <Menu.h>
  6. //initialize menu
  7. int seque;
  8. Menu menu = Menu(menuUsed,menuChanged);
  9. //initialize menuitems
  10. MenuItem menuItem1 = MenuItem();
  11. SubMenu subMenu1 = SubMenu(menuChanged);
  12. SubMenuItem subMenu1Item1 = SubMenuItem();
  13. SubMenuItem subMenu1Item2 = SubMenuItem();
  14. SubMenuItem subMenu1Item3 = SubMenuItem();
  15. MenuItem menuItem2 = MenuItem();
  16. SubMenu subMenu2 = SubMenu(menuChanged);
  17. SubMenuItem subMenu2Item1 = SubMenuItem();
  18. SubMenuItem subMenu2Item2 = SubMenuItem();
  19. SubMenuItem subMenu2Item3 = SubMenuItem();
  20. MenuItem menuItem3 = MenuItem();
  21. SubMenu subMenu3 = SubMenu(menuChanged);
  22. SubMenuItem subMenu3Item1 = SubMenuItem();
  23. SubMenuItem subMenu3Item2 = SubMenuItem();
  24. SubMenuItem subMenu3Item3 = SubMenuItem();
  25. //-------------------------------------------------------------------------
  26. void setup(){
  27. Serial.begin(9600);
  28.  
  29. //configure menu
  30. menu.addMenuItem(menuItem1);
  31. subMenu1.addSubMenuItem(subMenu1Item1);
  32. subMenu1.addSubMenuItem(subMenu1Item2);
  33. subMenu1.addSubMenuItem(subMenu1Item3);
  34. menu.addMenuItem(menuItem2);
  35. subMenu2.addSubMenuItem(subMenu2Item1);
  36. subMenu2.addSubMenuItem(subMenu2Item2);
  37. subMenu2.addSubMenuItem(subMenu2Item3);
  38. menu.addMenuItem(menuItem3);
  39. subMenu3.addSubMenuItem(subMenu3Item1);
  40. subMenu3.addSubMenuItem(subMenu3Item2);
  41. subMenu3.addSubMenuItem(subMenu3Item3);
  42.  
  43. menu.select(0);
  44. subMenu1.select(0);
  45. }
  46. //---------------------------------------------------------------------------
  47. void loop(){
  48. if (Serial.available()){
  49. switch (Serial.read()){
  50. case 'w':
  51. if(menu.isCurrentSubMenu())
  52. {
  53. subMenu1.down(); //set index closer to 0
  54. }
  55. break;
  56. case 's':
  57. if (menu.isCurrentSubMenu()){
  58. subMenu1.up(); //set index closer to maximum
  59. }
  60. break;
  61. case 'd':
  62. seque--;
  63. if (seque > 3) seque = 3;
  64. menu.down();
  65. break;
  66. case 'u':
  67. seque++;
  68. if (seque < 0) seque = 0;
  69. menu.up();
  70. break;
  71. case ' ':
  72. menu.use();
  73. break;
  74. case '0':
  75. seque = 0;
  76. menu.select(0);
  77. break;
  78. case '1':
  79. seque = 1;
  80. menu.select(1);
  81. break;
  82. case '2':
  83. seque = 2;
  84. menu.select(2);
  85. break;
  86. case '3':
  87. subMenu1.up();
  88. break;
  89. case '4':
  90.  
  91. subMenu1.down();
  92. break;
  93. case '5':
  94. subMenu2.up();
  95. break;
  96. case '6':
  97. subMenu2.down();
  98. break;
  99. case '7':
  100. subMenu3.up();
  101. break;
  102. case '8':
  103. subMenu3.down();
  104. break;
  105. }
  106. }
  107. }
  108. //---------------------------------------------------------------------------
  109. void menuChanged(ItemChangeEvent event){
  110. // Serial.println("menuChanged");
  111. int xpto = menu.isCurrentSubMenu();
  112. Serial.println(xpto);
  113.  
  114. if( event == &menuItem1 )
  115. {
  116. Serial.println("\tmenu 0"); //user feedback
  117. }
  118. if( event == &menuItem2 )
  119. {
  120. Serial.println("\tmenu 1 "); //user feedback
  121. }
  122. if( event == &menuItem3 )
  123. {
  124. Serial.println("\tmenu 2"); //user feedback
  125. }
  126. if (seque == 0)
  127. {
  128. if( event == &subMenu1Item1 )
  129. {
  130. Serial.println("\tsub Menu 0 "); //user feedback
  131. }
  132. if( event == &subMenu1Item2 )
  133. {
  134. Serial.println("\tsub Menu 1"); //user feedback
  135. }
  136. if( event == &subMenu1Item3 )
  137. {
  138. Serial.println("\tsub Menu 2 "); //user feedback
  139. }
  140. }
  141. }
  142. //---------------------------------------------------------------------------
  143. void menuUsed(ItemUseEvent event)
  144. {
  145. Serial.println("menuUsed");
  146. if( event == &menuItem1 )
  147. {
  148. Serial.println("\tmenuItem1 used"); //user feedback
  149. }else
  150. if( event == &subMenu1Item1 )
  151. {
  152. Serial.println("\tsubMenuItem1 used"); //user feedback
  153. }else
  154. if( event == &subMenu1Item2 )
  155. {
  156. Serial.println("\tsubMenuItem2 used"); //user feedback
  157. }else
  158. if( event == &subMenu1Item3 )
  159. {
  160. Serial.println("\tsubMenuItem3 used"); //user feedback
  161. }else
  162. if( event == &menuItem3 )
  163. {
  164. Serial.println("\tmenuItem3 used"); //user feedback
  165. }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement