Advertisement
RuiViana

Untitled

Aug 7th, 2015
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.71 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd(9, 8, 7, 6, 5, 4); //Ordem dos pinos RS EN D4 D5 D6 D7
  3. // Pino LCD 4 6 11 12 13 14
  4.  
  5. int botao0 = A0; // botões
  6. int botao1 = A1;
  7. int botao2 = A2;
  8. int botao3 = A3;
  9. int botao4 = A4;
  10. int botao5 = A5;
  11. int botao6 = 3;
  12.  
  13. char bt0 = 0;
  14. char fbt0 = 1;
  15.  
  16. char bt1 = 0;
  17. char fbt1 = 1;
  18.  
  19. char bt2 = 0;
  20. char fbt2 = 1;
  21.  
  22. char bt3 = 0;
  23. char fbt3 = 1;
  24.  
  25. char bt4 = 0;
  26. char fbt4 = 1;
  27.  
  28. char bt5 = 0;
  29. char fbt5 = 1;
  30.  
  31. char bt6 = 0;
  32. char fbt6 = 1;
  33.  
  34. char Nivel = 0;
  35. char Index_Nivel = 0;
  36. char Sub_Nivel = 0;
  37. char Index_Sub_Nivel = 0;
  38. char Pos = 1;
  39. byte Step = 0;
  40.  
  41. String MeuMenu;
  42.  
  43. //******************************* SETUP **********************************
  44. void setup() {
  45. lcd.begin(16, 2);
  46. lcd.clear();
  47. Serial.begin(9600);
  48. Serial.print("ok");
  49.  
  50. pinMode(botao1, INPUT);
  51. digitalWrite(botao1, LOW);
  52.  
  53. pinMode(botao0, INPUT_PULLUP); // Meunu UP
  54. pinMode(botao1, INPUT_PULLUP); // Meunu DOWN
  55. pinMode(botao2, INPUT_PULLUP); // Sub_Meunu Left
  56. pinMode(botao3, INPUT_PULLUP); // Sub_Meunu Right
  57. pinMode(botao4, INPUT_PULLUP); // Value Up
  58. pinMode(botao5, INPUT_PULLUP); // Value Down
  59. pinMode(botao6, INPUT_PULLUP); // Confirme
  60. DSP_Menu();
  61. }
  62. // ------------------------------- Execução ---------------------------
  63. void Execucao()
  64. {
  65. lcd.setCursor(0, 0);
  66. lcd.print(Index_Nivel+0);
  67. lcd.print(" ");
  68. lcd.print(Sub_Nivel+0);
  69. lcd.print(" ");
  70. lcd.print(Step+0);
  71. lcd.print(" ");
  72. }
  73. // ------------------------------- Display Menu ---------------------------
  74. void DSP_Menu()
  75. {
  76. lcd.clear();
  77. lcd.setCursor(6, 0);
  78. lcd.print(MeuMenu);
  79. lcd.setCursor(0, 1);
  80. lcd.print(" 0 0 0 0");
  81. }
  82. // ------------------------------- Display Index ---------------------------
  83. void Dsp_Index()
  84. {
  85. lcd.setCursor(6, 0);
  86. lcd.print(MeuMenu);
  87. lcd.setCursor(Pos, 1);
  88. lcd.print(" ");
  89. lcd.setCursor(Pos, 1);
  90. lcd.print(Step+0);
  91. lcd.setCursor(Pos, 1);
  92. lcd.blink();
  93. }
  94. // ---------------------------------- Display Sub_Menu ---------------------------
  95. void DSP_Sub_Menu()
  96. {
  97. lcd.setCursor(Pos, 1);
  98. lcd.blink();
  99. }
  100. //-------------------------- loop -------------------------------
  101. void loop()
  102. {
  103. //-------------------------- Menu Up -------------------------------
  104. bt0 = digitalRead(botao0); // Menu Up
  105. if ((bt0 == LOW) && (fbt0 == HIGH))
  106. {
  107. delay(30); // de-bouncing
  108. Nivel =Index_Nivel +1;
  109. Index_Nivel = Nivel;
  110. Sub_Nivel = 0;
  111. Step = 0;
  112. if (Nivel > 3)
  113. {
  114. Nivel = 0;
  115. Index_Nivel = 0;
  116. }
  117. }
  118. fbt0 = bt0;
  119. //-------------------------- Menu Down -------------------------------
  120. bt1 = digitalRead(botao1); // Menu Down
  121. if ((bt1 == LOW) && (fbt1 == HIGH))
  122. {
  123. delay(30); // de-bouncing
  124. Nivel = Index_Nivel -1;
  125. Index_Nivel = Nivel;
  126. Sub_Nivel = 0;
  127. Step = 0;
  128. if (Nivel < 0)
  129. {
  130. Nivel = 3;
  131. Index_Nivel = 3;
  132. }
  133. }
  134. fbt1 = bt1;
  135. //-------------------------- Sub_Menu Up -------------------------------
  136. bt2 = digitalRead(botao2); // Menu Down
  137. if ((bt2 == LOW) && (fbt2 == HIGH))
  138. {
  139. delay(30); // de-bouncing
  140. Sub_Nivel = Sub_Nivel +1;
  141. Step = 0;
  142. Dsp_Index();
  143. if (Sub_Nivel > 3)
  144. {
  145. Sub_Nivel = 0;
  146. }
  147. }
  148. fbt2 = bt2;
  149. //-------------------------- Sub_Menu Down -------------------------------
  150. bt3 = digitalRead(botao3); // Menu Down
  151. if ((bt3 == LOW) && (fbt3 == HIGH))
  152. {
  153. delay(30); // de-bouncing
  154. Sub_Nivel = Sub_Nivel - 1;
  155. Step = 0;
  156. Dsp_Index();
  157. if (Sub_Nivel < 0)
  158. {
  159. Sub_Nivel = 3;
  160. }
  161. }
  162. fbt3 = bt3;
  163. //-------------------------- Step_Up -------------------------------
  164. bt4 = digitalRead(botao4); // Menu Down
  165. if ((bt4 == LOW) && (fbt4 == HIGH))
  166. {
  167. delay(30); // de-bouncing
  168. Step = Step +1;
  169.  
  170. if (Step > 99)
  171. {
  172. Step = 0;
  173. }
  174. Dsp_Index();
  175. }
  176. fbt4 = bt4;
  177.  
  178. //-------------------------- Step_Down -------------------------------
  179. bt5 = digitalRead(botao5); // Menu Down
  180. if ((bt5 == LOW) && (fbt5 == HIGH))
  181. {
  182. delay(30); // de-bouncing
  183. Step = Step -1;
  184. if (Step > 99)
  185. {
  186. Step = 99;
  187. }
  188. Dsp_Index();
  189. }
  190. fbt5 = bt5;
  191. //-------------------------- Enter -------------------------------
  192. bt6 = digitalRead(botao6); // Menu Down
  193. if ((bt6 == LOW) && (fbt6 == HIGH))
  194. {
  195. delay(30); // de-bouncing
  196. Execucao();
  197. }
  198. fbt6 = bt6;
  199. delay(100);
  200. // --------------------------------- switch --------------------------
  201. switch (Nivel)
  202. {
  203. case 0:
  204. MeuMenu = "Menu 0";
  205. Nivel = 10;
  206. Dsp_Index();
  207. break;
  208. case 1:
  209. MeuMenu = "Menu 1";
  210. Nivel = 10;
  211. Dsp_Index();
  212. break;
  213. case 2:
  214. MeuMenu = "Menu 2";
  215. Nivel = 10;
  216. Dsp_Index();
  217. break;
  218. case 3:
  219. MeuMenu = "Menu 3";
  220. Nivel = 10;
  221. Dsp_Index();
  222. break;
  223. default:
  224. break;
  225. }
  226.  
  227. switch (Sub_Nivel)
  228. {
  229. case 0:
  230. Pos = 1;
  231. Dsp_Index();
  232. break;
  233. case 1:
  234. Pos = 5;
  235. Dsp_Index();
  236. break;
  237. case 2:
  238. Pos = 9;
  239. Dsp_Index();
  240. break;
  241. case 3:
  242. Pos = 13;
  243. Dsp_Index();
  244. break;
  245.  
  246. }
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement