Hello, I'm using the newest GLCD beta library, and I'm trying to get text to scroll across the screen when the string is longer than 128 bytes. Here is my code:
#include <glcd.h>
#include <glcd_Config.h>
#include "fonts/SystemFont5x7.h"
using namespace std;
class Message
{
public:
int x;
int y;
String words;
Message(String string, int x, int y) : words(string), x(x), y(y) {};
};
void setup()
{
GLCD.Init(); //initialize the library to draw dark pixels on a light
GLCD.SelectFont(System5x7);
};
void loop()
{
GLCD.FillRect(0, 52, 128, 12);
Message inst("This is only a test", 0, 54);
String coppy = inst.words;
if ((GLCD.StringWidth(inst.words&)) > 128);
{
while((GLCD.StringWidth(inst.words&) > 128)
{
inst.words.erase(1);
};
inst.words = coppy;
};
GLCD.CursorToXY(inst.x,inst.y);
GLCD.SetFontColor(WHITE);
GLCD.print(inst.words);
GLCD.ClearScreen();
};
I'm getting these errors:
Poject.cpp: In function 'void loop()':
Poject:25: error: expected primary-expression before ')' token
Poject:27: error: expected primary-expression before ')' token
Poject:28: error: expected `)' before '{' token
Poject:29: error: 'class String' has no member named 'erase'
How can I fix this, or if you have a better way to scroll text let me know. Thanks
You messed up with your closing braces in line 27 and the semicolon in line 25 is probably not what you want. After those two I stopped looking for more. Just read the messages and check the lines or the line before the error message.
In general, semi-colons are not required after closing braces. The only cases where they are required is following a struct or class definition statement.
The String class that you are using is NOT the one in the std namespace.
ok well how can i erase a single piece of the string then?
Start by defining what a piece of a string is? I know what a piece of pie is, although my definition of a piece of pie and my wife's definition are not the same.
How much of the string do you want to erase? One character? One word?
Start by defining what a piece of a string is? I know what a piece of pie is, although my definition of a piece of pie and my wife's definition are not the same.
How much of the string do you want to erase? One character? One word?
lol, well if the message is longer then the width of the screen (128) then i need it to erase the left or right most Char
Sketches go in pde files. Libraries go in cpp files.
Even if you are including a class definition in the sketch, it's still a pde file. The IDE creates a cpp file for you, from the pde file, adding function declarations and a main() function.