jk
Junior Member
Posts: 10
|
Post by jk on Feb 26, 2015 11:56:27 GMT -8
I just started to write the first programs with my new GD2. I tried the simple few lines below to print 2 textlines one after the other . void setup() { GD.begin(); GD.ClearColorRGB(0x7080bb); GD.Clear(); GD.cmd_text(240, 136, 31, OPT_CENTER, "Hello world"); GD.swap(); // show the first text delay(2000); GD.cmd_text(200, 180, 31, OPT_CENTER, "2. Zeile"); GD.swap(); // show 2nd after a short delay } void loop() { }Result: 1st text is shown well, but instead of the 2nd vertikal lines are drawn from top to bottom and the first text dissapears. Leaving out the first swap shows both texts at the samt time, as expected. , what's wrong.
|
|
Pix-OS
Junior Member
Posts: 11
|
Post by Pix-OS on Feb 28, 2015 13:17:46 GMT -8
i think you forgot to re-clear the screen between the delay and th second GD.cmd_text. as the gd.swap clear the buffer, meaning that the clear event must be called again as well here's the corrected code. void setup() { GD.begin(); GD.ClearColorRGB(0x7080bb); GD.Clear(); GD.cmd_text(240, 136, 31, OPT_CENTER, "Hello world"); GD.swap(); // show the first text delay(2000); GD.ClearColorRGB(0x7080bb); GD.Clear(); GD.cmd_text(200, 180, 31, OPT_CENTER, "2. Zeile"); GD.swap(); // show 2nd after a short delay } void loop() { }
|
|
|
Post by jamesbowman on Feb 28, 2015 18:55:48 GMT -8
Or even:
static void showmessage(const char *s) { GD.ClearColorRGB(0x7080bb); GD.Clear(); GD.cmd_text(240, 136, 31, OPT_CENTER, s); GD.swap(); }
void setup() { GD.begin(); showmessage("Hello world"); delay(2000); showmessage("2. Zeile"); }
void loop() { }
|
|
jk
Junior Member
Posts: 10
|
Post by jk on Mar 1, 2015 5:03:50 GMT -8
Thanks a lot, I will try it.
|
|
jk
Junior Member
Posts: 10
|
Post by jk on Mar 1, 2015 8:06:53 GMT -8
Both proposals work well. So the process is that a new page is drawn and swapped to 'visible' - that's clear. My intent was to add a text ("Zeile 2") as an additional 'message' to an existing page, without writing the code for the whole old page again & the message. Would that also be possible, perhaps writing the messagetext directly to memory?
Another question to James: What is the advantage to declare the function as 'static'?
|
|
|
Post by jamesbowman on Mar 1, 2015 10:12:41 GMT -8
Well the FT800 is a GPU, so the general idea is that to change the display you need to send a complete new series of drawing:
GD.Clear(); ... GD.swap();
this might seem like a lot of work, but because the GPU does everything in hardware, and the CPU is only transmitting very high-level drawing commands, it can almost always happen in 1/60th of a second. Consider this demo:
it runs at 60 Hz on a standard Arduino, redrawing everything on the screen 60 times per second. So drawing a screen with widgets and text is a very small amount of work!
The "static" keyword means that the function is only locally visible. More importantly for the Arduino, it also means that its code will only be included in the final program if it is actually called. The compiler is smart enough to omit "static" functions and data from the final program if they are not mentioned.
|
|
jk
Junior Member
Posts: 10
|
Post by jk on Mar 2, 2015 10:55:06 GMT -8
Thank's for your explanations.
|
|