Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: TextLCD mbed MaxSonar RTC-DS1307
Fork of TextLCD_HelloWorld by
main.cpp@10:21c24327e65f, 2017-05-25 (annotated)
- Committer:
- aueangpanit
- Date:
- Thu May 25 11:17:06 2017 +0000
- Revision:
- 10:21c24327e65f
- Parent:
- 9:39190ed25585
- Child:
- 11:f6a39ae5ecbc
Working game option menu with exit option menu
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| simon | 1:7418a52375a0 | 1 | // Hello World! for the TextLCD |
| simon | 1:7418a52375a0 | 2 | |
| simon | 0:334327d1a416 | 3 | #include "mbed.h" |
| aueangpanit | 4:c669026b6f6e | 4 | #include <string> |
| simon | 0:334327d1a416 | 5 | #include "TextLCD.h" |
| aueangpanit | 5:2f13ec8efe0b | 6 | #include "MaxSonar.h" |
| aueangpanit | 5:2f13ec8efe0b | 7 | using std::string; |
| simon | 0:334327d1a416 | 8 | |
| aueangpanit | 3:5e0ba6e35849 | 9 | TextLCD lcd(PTE30, PTE29, PTE23, PTE22, PTE21, PTE20); // rs, e, d4-d7 |
| aueangpanit | 3:5e0ba6e35849 | 10 | |
| aueangpanit | 7:f00ddf85cacc | 11 | DigitalOut questionScreen(PTE3); |
| aueangpanit | 4:c669026b6f6e | 12 | DigitalOut screen1(PTE5); |
| aueangpanit | 4:c669026b6f6e | 13 | DigitalOut screen2(PTE4); |
| aueangpanit | 4:c669026b6f6e | 14 | |
| aueangpanit | 9:39190ed25585 | 15 | //All functions for controlling screens |
| aueangpanit | 4:c669026b6f6e | 16 | void UpdateScreen(DigitalOut screen, string text); |
| aueangpanit | 5:2f13ec8efe0b | 17 | void UpdateScreen(DigitalOut screen, char text[1024]); |
| aueangpanit | 10:21c24327e65f | 18 | void UpdateScreen(DigitalOut screen, int firstLineLocation, string firstLineText, int secondLineLocation, string secondLineText); |
| aueangpanit | 10:21c24327e65f | 19 | void UpdateScreen(DigitalOut screen, int firstLineLocation, char firstLineText[1024], int secondLineLocation, char secondLineText[1024]); |
| aueangpanit | 9:39190ed25585 | 20 | void ClearAllScreen(); |
| aueangpanit | 9:39190ed25585 | 21 | |
| aueangpanit | 9:39190ed25585 | 22 | //All funcitons for range sensors |
| aueangpanit | 9:39190ed25585 | 23 | void UpdateRange(); |
| aueangpanit | 9:39190ed25585 | 24 | |
| aueangpanit | 9:39190ed25585 | 25 | //All functions for menu page |
| aueangpanit | 9:39190ed25585 | 26 | void GameOption(); |
| aueangpanit | 9:39190ed25585 | 27 | void StartGame(int gameOptionLocation); |
| aueangpanit | 9:39190ed25585 | 28 | |
| aueangpanit | 9:39190ed25585 | 29 | //All functions for exit screen menu |
| aueangpanit | 9:39190ed25585 | 30 | bool ExitScreen(); |
| aueangpanit | 9:39190ed25585 | 31 | bool CheckExit(float r1, float r2); |
| aueangpanit | 9:39190ed25585 | 32 | |
| aueangpanit | 9:39190ed25585 | 33 | //all functions for Multi-Maths game |
| aueangpanit | 9:39190ed25585 | 34 | void MultiChoice(); |
| aueangpanit | 8:8ce2ab8191cf | 35 | void DisplayNewQuestion(); |
| aueangpanit | 8:8ce2ab8191cf | 36 | bool CheckCorrect(int screenNumber); |
| aueangpanit | 8:8ce2ab8191cf | 37 | |
| aueangpanit | 8:8ce2ab8191cf | 38 | string questions[4] = {"What is 2*2?", |
| aueangpanit | 8:8ce2ab8191cf | 39 | "What is 5*2?", |
| aueangpanit | 8:8ce2ab8191cf | 40 | "what is 2+2?", |
| aueangpanit | 8:8ce2ab8191cf | 41 | "What is 5*4?"}; |
| aueangpanit | 8:8ce2ab8191cf | 42 | |
| aueangpanit | 8:8ce2ab8191cf | 43 | string screen1Answers[4] = {"4 ", "10 ", "5 ", "18 "}; |
| aueangpanit | 8:8ce2ab8191cf | 44 | string screen2Answers[4] = {"5 ", "8 ", "4 ", "20 "}; |
| aueangpanit | 8:8ce2ab8191cf | 45 | int correctScreen[4] = {1, 1, 2, 2}; //1 = screen1; 2 = screen2; |
| aueangpanit | 8:8ce2ab8191cf | 46 | |
| aueangpanit | 8:8ce2ab8191cf | 47 | int questionCount = 0; |
| simon | 0:334327d1a416 | 48 | |
| aueangpanit | 9:39190ed25585 | 49 | //all functions for jumping game |
| aueangpanit | 9:39190ed25585 | 50 | void Jumping(); |
| aueangpanit | 9:39190ed25585 | 51 | |
| aueangpanit | 9:39190ed25585 | 52 | MaxSonar *range1; |
| aueangpanit | 5:2f13ec8efe0b | 53 | float r1; |
| aueangpanit | 6:fa30f8383b99 | 54 | |
| aueangpanit | 6:fa30f8383b99 | 55 | MaxSonar *range2; |
| aueangpanit | 6:fa30f8383b99 | 56 | float r2; |
| aueangpanit | 9:39190ed25585 | 57 | int main() { |
| aueangpanit | 10:21c24327e65f | 58 | UpdateScreen(questionScreen, 3, "0", 3, "==="); |
| aueangpanit | 10:21c24327e65f | 59 | wait(5); |
| aueangpanit | 10:21c24327e65f | 60 | |
| aueangpanit | 5:2f13ec8efe0b | 61 | // Create and configure object for 3.3V powered LV-series device, |
| aueangpanit | 5:2f13ec8efe0b | 62 | // accessed with analog reads (in cm) on p16, triggered by p7. |
| aueangpanit | 5:2f13ec8efe0b | 63 | range1 = new MaxSonar(MS_LV, MS_ANALOG, PTB8, PTC2); |
| aueangpanit | 5:2f13ec8efe0b | 64 | range1->setVoltage(3.3); |
| aueangpanit | 5:2f13ec8efe0b | 65 | range1->setUnits(MS_CM); |
| aueangpanit | 5:2f13ec8efe0b | 66 | |
| aueangpanit | 6:fa30f8383b99 | 67 | range2 = new MaxSonar(MS_LV, MS_ANALOG, PTB9, PTB3); |
| aueangpanit | 6:fa30f8383b99 | 68 | range2->setVoltage(3.3); |
| aueangpanit | 6:fa30f8383b99 | 69 | range2->setUnits(MS_CM); |
| aueangpanit | 9:39190ed25585 | 70 | |
| aueangpanit | 9:39190ed25585 | 71 | ClearAllScreen(); |
| aueangpanit | 9:39190ed25585 | 72 | |
| aueangpanit | 9:39190ed25585 | 73 | GameOption(); |
| aueangpanit | 9:39190ed25585 | 74 | } |
| aueangpanit | 9:39190ed25585 | 75 | |
| aueangpanit | 9:39190ed25585 | 76 | int gameOptionLocation = 0; |
| aueangpanit | 10:21c24327e65f | 77 | string gameName[2] = {"Muti-Maths", "Pong!"}; |
| aueangpanit | 9:39190ed25585 | 78 | void GameOption() |
| aueangpanit | 9:39190ed25585 | 79 | { |
| aueangpanit | 9:39190ed25585 | 80 | ClearAllScreen(); |
| aueangpanit | 9:39190ed25585 | 81 | |
| aueangpanit | 9:39190ed25585 | 82 | UpdateScreen(questionScreen, "Select a game: >" + gameName[gameOptionLocation]); |
| aueangpanit | 9:39190ed25585 | 83 | |
| aueangpanit | 9:39190ed25585 | 84 | bool gameOption = true; |
| aueangpanit | 9:39190ed25585 | 85 | while(gameOption) |
| aueangpanit | 9:39190ed25585 | 86 | { |
| aueangpanit | 9:39190ed25585 | 87 | UpdateRange(); |
| aueangpanit | 9:39190ed25585 | 88 | |
| aueangpanit | 9:39190ed25585 | 89 | if(r1 < 25 && r2 < 25) |
| aueangpanit | 9:39190ed25585 | 90 | { |
| aueangpanit | 9:39190ed25585 | 91 | UpdateScreen(questionScreen, "Entering " + gameName[gameOptionLocation] + "....."); |
| aueangpanit | 9:39190ed25585 | 92 | wait(1); |
| aueangpanit | 9:39190ed25585 | 93 | |
| aueangpanit | 9:39190ed25585 | 94 | gameOption = false; |
| aueangpanit | 9:39190ed25585 | 95 | } |
| aueangpanit | 6:fa30f8383b99 | 96 | |
| aueangpanit | 9:39190ed25585 | 97 | else if(r1 < 20) |
| aueangpanit | 9:39190ed25585 | 98 | { |
| aueangpanit | 9:39190ed25585 | 99 | if(gameOptionLocation > 0) { gameOptionLocation--; UpdateScreen(questionScreen, "Select a game: >" + gameName[gameOptionLocation]); } |
| aueangpanit | 9:39190ed25585 | 100 | } |
| aueangpanit | 9:39190ed25585 | 101 | else if(r2 < 20) |
| aueangpanit | 9:39190ed25585 | 102 | { |
| aueangpanit | 9:39190ed25585 | 103 | if(gameOptionLocation < 1) { gameOptionLocation++; UpdateScreen(questionScreen, "Select a game: >" + gameName[gameOptionLocation]); } |
| aueangpanit | 9:39190ed25585 | 104 | } |
| aueangpanit | 9:39190ed25585 | 105 | } |
| aueangpanit | 9:39190ed25585 | 106 | |
| aueangpanit | 9:39190ed25585 | 107 | StartGame(gameOptionLocation); |
| aueangpanit | 9:39190ed25585 | 108 | } |
| aueangpanit | 9:39190ed25585 | 109 | |
| aueangpanit | 9:39190ed25585 | 110 | void StartGame(int gameOptionLocation) |
| aueangpanit | 9:39190ed25585 | 111 | { |
| aueangpanit | 9:39190ed25585 | 112 | switch(gameOptionLocation) |
| aueangpanit | 9:39190ed25585 | 113 | { |
| aueangpanit | 9:39190ed25585 | 114 | case 0: |
| aueangpanit | 9:39190ed25585 | 115 | MultiChoice(); |
| aueangpanit | 9:39190ed25585 | 116 | case 1: |
| aueangpanit | 9:39190ed25585 | 117 | Jumping(); |
| aueangpanit | 9:39190ed25585 | 118 | } |
| aueangpanit | 9:39190ed25585 | 119 | } |
| aueangpanit | 9:39190ed25585 | 120 | |
| aueangpanit | 9:39190ed25585 | 121 | void MultiChoice() |
| aueangpanit | 9:39190ed25585 | 122 | { |
| aueangpanit | 9:39190ed25585 | 123 | bool multiMaths = true; |
| aueangpanit | 9:39190ed25585 | 124 | |
| aueangpanit | 9:39190ed25585 | 125 | DisplayNewQuestion(); |
| aueangpanit | 9:39190ed25585 | 126 | while(multiMaths) { |
| aueangpanit | 9:39190ed25585 | 127 | UpdateRange(); |
| aueangpanit | 9:39190ed25585 | 128 | |
| aueangpanit | 9:39190ed25585 | 129 | if(CheckExit(r1, r2)) |
| aueangpanit | 9:39190ed25585 | 130 | { |
| aueangpanit | 9:39190ed25585 | 131 | GameOption(); |
| aueangpanit | 9:39190ed25585 | 132 | } |
| aueangpanit | 9:39190ed25585 | 133 | |
| aueangpanit | 8:8ce2ab8191cf | 134 | if(r1 < 20) |
| aueangpanit | 8:8ce2ab8191cf | 135 | { |
| aueangpanit | 8:8ce2ab8191cf | 136 | if(CheckCorrect(1)) |
| aueangpanit | 8:8ce2ab8191cf | 137 | { |
| aueangpanit | 8:8ce2ab8191cf | 138 | UpdateScreen(questionScreen, "Correct!"); |
| aueangpanit | 8:8ce2ab8191cf | 139 | wait(1); |
| aueangpanit | 8:8ce2ab8191cf | 140 | DisplayNewQuestion(); |
| aueangpanit | 8:8ce2ab8191cf | 141 | } |
| aueangpanit | 8:8ce2ab8191cf | 142 | else |
| aueangpanit | 8:8ce2ab8191cf | 143 | { |
| aueangpanit | 8:8ce2ab8191cf | 144 | UpdateScreen(questionScreen, "Try Again!"); |
| aueangpanit | 8:8ce2ab8191cf | 145 | wait(1); |
| aueangpanit | 8:8ce2ab8191cf | 146 | UpdateScreen(questionScreen, questions[questionCount]); |
| aueangpanit | 8:8ce2ab8191cf | 147 | } |
| aueangpanit | 8:8ce2ab8191cf | 148 | } |
| aueangpanit | 8:8ce2ab8191cf | 149 | if(r2 < 20) |
| aueangpanit | 8:8ce2ab8191cf | 150 | { |
| aueangpanit | 8:8ce2ab8191cf | 151 | if(CheckCorrect(2)) |
| aueangpanit | 8:8ce2ab8191cf | 152 | { |
| aueangpanit | 8:8ce2ab8191cf | 153 | UpdateScreen(questionScreen, "Correct!"); |
| aueangpanit | 8:8ce2ab8191cf | 154 | wait(1); |
| aueangpanit | 8:8ce2ab8191cf | 155 | DisplayNewQuestion(); |
| aueangpanit | 8:8ce2ab8191cf | 156 | } |
| aueangpanit | 8:8ce2ab8191cf | 157 | else |
| aueangpanit | 8:8ce2ab8191cf | 158 | { |
| aueangpanit | 8:8ce2ab8191cf | 159 | UpdateScreen(questionScreen, "Try Again!"); |
| aueangpanit | 8:8ce2ab8191cf | 160 | wait(1); |
| aueangpanit | 8:8ce2ab8191cf | 161 | UpdateScreen(questionScreen, questions[questionCount]); |
| aueangpanit | 8:8ce2ab8191cf | 162 | } |
| aueangpanit | 8:8ce2ab8191cf | 163 | } |
| aueangpanit | 8:8ce2ab8191cf | 164 | |
| aueangpanit | 5:2f13ec8efe0b | 165 | wait(0.5); |
| aueangpanit | 5:2f13ec8efe0b | 166 | } |
| aueangpanit | 4:c669026b6f6e | 167 | } |
| aueangpanit | 4:c669026b6f6e | 168 | |
| aueangpanit | 8:8ce2ab8191cf | 169 | void DisplayNewQuestion() |
| aueangpanit | 8:8ce2ab8191cf | 170 | { |
| aueangpanit | 8:8ce2ab8191cf | 171 | if(questionCount >= 3) |
| aueangpanit | 8:8ce2ab8191cf | 172 | { |
| aueangpanit | 8:8ce2ab8191cf | 173 | questionCount = 0; |
| aueangpanit | 8:8ce2ab8191cf | 174 | } |
| aueangpanit | 8:8ce2ab8191cf | 175 | else |
| aueangpanit | 8:8ce2ab8191cf | 176 | { |
| aueangpanit | 8:8ce2ab8191cf | 177 | questionCount++; |
| aueangpanit | 8:8ce2ab8191cf | 178 | } |
| aueangpanit | 8:8ce2ab8191cf | 179 | |
| aueangpanit | 8:8ce2ab8191cf | 180 | UpdateScreen(questionScreen, questions[questionCount]); |
| aueangpanit | 8:8ce2ab8191cf | 181 | UpdateScreen(screen1, screen1Answers[questionCount]); |
| aueangpanit | 8:8ce2ab8191cf | 182 | UpdateScreen(screen2, screen2Answers[questionCount]); |
| aueangpanit | 8:8ce2ab8191cf | 183 | } |
| aueangpanit | 8:8ce2ab8191cf | 184 | |
| aueangpanit | 8:8ce2ab8191cf | 185 | bool CheckCorrect(int screenNumber) |
| aueangpanit | 8:8ce2ab8191cf | 186 | { |
| aueangpanit | 8:8ce2ab8191cf | 187 | if(screenNumber == correctScreen[questionCount]) |
| aueangpanit | 8:8ce2ab8191cf | 188 | { |
| aueangpanit | 8:8ce2ab8191cf | 189 | return true; |
| aueangpanit | 8:8ce2ab8191cf | 190 | } |
| aueangpanit | 8:8ce2ab8191cf | 191 | else |
| aueangpanit | 8:8ce2ab8191cf | 192 | { |
| aueangpanit | 8:8ce2ab8191cf | 193 | return false; |
| aueangpanit | 8:8ce2ab8191cf | 194 | } |
| aueangpanit | 8:8ce2ab8191cf | 195 | } |
| aueangpanit | 8:8ce2ab8191cf | 196 | |
| aueangpanit | 9:39190ed25585 | 197 | void Jumping() |
| aueangpanit | 9:39190ed25585 | 198 | { |
| aueangpanit | 9:39190ed25585 | 199 | |
| aueangpanit | 9:39190ed25585 | 200 | } |
| aueangpanit | 9:39190ed25585 | 201 | |
| aueangpanit | 9:39190ed25585 | 202 | string exitOption[2] = {"Yes", "No"}; |
| aueangpanit | 9:39190ed25585 | 203 | bool CheckExit(float r1, float r2) |
| aueangpanit | 9:39190ed25585 | 204 | { |
| aueangpanit | 9:39190ed25585 | 205 | if(r1 < 25 && r2 < 25) |
| aueangpanit | 9:39190ed25585 | 206 | { |
| aueangpanit | 9:39190ed25585 | 207 | return ExitScreen(); |
| aueangpanit | 9:39190ed25585 | 208 | } |
| aueangpanit | 9:39190ed25585 | 209 | else |
| aueangpanit | 9:39190ed25585 | 210 | { |
| aueangpanit | 9:39190ed25585 | 211 | return false; |
| aueangpanit | 9:39190ed25585 | 212 | } |
| aueangpanit | 9:39190ed25585 | 213 | } |
| aueangpanit | 9:39190ed25585 | 214 | |
| aueangpanit | 9:39190ed25585 | 215 | bool ExitScreen() |
| aueangpanit | 9:39190ed25585 | 216 | { |
| aueangpanit | 9:39190ed25585 | 217 | int exitOption_int = 0; |
| aueangpanit | 9:39190ed25585 | 218 | UpdateScreen(questionScreen, "AreYouSureYouWantToExit? >" + exitOption[exitOption_int]); |
| aueangpanit | 9:39190ed25585 | 219 | |
| aueangpanit | 9:39190ed25585 | 220 | wait(1); |
| aueangpanit | 9:39190ed25585 | 221 | |
| aueangpanit | 9:39190ed25585 | 222 | bool choosing = true; |
| aueangpanit | 9:39190ed25585 | 223 | while(choosing) |
| aueangpanit | 9:39190ed25585 | 224 | { |
| aueangpanit | 9:39190ed25585 | 225 | wait(0.5); |
| aueangpanit | 9:39190ed25585 | 226 | UpdateRange(); |
| aueangpanit | 9:39190ed25585 | 227 | if(r1 < 25 && r2 < 25) |
| aueangpanit | 9:39190ed25585 | 228 | { |
| aueangpanit | 9:39190ed25585 | 229 | if(exitOption_int == 0) |
| aueangpanit | 9:39190ed25585 | 230 | { |
| aueangpanit | 9:39190ed25585 | 231 | choosing = false; |
| aueangpanit | 9:39190ed25585 | 232 | UpdateScreen(questionScreen, "Exiting..."); |
| aueangpanit | 9:39190ed25585 | 233 | wait(1); |
| aueangpanit | 9:39190ed25585 | 234 | return true; |
| aueangpanit | 9:39190ed25585 | 235 | } |
| aueangpanit | 9:39190ed25585 | 236 | else |
| aueangpanit | 9:39190ed25585 | 237 | { |
| aueangpanit | 9:39190ed25585 | 238 | choosing = false; |
| aueangpanit | 9:39190ed25585 | 239 | UpdateScreen(questionScreen, "Returning to game"); |
| aueangpanit | 9:39190ed25585 | 240 | wait(1); |
| aueangpanit | 9:39190ed25585 | 241 | return false; |
| aueangpanit | 9:39190ed25585 | 242 | } |
| aueangpanit | 9:39190ed25585 | 243 | } |
| aueangpanit | 9:39190ed25585 | 244 | else if(r1 < 20) |
| aueangpanit | 9:39190ed25585 | 245 | { |
| aueangpanit | 9:39190ed25585 | 246 | if(exitOption_int > 0) { exitOption_int--; UpdateScreen(questionScreen, "AreYouSureYouWantToExit? >" + exitOption[exitOption_int]); } |
| aueangpanit | 9:39190ed25585 | 247 | } |
| aueangpanit | 9:39190ed25585 | 248 | else if(r2 < 20) |
| aueangpanit | 9:39190ed25585 | 249 | { |
| aueangpanit | 9:39190ed25585 | 250 | if(exitOption_int < 1) { exitOption_int++; UpdateScreen(questionScreen, "AreYouSureYouWantToExit? >" + exitOption[exitOption_int]); } |
| aueangpanit | 9:39190ed25585 | 251 | } |
| aueangpanit | 9:39190ed25585 | 252 | } |
| aueangpanit | 9:39190ed25585 | 253 | } |
| aueangpanit | 9:39190ed25585 | 254 | |
| aueangpanit | 4:c669026b6f6e | 255 | void UpdateScreen(DigitalOut screen, string text) |
| aueangpanit | 4:c669026b6f6e | 256 | { |
| aueangpanit | 4:c669026b6f6e | 257 | //disable all E pin for all screens |
| aueangpanit | 8:8ce2ab8191cf | 258 | questionScreen = 0; |
| aueangpanit | 4:c669026b6f6e | 259 | screen1 = 0; |
| aueangpanit | 4:c669026b6f6e | 260 | screen2 = 0; |
| aueangpanit | 4:c669026b6f6e | 261 | |
| aueangpanit | 4:c669026b6f6e | 262 | //enable E pin for the scrren that we want to update |
| aueangpanit | 4:c669026b6f6e | 263 | screen = 1; |
| aueangpanit | 4:c669026b6f6e | 264 | |
| aueangpanit | 5:2f13ec8efe0b | 265 | //convert text to char array |
| aueangpanit | 5:2f13ec8efe0b | 266 | char text_char_array[1024]; |
| aueangpanit | 5:2f13ec8efe0b | 267 | strcpy(text_char_array, text.c_str()); |
| aueangpanit | 4:c669026b6f6e | 268 | //some weird behaviour after disabling the E pin once means that we need to update the screen several times for it to display properly |
| aueangpanit | 5:2f13ec8efe0b | 269 | for(int i = 0; i < 10; i++) |
| aueangpanit | 4:c669026b6f6e | 270 | { |
| aueangpanit | 3:5e0ba6e35849 | 271 | lcd.cls(); |
| aueangpanit | 4:c669026b6f6e | 272 | lcd.printf(text_char_array); |
| aueangpanit | 3:5e0ba6e35849 | 273 | } |
| aueangpanit | 5:2f13ec8efe0b | 274 | } |
| aueangpanit | 5:2f13ec8efe0b | 275 | |
| aueangpanit | 5:2f13ec8efe0b | 276 | void UpdateScreen(DigitalOut screen, char text[1024]) |
| aueangpanit | 5:2f13ec8efe0b | 277 | { |
| aueangpanit | 5:2f13ec8efe0b | 278 | //disable all E pin for all screens |
| aueangpanit | 8:8ce2ab8191cf | 279 | questionScreen = 0; |
| aueangpanit | 5:2f13ec8efe0b | 280 | screen1 = 0; |
| aueangpanit | 5:2f13ec8efe0b | 281 | screen2 = 0; |
| aueangpanit | 4:c669026b6f6e | 282 | |
| aueangpanit | 5:2f13ec8efe0b | 283 | //enable E pin for the scrren that we want to update |
| aueangpanit | 5:2f13ec8efe0b | 284 | screen = 1; |
| aueangpanit | 4:c669026b6f6e | 285 | |
| aueangpanit | 5:2f13ec8efe0b | 286 | //some weird behaviour after disabling the E pin once means that we need to update the screen several times for it to display properly |
| aueangpanit | 5:2f13ec8efe0b | 287 | for(int i = 0; i < 10; i++) |
| aueangpanit | 5:2f13ec8efe0b | 288 | { |
| aueangpanit | 5:2f13ec8efe0b | 289 | lcd.cls(); |
| aueangpanit | 5:2f13ec8efe0b | 290 | lcd.printf(text); |
| aueangpanit | 5:2f13ec8efe0b | 291 | } |
| simon | 0:334327d1a416 | 292 | } |
| aueangpanit | 9:39190ed25585 | 293 | |
| aueangpanit | 10:21c24327e65f | 294 | void UpdateScreen(DigitalOut screen, int firstLineLocation, string firstLineText, int secondLineLocation, string secondLineText) |
| aueangpanit | 10:21c24327e65f | 295 | { |
| aueangpanit | 10:21c24327e65f | 296 | //disable all E pin for all screens |
| aueangpanit | 10:21c24327e65f | 297 | questionScreen = 0; |
| aueangpanit | 10:21c24327e65f | 298 | screen1 = 0; |
| aueangpanit | 10:21c24327e65f | 299 | screen2 = 0; |
| aueangpanit | 10:21c24327e65f | 300 | |
| aueangpanit | 10:21c24327e65f | 301 | //enable E pin for the scrren that we want to update |
| aueangpanit | 10:21c24327e65f | 302 | screen = 1; |
| aueangpanit | 10:21c24327e65f | 303 | |
| aueangpanit | 10:21c24327e65f | 304 | //convert text to char array |
| aueangpanit | 10:21c24327e65f | 305 | char firstLine_char_array[1024]; |
| aueangpanit | 10:21c24327e65f | 306 | char secondLine_char_array[1024]; |
| aueangpanit | 10:21c24327e65f | 307 | strcpy(firstLine_char_array, firstLineText.c_str()); |
| aueangpanit | 10:21c24327e65f | 308 | strcpy(secondLine_char_array, secondLineText.c_str()); |
| aueangpanit | 10:21c24327e65f | 309 | |
| aueangpanit | 10:21c24327e65f | 310 | //some weird behaviour after disabling the E pin once means that we need to update the screen several times for it to display properly |
| aueangpanit | 10:21c24327e65f | 311 | for(int i = 0; i < 10; i++) |
| aueangpanit | 10:21c24327e65f | 312 | { |
| aueangpanit | 10:21c24327e65f | 313 | lcd.cls(); |
| aueangpanit | 10:21c24327e65f | 314 | lcd.locate(firstLineLocation, 0); |
| aueangpanit | 10:21c24327e65f | 315 | lcd.printf(firstLine_char_array); |
| aueangpanit | 10:21c24327e65f | 316 | lcd.locate(secondLineLocation, 1); |
| aueangpanit | 10:21c24327e65f | 317 | lcd.printf(secondLine_char_array); |
| aueangpanit | 10:21c24327e65f | 318 | } |
| aueangpanit | 10:21c24327e65f | 319 | } |
| aueangpanit | 10:21c24327e65f | 320 | |
| aueangpanit | 10:21c24327e65f | 321 | void UpdateScreen(DigitalOut screen, int firstLineLocation, char firstLineText[1024], int secondLineLocation, char secondLineText[1024]) |
| aueangpanit | 10:21c24327e65f | 322 | { |
| aueangpanit | 10:21c24327e65f | 323 | //disable all E pin for all screens |
| aueangpanit | 10:21c24327e65f | 324 | questionScreen = 0; |
| aueangpanit | 10:21c24327e65f | 325 | screen1 = 0; |
| aueangpanit | 10:21c24327e65f | 326 | screen2 = 0; |
| aueangpanit | 10:21c24327e65f | 327 | |
| aueangpanit | 10:21c24327e65f | 328 | //enable E pin for the scrren that we want to update |
| aueangpanit | 10:21c24327e65f | 329 | screen = 1; |
| aueangpanit | 10:21c24327e65f | 330 | |
| aueangpanit | 10:21c24327e65f | 331 | //some weird behaviour after disabling the E pin once means that we need to update the screen several times for it to display properly |
| aueangpanit | 10:21c24327e65f | 332 | for(int i = 0; i < 10; i++) |
| aueangpanit | 10:21c24327e65f | 333 | { |
| aueangpanit | 10:21c24327e65f | 334 | lcd.cls(); |
| aueangpanit | 10:21c24327e65f | 335 | lcd.locate(firstLineLocation, 0); |
| aueangpanit | 10:21c24327e65f | 336 | lcd.printf(firstLineText); |
| aueangpanit | 10:21c24327e65f | 337 | lcd.locate(secondLineLocation, 1); |
| aueangpanit | 10:21c24327e65f | 338 | lcd.printf(secondLineText); |
| aueangpanit | 10:21c24327e65f | 339 | } |
| aueangpanit | 10:21c24327e65f | 340 | } |
| aueangpanit | 10:21c24327e65f | 341 | |
| aueangpanit | 9:39190ed25585 | 342 | void ClearAllScreen() |
| aueangpanit | 9:39190ed25585 | 343 | { |
| aueangpanit | 9:39190ed25585 | 344 | questionScreen = 1; |
| aueangpanit | 9:39190ed25585 | 345 | screen1 = 1; |
| aueangpanit | 9:39190ed25585 | 346 | screen2 = 1; |
| aueangpanit | 9:39190ed25585 | 347 | |
| aueangpanit | 9:39190ed25585 | 348 | lcd.cls(); |
| aueangpanit | 9:39190ed25585 | 349 | } |
| aueangpanit | 9:39190ed25585 | 350 | |
| aueangpanit | 9:39190ed25585 | 351 | void UpdateRange() |
| aueangpanit | 9:39190ed25585 | 352 | { |
| aueangpanit | 9:39190ed25585 | 353 | // Trigger read, wait 49ms until ranger finder has |
| aueangpanit | 9:39190ed25585 | 354 | // finished, then read. |
| aueangpanit | 9:39190ed25585 | 355 | range1->triggerRead(); |
| aueangpanit | 9:39190ed25585 | 356 | wait_ms(49); |
| aueangpanit | 9:39190ed25585 | 357 | r1 = range1->read(); |
| aueangpanit | 9:39190ed25585 | 358 | |
| aueangpanit | 9:39190ed25585 | 359 | range2->triggerRead(); |
| aueangpanit | 9:39190ed25585 | 360 | wait_ms(49); |
| aueangpanit | 9:39190ed25585 | 361 | r2 = range2->read(); |
| aueangpanit | 9:39190ed25585 | 362 | } |
