SHARE
TWEET

Catan Menu

tarbear123 Feb 16th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  3. int keypad_pin = A0;
  4. int keypad_value = 0;
  5. int keypad_value_old = 0;
  6. char btn_push;
  7. byte mainMenuPage = 1;
  8. byte mainMenuPageOld = 1;
  9. byte mainMenuTotal = 4;
  10. void setup() {
  11. lcd.begin(16, 2); //Initialize a 2x16 type LCD
  12. MainMenuDisplay();
  13. delay(1000);
  14. }
  15. void loop() {
  16. btn_push = ReadKeypad();
  17. MainMenuBtn();
  18. if (btn_push == 'S') { //enter selected menu
  19. WaitBtnRelease();
  20. switch (mainMenuPage) {
  21. case 1:
  22. Catan;
  23. break;
  24. case 2:
  25. Rivals_Of_Catan();
  26. break;
  27. case 3:
  28. MenuC();
  29. break;
  30. case 4:
  31. MenuD();
  32. break;
  33. }
  34. MainMenuDisplay();
  35. WaitBtnRelease();
  36. }
  37. delay(10);
  38. }//--------------- End of loop() loop ---------------------
  39. void Catan() {
  40.  
  41. }
  42.  
  43. void Rivals_Of_Catan() {
  44.  
  45.  
  46. }
  47. void MenuC()
  48. {
  49. lcd.clear();
  50. lcd.setCursor(0, 0);
  51. lcd.print("Inside Menu C");
  52. while (ReadKeypad() != 'L')
  53. {
  54. //Insert Task for Menu C here
  55. }
  56. }
  57. void MenuD()
  58. {
  59. lcd.clear();
  60. lcd.setCursor(0, 0);
  61. lcd.print("Inside Menu D");
  62. while (ReadKeypad() != 'L')
  63. {
  64. //Insert Task for Menu D here
  65. }
  66. }
  67. void MainMenuDisplay()
  68. {
  69. lcd.clear();
  70. lcd.setCursor(0, 0);
  71. switch (mainMenuPage)
  72. {
  73. case 1:
  74. lcd.print("Catan");
  75. break;
  76. case 2:
  77. lcd.print("Rivals_Of_Catan");
  78. break;
  79. case 3:
  80. lcd.print("3. Menu C");
  81. break;
  82. case 4:
  83. lcd.print("4. Menu D");
  84. break;
  85. }
  86. }
  87. void MainMenuBtn()
  88. {
  89. WaitBtnRelease();
  90. if (btn_push == 'U')
  91. {
  92. mainMenuPage++;
  93. if (mainMenuPage > mainMenuTotal)
  94. mainMenuPage = 1;
  95. }
  96. else if (btn_push == 'D')
  97. {
  98. mainMenuPage--;
  99. if (mainMenuPage == 0)
  100. mainMenuPage = mainMenuTotal;
  101. }
  102. if (mainMenuPage != mainMenuPageOld) //only update display when page change
  103. {
  104. MainMenuDisplay();
  105. mainMenuPageOld = mainMenuPage;
  106. }
  107. }
  108. char ReadKeypad()
  109. {
  110. /* Keypad button analog Value
  111. no button pressed 1023
  112. select 741
  113. left 503
  114. down 326
  115. up 142
  116. right 0
  117. */
  118. keypad_value = analogRead(keypad_pin);
  119. if (keypad_value < 100)
  120. return 'R';
  121. else if (keypad_value < 200)
  122. return 'U';
  123. else if (keypad_value < 400)
  124. return 'D';
  125. else if (keypad_value < 600)
  126. return 'L';
  127. else if (keypad_value < 800)
  128. return 'S';
  129. else
  130. return 'N';
  131. }
  132. void WaitBtnRelease()
  133. {
  134. while ( analogRead(keypad_pin) < 800)
  135. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top