Display text on screen.

Dependencies:   TextLCD mbed MaxSonar RTC-DS1307

Fork of TextLCD_HelloWorld by Simon Ford

Committer:
aueangpanit
Date:
Thu May 25 12:09:54 2017 +0000
Revision:
12:75b8081e1304
Parent:
11:f6a39ae5ecbc
Child:
13:95eea857ed37
Pong: Player location controlled by 2 distance sensors

Who changed what in which revision?

UserRevisionLine numberNew 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 12:75b8081e1304 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 12:75b8081e1304 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 12:75b8081e1304 210 bool pong = true;
aueangpanit 12:75b8081e1304 211
aueangpanit 12:75b8081e1304 212 //player
aueangpanit 12:75b8081e1304 213 int pLocation = 5;
aueangpanit 12:75b8081e1304 214 string player = "___";
aueangpanit 12:75b8081e1304 215
aueangpanit 12:75b8081e1304 216 //ball
aueangpanit 12:75b8081e1304 217 string ball = 0;
aueangpanit 12:75b8081e1304 218
aueangpanit 12:75b8081e1304 219 int ballPX = 0;
aueangpanit 12:75b8081e1304 220 int ballPY = 0;
aueangpanit 12:75b8081e1304 221
aueangpanit 12:75b8081e1304 222 int ballVX = 1;
aueangpanit 12:75b8081e1304 223 int ballVY = 1;
aueangpanit 12:75b8081e1304 224
aueangpanit 12:75b8081e1304 225 UpdateScreen(questionScreen, "Welcome to Pong!");
aueangpanit 12:75b8081e1304 226 UpdateScreen(screen2, 0, "", pLocation, player);
aueangpanit 12:75b8081e1304 227
aueangpanit 12:75b8081e1304 228 while(pong)
aueangpanit 12:75b8081e1304 229 {
aueangpanit 12:75b8081e1304 230 UpdateRange();
aueangpanit 12:75b8081e1304 231 if(CheckExit(r1, r2))
aueangpanit 12:75b8081e1304 232 {
aueangpanit 12:75b8081e1304 233 GameOption();
aueangpanit 12:75b8081e1304 234 }
aueangpanit 9:39190ed25585 235
aueangpanit 12:75b8081e1304 236 if(r2 < 20)
aueangpanit 12:75b8081e1304 237 {
aueangpanit 12:75b8081e1304 238 if(pLocation > 0)
aueangpanit 12:75b8081e1304 239 {
aueangpanit 12:75b8081e1304 240 pLocation--;
aueangpanit 12:75b8081e1304 241 UpdateScreen(screen2, 0, "", pLocation, player);
aueangpanit 12:75b8081e1304 242 }
aueangpanit 12:75b8081e1304 243 }
aueangpanit 12:75b8081e1304 244 if(r1 < 20)
aueangpanit 12:75b8081e1304 245 {
aueangpanit 12:75b8081e1304 246 if(pLocation < 12)
aueangpanit 12:75b8081e1304 247 {
aueangpanit 12:75b8081e1304 248 pLocation++;
aueangpanit 12:75b8081e1304 249 UpdateScreen(screen2, 0, "", pLocation, player);
aueangpanit 12:75b8081e1304 250 }
aueangpanit 12:75b8081e1304 251 }
aueangpanit 12:75b8081e1304 252
aueangpanit 12:75b8081e1304 253 wait(0.5);
aueangpanit 12:75b8081e1304 254 }
aueangpanit 9:39190ed25585 255 }
aueangpanit 9:39190ed25585 256
aueangpanit 9:39190ed25585 257 string exitOption[2] = {"Yes", "No"};
aueangpanit 9:39190ed25585 258 bool CheckExit(float r1, float r2)
aueangpanit 9:39190ed25585 259 {
aueangpanit 9:39190ed25585 260 if(r1 < 25 && r2 < 25)
aueangpanit 9:39190ed25585 261 {
aueangpanit 9:39190ed25585 262 return ExitScreen();
aueangpanit 9:39190ed25585 263 }
aueangpanit 9:39190ed25585 264 else
aueangpanit 9:39190ed25585 265 {
aueangpanit 9:39190ed25585 266 return false;
aueangpanit 9:39190ed25585 267 }
aueangpanit 9:39190ed25585 268 }
aueangpanit 9:39190ed25585 269
aueangpanit 9:39190ed25585 270 bool ExitScreen()
aueangpanit 9:39190ed25585 271 {
aueangpanit 9:39190ed25585 272 int exitOption_int = 0;
aueangpanit 9:39190ed25585 273 UpdateScreen(questionScreen, "AreYouSureYouWantToExit? >" + exitOption[exitOption_int]);
aueangpanit 9:39190ed25585 274
aueangpanit 9:39190ed25585 275 wait(1);
aueangpanit 9:39190ed25585 276
aueangpanit 9:39190ed25585 277 bool choosing = true;
aueangpanit 9:39190ed25585 278 while(choosing)
aueangpanit 9:39190ed25585 279 {
aueangpanit 9:39190ed25585 280 wait(0.5);
aueangpanit 9:39190ed25585 281 UpdateRange();
aueangpanit 9:39190ed25585 282 if(r1 < 25 && r2 < 25)
aueangpanit 9:39190ed25585 283 {
aueangpanit 9:39190ed25585 284 if(exitOption_int == 0)
aueangpanit 9:39190ed25585 285 {
aueangpanit 9:39190ed25585 286 choosing = false;
aueangpanit 9:39190ed25585 287 UpdateScreen(questionScreen, "Exiting...");
aueangpanit 9:39190ed25585 288 wait(1);
aueangpanit 9:39190ed25585 289 return true;
aueangpanit 9:39190ed25585 290 }
aueangpanit 9:39190ed25585 291 else
aueangpanit 9:39190ed25585 292 {
aueangpanit 9:39190ed25585 293 choosing = false;
aueangpanit 9:39190ed25585 294 UpdateScreen(questionScreen, "Returning to game");
aueangpanit 9:39190ed25585 295 wait(1);
aueangpanit 9:39190ed25585 296 return false;
aueangpanit 9:39190ed25585 297 }
aueangpanit 9:39190ed25585 298 }
aueangpanit 9:39190ed25585 299 else if(r1 < 20)
aueangpanit 9:39190ed25585 300 {
aueangpanit 9:39190ed25585 301 if(exitOption_int > 0) { exitOption_int--; UpdateScreen(questionScreen, "AreYouSureYouWantToExit? >" + exitOption[exitOption_int]); }
aueangpanit 9:39190ed25585 302 }
aueangpanit 9:39190ed25585 303 else if(r2 < 20)
aueangpanit 9:39190ed25585 304 {
aueangpanit 9:39190ed25585 305 if(exitOption_int < 1) { exitOption_int++; UpdateScreen(questionScreen, "AreYouSureYouWantToExit? >" + exitOption[exitOption_int]); }
aueangpanit 9:39190ed25585 306 }
aueangpanit 9:39190ed25585 307 }
aueangpanit 9:39190ed25585 308 }
aueangpanit 9:39190ed25585 309
aueangpanit 4:c669026b6f6e 310 void UpdateScreen(DigitalOut screen, string text)
aueangpanit 4:c669026b6f6e 311 {
aueangpanit 4:c669026b6f6e 312 //disable all E pin for all screens
aueangpanit 8:8ce2ab8191cf 313 questionScreen = 0;
aueangpanit 4:c669026b6f6e 314 screen1 = 0;
aueangpanit 4:c669026b6f6e 315 screen2 = 0;
aueangpanit 4:c669026b6f6e 316
aueangpanit 4:c669026b6f6e 317 //enable E pin for the scrren that we want to update
aueangpanit 4:c669026b6f6e 318 screen = 1;
aueangpanit 4:c669026b6f6e 319
aueangpanit 5:2f13ec8efe0b 320 //convert text to char array
aueangpanit 5:2f13ec8efe0b 321 char text_char_array[1024];
aueangpanit 5:2f13ec8efe0b 322 strcpy(text_char_array, text.c_str());
aueangpanit 4:c669026b6f6e 323 //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 324 for(int i = 0; i < 10; i++)
aueangpanit 4:c669026b6f6e 325 {
aueangpanit 3:5e0ba6e35849 326 lcd.cls();
aueangpanit 4:c669026b6f6e 327 lcd.printf(text_char_array);
aueangpanit 3:5e0ba6e35849 328 }
aueangpanit 5:2f13ec8efe0b 329 }
aueangpanit 5:2f13ec8efe0b 330
aueangpanit 5:2f13ec8efe0b 331 void UpdateScreen(DigitalOut screen, char text[1024])
aueangpanit 5:2f13ec8efe0b 332 {
aueangpanit 5:2f13ec8efe0b 333 //disable all E pin for all screens
aueangpanit 8:8ce2ab8191cf 334 questionScreen = 0;
aueangpanit 5:2f13ec8efe0b 335 screen1 = 0;
aueangpanit 5:2f13ec8efe0b 336 screen2 = 0;
aueangpanit 4:c669026b6f6e 337
aueangpanit 5:2f13ec8efe0b 338 //enable E pin for the scrren that we want to update
aueangpanit 5:2f13ec8efe0b 339 screen = 1;
aueangpanit 4:c669026b6f6e 340
aueangpanit 5:2f13ec8efe0b 341 //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 342 for(int i = 0; i < 10; i++)
aueangpanit 5:2f13ec8efe0b 343 {
aueangpanit 5:2f13ec8efe0b 344 lcd.cls();
aueangpanit 5:2f13ec8efe0b 345 lcd.printf(text);
aueangpanit 5:2f13ec8efe0b 346 }
simon 0:334327d1a416 347 }
aueangpanit 9:39190ed25585 348
aueangpanit 10:21c24327e65f 349 void UpdateScreen(DigitalOut screen, int firstLineLocation, string firstLineText, int secondLineLocation, string secondLineText)
aueangpanit 10:21c24327e65f 350 {
aueangpanit 10:21c24327e65f 351 //disable all E pin for all screens
aueangpanit 10:21c24327e65f 352 questionScreen = 0;
aueangpanit 10:21c24327e65f 353 screen1 = 0;
aueangpanit 10:21c24327e65f 354 screen2 = 0;
aueangpanit 10:21c24327e65f 355
aueangpanit 10:21c24327e65f 356 //enable E pin for the scrren that we want to update
aueangpanit 10:21c24327e65f 357 screen = 1;
aueangpanit 10:21c24327e65f 358
aueangpanit 11:f6a39ae5ecbc 359 string line1text = GetLocationSpaces(firstLineLocation) + firstLineText;
aueangpanit 11:f6a39ae5ecbc 360 string line2text = GetLocationSpaces(secondLineLocation) + secondLineText;
aueangpanit 11:f6a39ae5ecbc 361
aueangpanit 10:21c24327e65f 362 //convert text to char array
aueangpanit 10:21c24327e65f 363 char firstLine_char_array[1024];
aueangpanit 10:21c24327e65f 364 char secondLine_char_array[1024];
aueangpanit 11:f6a39ae5ecbc 365 strcpy(firstLine_char_array, line1text.c_str());
aueangpanit 11:f6a39ae5ecbc 366 strcpy(secondLine_char_array, line2text.c_str());
aueangpanit 10:21c24327e65f 367
aueangpanit 10:21c24327e65f 368 //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 369 for(int i = 0; i < 10; i++)
aueangpanit 10:21c24327e65f 370 {
aueangpanit 10:21c24327e65f 371 lcd.cls();
aueangpanit 11:f6a39ae5ecbc 372 lcd.locate(0, 0);
aueangpanit 10:21c24327e65f 373 lcd.printf(firstLine_char_array);
aueangpanit 11:f6a39ae5ecbc 374 lcd.locate(0, 1);
aueangpanit 10:21c24327e65f 375 lcd.printf(secondLine_char_array);
aueangpanit 10:21c24327e65f 376 }
aueangpanit 10:21c24327e65f 377 }
aueangpanit 10:21c24327e65f 378
aueangpanit 11:f6a39ae5ecbc 379 string GetLocationSpaces(int location)
aueangpanit 10:21c24327e65f 380 {
aueangpanit 11:f6a39ae5ecbc 381 string space = "";
aueangpanit 11:f6a39ae5ecbc 382 for(int i = 0; i < location; i++)
aueangpanit 10:21c24327e65f 383 {
aueangpanit 11:f6a39ae5ecbc 384 space += " ";
aueangpanit 11:f6a39ae5ecbc 385 }
aueangpanit 11:f6a39ae5ecbc 386 return space;
aueangpanit 10:21c24327e65f 387 }
aueangpanit 10:21c24327e65f 388
aueangpanit 9:39190ed25585 389 void ClearAllScreen()
aueangpanit 9:39190ed25585 390 {
aueangpanit 9:39190ed25585 391 questionScreen = 1;
aueangpanit 9:39190ed25585 392 screen1 = 1;
aueangpanit 9:39190ed25585 393 screen2 = 1;
aueangpanit 9:39190ed25585 394
aueangpanit 9:39190ed25585 395 lcd.cls();
aueangpanit 9:39190ed25585 396 }
aueangpanit 9:39190ed25585 397
aueangpanit 9:39190ed25585 398 void UpdateRange()
aueangpanit 9:39190ed25585 399 {
aueangpanit 9:39190ed25585 400 // Trigger read, wait 49ms until ranger finder has
aueangpanit 9:39190ed25585 401 // finished, then read.
aueangpanit 9:39190ed25585 402 range1->triggerRead();
aueangpanit 9:39190ed25585 403 wait_ms(49);
aueangpanit 9:39190ed25585 404 r1 = range1->read();
aueangpanit 9:39190ed25585 405
aueangpanit 9:39190ed25585 406 range2->triggerRead();
aueangpanit 9:39190ed25585 407 wait_ms(49);
aueangpanit 9:39190ed25585 408 r2 = range2->read();
aueangpanit 9:39190ed25585 409 }