manhoosbilli1

LCD_MENU_SKETCH

Oct 7th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. #include <Bounce2.h>
  2. #include <Wire.h>
  3. #include <LiquidCrystal_I2C.h>
  4. LiquidCrystal_I2C lcd(0x27, 16, 2);
  5. #define up 7
  6. #define down 6
  7. #define LED_PIN 13
  8. unsigned int counter = 0;
  9. unsigned long currentMillis;
  10. unsigned long previousMillis;
  11. int menuSize = 8;
  12. int ledState = LOW;
  13. bool mainMenu = true;
  14. int currentMenu =0;
  15. int subMenu = 0;
  16.  
  17. byte arrow[] = {
  18. B00000,
  19. B00100,
  20. B00010,
  21. B11111,
  22. B00010,
  23. B00100,
  24. B00000,
  25. B00000
  26. };
  27.  
  28. byte degree[] = {
  29. B00000,
  30. B01110,
  31. B01010,
  32. B01110,
  33. B00000,
  34. B00000,
  35. B00000,
  36. B00000
  37. };
  38.  
  39. byte celcius[] = {
  40. 0x00,
  41. 0x06,
  42. 0x09,
  43. 0x08,
  44. 0x08,
  45. 0x09,
  46. 0x06,
  47. 0x00
  48. };
  49.  
  50. Bounce debouncerup = Bounce(); // Instantiate a Bounce object
  51. Bounce debouncerdown = Bounce(); // Instantiate a Bounce object
  52.  
  53. void setup() {
  54.  
  55. debouncerup.attach(up,INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode
  56. debouncerdown.attach(down, INPUT_PULLUP);
  57. pinMode(LED_BUILTIN,OUTPUT); // Setup the LED
  58. debouncerup.interval(50);
  59. debouncerdown.interval(50); // Use a debounce interval of 25 milliseconds
  60. lcd.begin();
  61. lcd.backlight();
  62. lcd.setCursor(0,0);
  63. lcd.print("Incubator Is Now");
  64. lcd.setCursor(0,1);
  65. lcd.print("Starting...");
  66. lcd.createChar(0, arrow);
  67. lcd.createChar(1, degree);
  68. lcd.createChar(2, celcius);
  69. lcd.home();
  70. delay(1000);
  71. currentMenu = 1;
  72. lcd.clear();
  73.  
  74.  
  75. }
  76.  
  77. void loop() {
  78. currentMillis = millis();
  79. debouncerup.update(); // Update the Bounce instance
  80. debouncerdown.update();
  81. calculateMenu(); //decides to decrement or increment
  82. checkMenu(); //shows different text on lcd according to menu system
  83. updateSub();
  84.  
  85.  
  86. }
  87.  
  88. //----------------------------------Functions-----------------------
  89.  
  90.  
  91. void checkMenu() {
  92.  
  93. switch(currentMenu) {
  94. case 0:
  95. currentMenu = 1;
  96. break;
  97.  
  98. case 1: //shows temp and humidity default case
  99. lcd.setCursor(0,0);
  100. lcd.print("Temp: 35");
  101.  
  102. lcd.setCursor(0,1);
  103. lcd.print("Hum: 50");
  104.  
  105. break; //remember to turn mainmenu variable to false when getting into sub menus and change it back as you go into main menu
  106. //this will help me differentiate between main menu and sub menu variables and also the counters.
  107.  
  108. case 2: //Motor settings
  109.  
  110. lcd.setCursor(0,0);
  111. lcd.write(0);
  112. lcd.print("Motor settings ");
  113. lcd.setCursor(0,1);
  114. lcd.print(" LCD backlight");
  115.  
  116. break; //to execute a process. makea an if statement saying if the menu matches that number and select button is pressed. start the process
  117.  
  118. case 3: //Stop motor
  119.  
  120. lcd.setCursor(0,0);
  121. lcd.print(" Motor settings");
  122. lcd.setCursor(0,1);
  123. lcd.write(0);
  124. lcd.print("LCD backlight");
  125. break;
  126.  
  127. case 4: //light setting
  128.  
  129. lcd.setCursor(0,0);
  130. lcd.write(0);
  131. lcd.print("Light settings ");
  132. lcd.setCursor(0,1);
  133. lcd.print(" Time settings ");
  134. //add a up or down character to show the user that you can press up and down to change menu
  135. break;
  136.  
  137. case 5: //Time settings
  138.  
  139. lcd.setCursor(0,0);
  140. lcd.print(" Light settings ");
  141. lcd.setCursor(0,1);
  142. lcd.write(0); //selected
  143. lcd.print("Time settings "); //this goes into sub menu. make another sub menu switch case when select is pressed it should change into that sub menu and
  144. //when the down button is pressed for 5 sec it should take you back to home
  145. break;
  146.  
  147. case 6:
  148. currentMenu = 5;
  149. break;
  150.  
  151.  
  152. }
  153. }
  154.  
  155. //--------------------Setting up led rate function--------------------
  156.  
  157. void ledRate() {
  158. if ( debouncerup.fell() ) { // Call code if button transitions from HIGH to LOW
  159. lcd.clear();
  160. counter= counter + 50;
  161. lcd.setCursor(0,0);
  162. lcd.print("Counter:");
  163. lcd.setCursor(9,0);
  164. lcd.print(counter);
  165. return;
  166. }
  167.  
  168. if ( debouncerdown.fell() ) { // Call code if button transitions from HIGH to LOW
  169. lcd.clear();
  170. counter = counter-50;
  171. lcd.setCursor(0,0);
  172. lcd.print("Counter:");
  173. lcd.setCursor(9,0);
  174. lcd.print(counter);
  175. return;
  176. }
  177.  
  178. }
  179.  
  180. //-------------------Blink led function-------------------
  181.  
  182.  
  183. void blinkLed() {
  184. if(currentMillis - previousMillis >= counter) {
  185. digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  186. previousMillis = currentMillis;
  187. }
  188. }
  189.  
  190.  
  191. //--------------------Update Menu function--------------------
  192.  
  193. void calculateMenu() {
  194. if(mainMenu == true) {
  195. if(debouncerup.fell()){
  196. if(currentMenu < menuSize) {
  197. currentMenu = currentMenu + 1;
  198. }
  199. }
  200. if(debouncerdown.fell()) {
  201. if(currentMenu > 0) {
  202. currentMenu = currentMenu - 1;
  203. }
  204. }
  205. }
  206. }
  207.  
  208. /*--------------------Go home function--------------------
  209.  
  210. void goHome() {
  211. //when back button is pressed for 5 sec
  212. currentMenu = 1;
  213. submenu = initial state;
  214. }
  215. */
Add Comment
Please, Sign In to add comment