Display text on screen.
Dependencies: TextLCD mbed MaxSonar RTC-DS1307
Fork of TextLCD_HelloWorld by
main.cpp@11:f6a39ae5ecbc, 2017-05-25 (annotated)
- Committer:
- aueangpanit
- Date:
- Thu May 25 11:55:41 2017 +0000
- Revision:
- 11:f6a39ae5ecbc
- Parent:
- 10:21c24327e65f
- Child:
- 12:75b8081e1304
working text location function on screen
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 | 11:f6a39ae5ecbc | 19 | string GetLocationSpaces(int location); |
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 | 11:f6a39ae5ecbc | 49 | //all functions for pong game |
aueangpanit | 11:f6a39ae5ecbc | 50 | void Pong(); |
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 | 11:f6a39ae5ecbc | 58 | |
aueangpanit | 11:f6a39ae5ecbc | 59 | UpdateScreen(questionScreen, 5, "0", 7, "___"); |
aueangpanit | 11:f6a39ae5ecbc | 60 | |
aueangpanit | 11:f6a39ae5ecbc | 61 | /*questionScreen = 1; |
aueangpanit | 11:f6a39ae5ecbc | 62 | |
aueangpanit | 11:f6a39ae5ecbc | 63 | for(int i = 0; i < 10; i++){ |
aueangpanit | 11:f6a39ae5ecbc | 64 | lcd.cls(); |
aueangpanit | 11:f6a39ae5ecbc | 65 | lcd.locate(2, 0); |
aueangpanit | 11:f6a39ae5ecbc | 66 | lcd.printf("0"); |
aueangpanit | 11:f6a39ae5ecbc | 67 | lcd.locate(2, 1); |
aueangpanit | 11:f6a39ae5ecbc | 68 | lcd.printf("==="); |
aueangpanit | 11:f6a39ae5ecbc | 69 | }*/ |
aueangpanit | 10:21c24327e65f | 70 | wait(5); |
aueangpanit | 10:21c24327e65f | 71 | |
aueangpanit | 5:2f13ec8efe0b | 72 | // Create and configure object for 3.3V powered LV-series device, |
aueangpanit | 5:2f13ec8efe0b | 73 | // accessed with analog reads (in cm) on p16, triggered by p7. |
aueangpanit | 5:2f13ec8efe0b | 74 | range1 = new MaxSonar(MS_LV, MS_ANALOG, PTB8, PTC2); |
aueangpanit | 5:2f13ec8efe0b | 75 | range1->setVoltage(3.3); |
aueangpanit | 5:2f13ec8efe0b | 76 | range1->setUnits(MS_CM); |
aueangpanit | 5:2f13ec8efe0b | 77 | |
aueangpanit | 6:fa30f8383b99 | 78 | range2 = new MaxSonar(MS_LV, MS_ANALOG, PTB9, PTB3); |
aueangpanit | 6:fa30f8383b99 | 79 | range2->setVoltage(3.3); |
aueangpanit | 6:fa30f8383b99 | 80 | range2->setUnits(MS_CM); |
aueangpanit | 9:39190ed25585 | 81 | |
aueangpanit | 9:39190ed25585 | 82 | ClearAllScreen(); |
aueangpanit | 9:39190ed25585 | 83 | |
aueangpanit | 9:39190ed25585 | 84 | GameOption(); |
aueangpanit | 9:39190ed25585 | 85 | } |
aueangpanit | 9:39190ed25585 | 86 | |
aueangpanit | 9:39190ed25585 | 87 | int gameOptionLocation = 0; |
aueangpanit | 10:21c24327e65f | 88 | string gameName[2] = {"Muti-Maths", "Pong!"}; |
aueangpanit | 9:39190ed25585 | 89 | void GameOption() |
aueangpanit | 9:39190ed25585 | 90 | { |
aueangpanit | 9:39190ed25585 | 91 | ClearAllScreen(); |
aueangpanit | 9:39190ed25585 | 92 | |
aueangpanit | 9:39190ed25585 | 93 | UpdateScreen(questionScreen, "Select a game: >" + gameName[gameOptionLocation]); |
aueangpanit | 9:39190ed25585 | 94 | |
aueangpanit | 9:39190ed25585 | 95 | bool gameOption = true; |
aueangpanit | 9:39190ed25585 | 96 | while(gameOption) |
aueangpanit | 9:39190ed25585 | 97 | { |
aueangpanit | 9:39190ed25585 | 98 | UpdateRange(); |
aueangpanit | 9:39190ed25585 | 99 | |
aueangpanit | 9:39190ed25585 | 100 | if(r1 < 25 && r2 < 25) |
aueangpanit | 9:39190ed25585 | 101 | { |
aueangpanit | 9:39190ed25585 | 102 | UpdateScreen(questionScreen, "Entering " + gameName[gameOptionLocation] + "....."); |
aueangpanit | 9:39190ed25585 | 103 | wait(1); |
aueangpanit | 9:39190ed25585 | 104 | |
aueangpanit | 9:39190ed25585 | 105 | gameOption = false; |
aueangpanit | 9:39190ed25585 | 106 | } |
aueangpanit | 6:fa30f8383b99 | 107 | |
aueangpanit | 9:39190ed25585 | 108 | else if(r1 < 20) |
aueangpanit | 9:39190ed25585 | 109 | { |
aueangpanit | 9:39190ed25585 | 110 | if(gameOptionLocation > 0) { gameOptionLocation--; UpdateScreen(questionScreen, "Select a game: >" + gameName[gameOptionLocation]); } |
aueangpanit | 9:39190ed25585 | 111 | } |
aueangpanit | 9:39190ed25585 | 112 | else if(r2 < 20) |
aueangpanit | 9:39190ed25585 | 113 | { |
aueangpanit | 9:39190ed25585 | 114 | if(gameOptionLocation < 1) { gameOptionLocation++; UpdateScreen(questionScreen, "Select a game: >" + gameName[gameOptionLocation]); } |
aueangpanit | 9:39190ed25585 | 115 | } |
aueangpanit | 9:39190ed25585 | 116 | } |
aueangpanit | 9:39190ed25585 | 117 | |
aueangpanit | 9:39190ed25585 | 118 | StartGame(gameOptionLocation); |
aueangpanit | 9:39190ed25585 | 119 | } |
aueangpanit | 9:39190ed25585 | 120 | |
aueangpanit | 9:39190ed25585 | 121 | void StartGame(int gameOptionLocation) |
aueangpanit | 9:39190ed25585 | 122 | { |
aueangpanit | 9:39190ed25585 | 123 | switch(gameOptionLocation) |
aueangpanit | 9:39190ed25585 | 124 | { |
aueangpanit | 9:39190ed25585 | 125 | case 0: |
aueangpanit | 9:39190ed25585 | 126 | MultiChoice(); |
aueangpanit | 9:39190ed25585 | 127 | case 1: |
aueangpanit | 11:f6a39ae5ecbc | 128 | Pong(); |
aueangpanit | 9:39190ed25585 | 129 | } |
aueangpanit | 9:39190ed25585 | 130 | } |
aueangpanit | 9:39190ed25585 | 131 | |
aueangpanit | 9:39190ed25585 | 132 | void MultiChoice() |
aueangpanit | 9:39190ed25585 | 133 | { |
aueangpanit | 9:39190ed25585 | 134 | bool multiMaths = true; |
aueangpanit | 9:39190ed25585 | 135 | |
aueangpanit | 9:39190ed25585 | 136 | DisplayNewQuestion(); |
aueangpanit | 9:39190ed25585 | 137 | while(multiMaths) { |
aueangpanit | 9:39190ed25585 | 138 | UpdateRange(); |
aueangpanit | 9:39190ed25585 | 139 | |
aueangpanit | 9:39190ed25585 | 140 | if(CheckExit(r1, r2)) |
aueangpanit | 9:39190ed25585 | 141 | { |
aueangpanit | 9:39190ed25585 | 142 | GameOption(); |
aueangpanit | 9:39190ed25585 | 143 | } |
aueangpanit | 9:39190ed25585 | 144 | |
aueangpanit | 8:8ce2ab8191cf | 145 | if(r1 < 20) |
aueangpanit | 8:8ce2ab8191cf | 146 | { |
aueangpanit | 8:8ce2ab8191cf | 147 | if(CheckCorrect(1)) |
aueangpanit | 8:8ce2ab8191cf | 148 | { |
aueangpanit | 8:8ce2ab8191cf | 149 | UpdateScreen(questionScreen, "Correct!"); |
aueangpanit | 8:8ce2ab8191cf | 150 | wait(1); |
aueangpanit | 8:8ce2ab8191cf | 151 | DisplayNewQuestion(); |
aueangpanit | 8:8ce2ab8191cf | 152 | } |
aueangpanit | 8:8ce2ab8191cf | 153 | else |
aueangpanit | 8:8ce2ab8191cf | 154 | { |
aueangpanit | 8:8ce2ab8191cf | 155 | UpdateScreen(questionScreen, "Try Again!"); |
aueangpanit | 8:8ce2ab8191cf | 156 | wait(1); |
aueangpanit | 8:8ce2ab8191cf | 157 | UpdateScreen(questionScreen, questions[questionCount]); |
aueangpanit | 8:8ce2ab8191cf | 158 | } |
aueangpanit | 8:8ce2ab8191cf | 159 | } |
aueangpanit | 8:8ce2ab8191cf | 160 | if(r2 < 20) |
aueangpanit | 8:8ce2ab8191cf | 161 | { |
aueangpanit | 8:8ce2ab8191cf | 162 | if(CheckCorrect(2)) |
aueangpanit | 8:8ce2ab8191cf | 163 | { |
aueangpanit | 8:8ce2ab8191cf | 164 | UpdateScreen(questionScreen, "Correct!"); |
aueangpanit | 8:8ce2ab8191cf | 165 | wait(1); |
aueangpanit | 8:8ce2ab8191cf | 166 | DisplayNewQuestion(); |
aueangpanit | 8:8ce2ab8191cf | 167 | } |
aueangpanit | 8:8ce2ab8191cf | 168 | else |
aueangpanit | 8:8ce2ab8191cf | 169 | { |
aueangpanit | 8:8ce2ab8191cf | 170 | UpdateScreen(questionScreen, "Try Again!"); |
aueangpanit | 8:8ce2ab8191cf | 171 | wait(1); |
aueangpanit | 8:8ce2ab8191cf | 172 | UpdateScreen(questionScreen, questions[questionCount]); |
aueangpanit | 8:8ce2ab8191cf | 173 | } |
aueangpanit | 8:8ce2ab8191cf | 174 | } |
aueangpanit | 8:8ce2ab8191cf | 175 | |
aueangpanit | 5:2f13ec8efe0b | 176 | wait(0.5); |
aueangpanit | 5:2f13ec8efe0b | 177 | } |
aueangpanit | 4:c669026b6f6e | 178 | } |
aueangpanit | 4:c669026b6f6e | 179 | |
aueangpanit | 8:8ce2ab8191cf | 180 | void DisplayNewQuestion() |
aueangpanit | 8:8ce2ab8191cf | 181 | { |
aueangpanit | 8:8ce2ab8191cf | 182 | if(questionCount >= 3) |
aueangpanit | 8:8ce2ab8191cf | 183 | { |
aueangpanit | 8:8ce2ab8191cf | 184 | questionCount = 0; |
aueangpanit | 8:8ce2ab8191cf | 185 | } |
aueangpanit | 8:8ce2ab8191cf | 186 | else |
aueangpanit | 8:8ce2ab8191cf | 187 | { |
aueangpanit | 8:8ce2ab8191cf | 188 | questionCount++; |
aueangpanit | 8:8ce2ab8191cf | 189 | } |
aueangpanit | 8:8ce2ab8191cf | 190 | |
aueangpanit | 8:8ce2ab8191cf | 191 | UpdateScreen(questionScreen, questions[questionCount]); |
aueangpanit | 8:8ce2ab8191cf | 192 | UpdateScreen(screen1, screen1Answers[questionCount]); |
aueangpanit | 8:8ce2ab8191cf | 193 | UpdateScreen(screen2, screen2Answers[questionCount]); |
aueangpanit | 8:8ce2ab8191cf | 194 | } |
aueangpanit | 8:8ce2ab8191cf | 195 | |
aueangpanit | 8:8ce2ab8191cf | 196 | bool CheckCorrect(int screenNumber) |
aueangpanit | 8:8ce2ab8191cf | 197 | { |
aueangpanit | 8:8ce2ab8191cf | 198 | if(screenNumber == correctScreen[questionCount]) |
aueangpanit | 8:8ce2ab8191cf | 199 | { |
aueangpanit | 8:8ce2ab8191cf | 200 | return true; |
aueangpanit | 8:8ce2ab8191cf | 201 | } |
aueangpanit | 8:8ce2ab8191cf | 202 | else |
aueangpanit | 8:8ce2ab8191cf | 203 | { |
aueangpanit | 8:8ce2ab8191cf | 204 | return false; |
aueangpanit | 8:8ce2ab8191cf | 205 | } |
aueangpanit | 8:8ce2ab8191cf | 206 | } |
aueangpanit | 8:8ce2ab8191cf | 207 | |
aueangpanit | 11:f6a39ae5ecbc | 208 | void Pong() |
aueangpanit | 9:39190ed25585 | 209 | { |
aueangpanit | 9:39190ed25585 | 210 | |
aueangpanit | 9:39190ed25585 | 211 | } |
aueangpanit | 9:39190ed25585 | 212 | |
aueangpanit | 9:39190ed25585 | 213 | string exitOption[2] = {"Yes", "No"}; |
aueangpanit | 9:39190ed25585 | 214 | bool CheckExit(float r1, float r2) |
aueangpanit | 9:39190ed25585 | 215 | { |
aueangpanit | 9:39190ed25585 | 216 | if(r1 < 25 && r2 < 25) |
aueangpanit | 9:39190ed25585 | 217 | { |
aueangpanit | 9:39190ed25585 | 218 | return ExitScreen(); |
aueangpanit | 9:39190ed25585 | 219 | } |
aueangpanit | 9:39190ed25585 | 220 | else |
aueangpanit | 9:39190ed25585 | 221 | { |
aueangpanit | 9:39190ed25585 | 222 | return false; |
aueangpanit | 9:39190ed25585 | 223 | } |
aueangpanit | 9:39190ed25585 | 224 | } |
aueangpanit | 9:39190ed25585 | 225 | |
aueangpanit | 9:39190ed25585 | 226 | bool ExitScreen() |
aueangpanit | 9:39190ed25585 | 227 | { |
aueangpanit | 9:39190ed25585 | 228 | int exitOption_int = 0; |
aueangpanit | 9:39190ed25585 | 229 | UpdateScreen(questionScreen, "AreYouSureYouWantToExit? >" + exitOption[exitOption_int]); |
aueangpanit | 9:39190ed25585 | 230 | |
aueangpanit | 9:39190ed25585 | 231 | wait(1); |
aueangpanit | 9:39190ed25585 | 232 | |
aueangpanit | 9:39190ed25585 | 233 | bool choosing = true; |
aueangpanit | 9:39190ed25585 | 234 | while(choosing) |
aueangpanit | 9:39190ed25585 | 235 | { |
aueangpanit | 9:39190ed25585 | 236 | wait(0.5); |
aueangpanit | 9:39190ed25585 | 237 | UpdateRange(); |
aueangpanit | 9:39190ed25585 | 238 | if(r1 < 25 && r2 < 25) |
aueangpanit | 9:39190ed25585 | 239 | { |
aueangpanit | 9:39190ed25585 | 240 | if(exitOption_int == 0) |
aueangpanit | 9:39190ed25585 | 241 | { |
aueangpanit | 9:39190ed25585 | 242 | choosing = false; |
aueangpanit | 9:39190ed25585 | 243 | UpdateScreen(questionScreen, "Exiting..."); |
aueangpanit | 9:39190ed25585 | 244 | wait(1); |
aueangpanit | 9:39190ed25585 | 245 | return true; |
aueangpanit | 9:39190ed25585 | 246 | } |
aueangpanit | 9:39190ed25585 | 247 | else |
aueangpanit | 9:39190ed25585 | 248 | { |
aueangpanit | 9:39190ed25585 | 249 | choosing = false; |
aueangpanit | 9:39190ed25585 | 250 | UpdateScreen(questionScreen, "Returning to game"); |
aueangpanit | 9:39190ed25585 | 251 | wait(1); |
aueangpanit | 9:39190ed25585 | 252 | return false; |
aueangpanit | 9:39190ed25585 | 253 | } |
aueangpanit | 9:39190ed25585 | 254 | } |
aueangpanit | 9:39190ed25585 | 255 | else if(r1 < 20) |
aueangpanit | 9:39190ed25585 | 256 | { |
aueangpanit | 9:39190ed25585 | 257 | if(exitOption_int > 0) { exitOption_int--; UpdateScreen(questionScreen, "AreYouSureYouWantToExit? >" + exitOption[exitOption_int]); } |
aueangpanit | 9:39190ed25585 | 258 | } |
aueangpanit | 9:39190ed25585 | 259 | else if(r2 < 20) |
aueangpanit | 9:39190ed25585 | 260 | { |
aueangpanit | 9:39190ed25585 | 261 | if(exitOption_int < 1) { exitOption_int++; UpdateScreen(questionScreen, "AreYouSureYouWantToExit? >" + exitOption[exitOption_int]); } |
aueangpanit | 9:39190ed25585 | 262 | } |
aueangpanit | 9:39190ed25585 | 263 | } |
aueangpanit | 9:39190ed25585 | 264 | } |
aueangpanit | 9:39190ed25585 | 265 | |
aueangpanit | 4:c669026b6f6e | 266 | void UpdateScreen(DigitalOut screen, string text) |
aueangpanit | 4:c669026b6f6e | 267 | { |
aueangpanit | 4:c669026b6f6e | 268 | //disable all E pin for all screens |
aueangpanit | 8:8ce2ab8191cf | 269 | questionScreen = 0; |
aueangpanit | 4:c669026b6f6e | 270 | screen1 = 0; |
aueangpanit | 4:c669026b6f6e | 271 | screen2 = 0; |
aueangpanit | 4:c669026b6f6e | 272 | |
aueangpanit | 4:c669026b6f6e | 273 | //enable E pin for the scrren that we want to update |
aueangpanit | 4:c669026b6f6e | 274 | screen = 1; |
aueangpanit | 4:c669026b6f6e | 275 | |
aueangpanit | 5:2f13ec8efe0b | 276 | //convert text to char array |
aueangpanit | 5:2f13ec8efe0b | 277 | char text_char_array[1024]; |
aueangpanit | 5:2f13ec8efe0b | 278 | strcpy(text_char_array, text.c_str()); |
aueangpanit | 4:c669026b6f6e | 279 | //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 | 280 | for(int i = 0; i < 10; i++) |
aueangpanit | 4:c669026b6f6e | 281 | { |
aueangpanit | 3:5e0ba6e35849 | 282 | lcd.cls(); |
aueangpanit | 4:c669026b6f6e | 283 | lcd.printf(text_char_array); |
aueangpanit | 3:5e0ba6e35849 | 284 | } |
aueangpanit | 5:2f13ec8efe0b | 285 | } |
aueangpanit | 5:2f13ec8efe0b | 286 | |
aueangpanit | 5:2f13ec8efe0b | 287 | void UpdateScreen(DigitalOut screen, char text[1024]) |
aueangpanit | 5:2f13ec8efe0b | 288 | { |
aueangpanit | 5:2f13ec8efe0b | 289 | //disable all E pin for all screens |
aueangpanit | 8:8ce2ab8191cf | 290 | questionScreen = 0; |
aueangpanit | 5:2f13ec8efe0b | 291 | screen1 = 0; |
aueangpanit | 5:2f13ec8efe0b | 292 | screen2 = 0; |
aueangpanit | 4:c669026b6f6e | 293 | |
aueangpanit | 5:2f13ec8efe0b | 294 | //enable E pin for the scrren that we want to update |
aueangpanit | 5:2f13ec8efe0b | 295 | screen = 1; |
aueangpanit | 4:c669026b6f6e | 296 | |
aueangpanit | 5:2f13ec8efe0b | 297 | //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 | 298 | for(int i = 0; i < 10; i++) |
aueangpanit | 5:2f13ec8efe0b | 299 | { |
aueangpanit | 5:2f13ec8efe0b | 300 | lcd.cls(); |
aueangpanit | 5:2f13ec8efe0b | 301 | lcd.printf(text); |
aueangpanit | 5:2f13ec8efe0b | 302 | } |
simon | 0:334327d1a416 | 303 | } |
aueangpanit | 9:39190ed25585 | 304 | |
aueangpanit | 10:21c24327e65f | 305 | void UpdateScreen(DigitalOut screen, int firstLineLocation, string firstLineText, int secondLineLocation, string secondLineText) |
aueangpanit | 10:21c24327e65f | 306 | { |
aueangpanit | 10:21c24327e65f | 307 | //disable all E pin for all screens |
aueangpanit | 10:21c24327e65f | 308 | questionScreen = 0; |
aueangpanit | 10:21c24327e65f | 309 | screen1 = 0; |
aueangpanit | 10:21c24327e65f | 310 | screen2 = 0; |
aueangpanit | 10:21c24327e65f | 311 | |
aueangpanit | 10:21c24327e65f | 312 | //enable E pin for the scrren that we want to update |
aueangpanit | 10:21c24327e65f | 313 | screen = 1; |
aueangpanit | 10:21c24327e65f | 314 | |
aueangpanit | 11:f6a39ae5ecbc | 315 | string line1text = GetLocationSpaces(firstLineLocation) + firstLineText; |
aueangpanit | 11:f6a39ae5ecbc | 316 | string line2text = GetLocationSpaces(secondLineLocation) + secondLineText; |
aueangpanit | 11:f6a39ae5ecbc | 317 | |
aueangpanit | 10:21c24327e65f | 318 | //convert text to char array |
aueangpanit | 10:21c24327e65f | 319 | char firstLine_char_array[1024]; |
aueangpanit | 10:21c24327e65f | 320 | char secondLine_char_array[1024]; |
aueangpanit | 11:f6a39ae5ecbc | 321 | strcpy(firstLine_char_array, line1text.c_str()); |
aueangpanit | 11:f6a39ae5ecbc | 322 | strcpy(secondLine_char_array, line2text.c_str()); |
aueangpanit | 10:21c24327e65f | 323 | |
aueangpanit | 10:21c24327e65f | 324 | //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 | 325 | for(int i = 0; i < 10; i++) |
aueangpanit | 10:21c24327e65f | 326 | { |
aueangpanit | 10:21c24327e65f | 327 | lcd.cls(); |
aueangpanit | 11:f6a39ae5ecbc | 328 | lcd.locate(0, 0); |
aueangpanit | 10:21c24327e65f | 329 | lcd.printf(firstLine_char_array); |
aueangpanit | 11:f6a39ae5ecbc | 330 | lcd.locate(0, 1); |
aueangpanit | 10:21c24327e65f | 331 | lcd.printf(secondLine_char_array); |
aueangpanit | 10:21c24327e65f | 332 | } |
aueangpanit | 10:21c24327e65f | 333 | } |
aueangpanit | 10:21c24327e65f | 334 | |
aueangpanit | 11:f6a39ae5ecbc | 335 | string GetLocationSpaces(int location) |
aueangpanit | 10:21c24327e65f | 336 | { |
aueangpanit | 11:f6a39ae5ecbc | 337 | string space = ""; |
aueangpanit | 11:f6a39ae5ecbc | 338 | for(int i = 0; i < location; i++) |
aueangpanit | 10:21c24327e65f | 339 | { |
aueangpanit | 11:f6a39ae5ecbc | 340 | space += " "; |
aueangpanit | 11:f6a39ae5ecbc | 341 | } |
aueangpanit | 11:f6a39ae5ecbc | 342 | return space; |
aueangpanit | 10:21c24327e65f | 343 | } |
aueangpanit | 10:21c24327e65f | 344 | |
aueangpanit | 9:39190ed25585 | 345 | void ClearAllScreen() |
aueangpanit | 9:39190ed25585 | 346 | { |
aueangpanit | 9:39190ed25585 | 347 | questionScreen = 1; |
aueangpanit | 9:39190ed25585 | 348 | screen1 = 1; |
aueangpanit | 9:39190ed25585 | 349 | screen2 = 1; |
aueangpanit | 9:39190ed25585 | 350 | |
aueangpanit | 9:39190ed25585 | 351 | lcd.cls(); |
aueangpanit | 9:39190ed25585 | 352 | } |
aueangpanit | 9:39190ed25585 | 353 | |
aueangpanit | 9:39190ed25585 | 354 | void UpdateRange() |
aueangpanit | 9:39190ed25585 | 355 | { |
aueangpanit | 9:39190ed25585 | 356 | // Trigger read, wait 49ms until ranger finder has |
aueangpanit | 9:39190ed25585 | 357 | // finished, then read. |
aueangpanit | 9:39190ed25585 | 358 | range1->triggerRead(); |
aueangpanit | 9:39190ed25585 | 359 | wait_ms(49); |
aueangpanit | 9:39190ed25585 | 360 | r1 = range1->read(); |
aueangpanit | 9:39190ed25585 | 361 | |
aueangpanit | 9:39190ed25585 | 362 | range2->triggerRead(); |
aueangpanit | 9:39190ed25585 | 363 | wait_ms(49); |
aueangpanit | 9:39190ed25585 | 364 | r2 = range2->read(); |
aueangpanit | 9:39190ed25585 | 365 | } |