Display text on screen.

Dependencies:   TextLCD mbed MaxSonar RTC-DS1307

Fork of TextLCD_HelloWorld by Simon Ford

Revision:
11:f6a39ae5ecbc
Parent:
10:21c24327e65f
Child:
12:75b8081e1304
--- a/main.cpp	Thu May 25 11:17:06 2017 +0000
+++ b/main.cpp	Thu May 25 11:55:41 2017 +0000
@@ -16,7 +16,7 @@
 void UpdateScreen(DigitalOut screen, string text);
 void UpdateScreen(DigitalOut screen, char text[1024]);
 void UpdateScreen(DigitalOut screen, int firstLineLocation, string firstLineText, int secondLineLocation, string secondLineText);
-void UpdateScreen(DigitalOut screen, int firstLineLocation, char firstLineText[1024], int secondLineLocation, char secondLineText[1024]);
+string GetLocationSpaces(int location);
 void ClearAllScreen();
 
 //All funcitons for range sensors
@@ -46,8 +46,8 @@
 
 int questionCount = 0;
 
-//all functions for jumping game
-void Jumping();
+//all functions for pong game
+void Pong();
 
 MaxSonar *range1;
     float r1;
@@ -55,7 +55,18 @@
     MaxSonar *range2;
     float r2;
 int main() {
-    UpdateScreen(questionScreen, 3, "0", 3, "===");
+    
+    UpdateScreen(questionScreen, 5, "0", 7, "___");
+    
+    /*questionScreen = 1;
+    
+    for(int i = 0; i < 10; i++){
+        lcd.cls();
+        lcd.locate(2, 0);
+        lcd.printf("0");
+        lcd.locate(2, 1);
+        lcd.printf("===");
+    }*/
     wait(5);
     
     // Create and configure object for 3.3V powered LV-series device, 
@@ -114,7 +125,7 @@
         case 0:
             MultiChoice();
         case 1:
-            Jumping();
+            Pong();
     }    
 }
 
@@ -194,7 +205,7 @@
     }
 }
 
-void Jumping()
+void Pong()
 {
         
 }
@@ -301,42 +312,34 @@
     //enable E pin for the scrren that we want to update
     screen = 1;
     
+    string line1text = GetLocationSpaces(firstLineLocation) + firstLineText;
+    string line2text = GetLocationSpaces(secondLineLocation) + secondLineText;
+    
     //convert text to char array
     char firstLine_char_array[1024];
     char secondLine_char_array[1024];
-    strcpy(firstLine_char_array, firstLineText.c_str());
-    strcpy(secondLine_char_array, secondLineText.c_str());
+    strcpy(firstLine_char_array, line1text.c_str());
+    strcpy(secondLine_char_array, line2text.c_str());
     
     //some weird behaviour after disabling the E pin once means that we need to update the screen several times for it to display properly
     for(int i = 0; i < 10; i++)
     {
         lcd.cls();
-        lcd.locate(firstLineLocation, 0);
+        lcd.locate(0, 0);
         lcd.printf(firstLine_char_array);
-        lcd.locate(secondLineLocation, 1);
+        lcd.locate(0, 1);
         lcd.printf(secondLine_char_array);
     }
 }
 
-void UpdateScreen(DigitalOut screen, int firstLineLocation, char firstLineText[1024], int secondLineLocation, char secondLineText[1024])
+string GetLocationSpaces(int location)
 {
-    //disable all E pin for all screens
-    questionScreen = 0;
-    screen1 = 0;
-    screen2 = 0;
-        
-    //enable E pin for the scrren that we want to update
-    screen = 1;
-    
-    //some weird behaviour after disabling the E pin once means that we need to update the screen several times for it to display properly
-    for(int i = 0; i < 10; i++)
+    string space = "";
+    for(int i = 0; i < location; i++)
     {
-        lcd.cls();
-        lcd.locate(firstLineLocation, 0);
-        lcd.printf(firstLineText);
-        lcd.locate(secondLineLocation, 1);
-        lcd.printf(secondLineText);
-    }
+        space += " ";
+    }    
+    return space;
 }
 
 void ClearAllScreen()