Go Down

Topic: help using the flash.h library and functions (Read 2 times) previous topic - next topic

Aeturnalus

I just tested this, and it does work:

Code: [Select]

#include <Flash.h>

FLASH_STRING(foo, "foobar123456");

void setup() {
  Serial.begin(115200);
}

void loop() {
  for (uint8_t i = 0; i < foo.length(); i++) {
    Serial.print(foo[i]);
    delay(100);
  }
  Serial.print("\r\n");
}


If there's an issue with the code, it's on your LCD's side.

SouthernAtHeart

Yes, but I have no idea how to make it work for myself.
I guess I'm stumped on this one.
Worse yet, I feel like I never really explained my problem in such a way that someone understands it, I think that's worse than being stumped! :(

Aeturnalus

Providing some LCD documentation would really help - we've been approaching this problem as if you just have a Serial output, so if your LCD needs something different, do tell.

Your sendMsg() function can be rewritten to be equivalent to this:
Code: [Select]

void sendMsg(_FLASH_STRING str) {
  for (int i = 0; i < str.length(); i++) {
    Serial.print(str[i]);
  }
}

or, more like your original, like this:
Code: [Select]

void sendMsg(_FLASH_STRING str) {
  int i = 0;
  while (1) {
    Serial.print(str[i]);
    i++;
    if (i == str.length()) break;
  }
}

SouthernAtHeart

IT WORKS!  IT REALLY WORKS!! 
I don't know what those underscores mean, but this sure is simple.  I looked at the http://arduiniana.org/libraries/flash/ page again, but don't really see anything pointing me to this answer.  I wish I understood why it works, but there are some thing about this I know I'll never understand. 
Thanks again!

Aeturnalus

FLASH_STRING(foo, "bar") creates an object of type _FLASH_STRING with a value "bar".  This is explained in the comments section at the bottom of the page, and can be easily figured out if you look at the source code of the header file (Flash.h).

Go Up