I'm trying to create a function that will take a String as an input, and at every 20 characters, it will instert "\n" so that the string doesn't go off the side of my screen (I'm using an oled with the SSD1306Ascii library).
This is my code so far, but when I run it nothing appears on the screen (I have another part of the code which passes the string to the funtion):
String message = "";
String newMessage = "";
void printMessage(String message) {
oled.clear();
if(message.length() > 20) {
current = 20;
while(current < message.length()) {
newMessage = message.substring(current-20, current) + "\n";
newMessage = newMessage + message.substring(current+1);
current+20;
}
oled.println(newMessage);
}
else {
oled.println(message);
}
}
newMessage
will remain empty.