Display text on screen.
Dependencies: TextLCD mbed MaxSonar RTC-DS1307
Fork of TextLCD_HelloWorld by
Diff: main.cpp
- Revision:
- 10:21c24327e65f
- Parent:
- 9:39190ed25585
- Child:
- 11:f6a39ae5ecbc
--- a/main.cpp Thu May 25 10:55:51 2017 +0000 +++ b/main.cpp Thu May 25 11:17:06 2017 +0000 @@ -15,6 +15,8 @@ //All functions for controlling screens 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]); void ClearAllScreen(); //All funcitons for range sensors @@ -53,6 +55,9 @@ MaxSonar *range2; float r2; int main() { + UpdateScreen(questionScreen, 3, "0", 3, "==="); + wait(5); + // Create and configure object for 3.3V powered LV-series device, // accessed with analog reads (in cm) on p16, triggered by p7. range1 = new MaxSonar(MS_LV, MS_ANALOG, PTB8, PTC2); @@ -69,7 +74,7 @@ } int gameOptionLocation = 0; -string gameName[2] = {"Muti-Maths", "Jumping!"}; +string gameName[2] = {"Muti-Maths", "Pong!"}; void GameOption() { ClearAllScreen(); @@ -286,6 +291,54 @@ } } +void UpdateScreen(DigitalOut screen, int firstLineLocation, string firstLineText, int secondLineLocation, string secondLineText) +{ + //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; + + //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()); + + //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.printf(firstLine_char_array); + lcd.locate(secondLineLocation, 1); + lcd.printf(secondLine_char_array); + } +} + +void UpdateScreen(DigitalOut screen, int firstLineLocation, char firstLineText[1024], int secondLineLocation, char secondLineText[1024]) +{ + //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++) + { + lcd.cls(); + lcd.locate(firstLineLocation, 0); + lcd.printf(firstLineText); + lcd.locate(secondLineLocation, 1); + lcd.printf(secondLineText); + } +} + void ClearAllScreen() { questionScreen = 1;