Go Down

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

SouthernAtHeart

I'm a self taught programmer, and I had a poor teacher!  :)

I've look at all three examples in the flash example liberary, twice.  I've read the http://arduiniana.org/libraries/flash/ probably 3 times.  my Arduino programming probably looks pathethic, but I manage, and I really enjoy Arduino a lot.  I just can't figure out how to move my messages that I send to an LCD over into flash, so I have room to add a few more features. 
Is there anyone else who understands how the flash.h library works who could read post 13 of this thread, which pretty well in a nutshell explains my problem.
I can't get the syntax down for how to print out, letter by letter, a string from flash.  I'm not even sure which flash type I need to save my strings as.  All I'm sure about is, is that it's not nearly as easy as it sounded the first time I read arduiniana.org/libraries/flash/


Aeturnalus

Seems to be pretty simple, according to the documentation:

Code: [Select]

LiquidCrystal lcd();
// ...

// in some method or another
  lcd << F("foo, bar, this is a flash string");

SouthernAtHeart


Seems to be pretty simple, according to the documentation:

Code: [Select]

LiquidCrystal lcd();
// ...

// in some method or another
  lcd << F("foo, bar, this is a flash string");


yes, I've notice how very simple it is, that way, but it doesn't work for me.  I guess post 13 didn't tell everything.  My very first post tellss why this doesn't work for me.  I need to send the string, one character at a time, to the lcd, which makes it nicely show up in a ver readable fashion, as the LCD I have has built in functionality for automatically moving the lines up.
See post 1

thanks,

Aeturnalus

Code: [Select]

FLASH_STRING(foo, "bar");

// somewhere in a method
for (uint8_t i = 0; i < foo.length(); i++) {
  char c = foo[i];
  Serial.print(c);
}
Serial.print("\r\n");

SouthernAtHeart


Code: [Select]

FLASH_STRING(foo, "bar");

// somewhere in a method
for (uint8_t i = 0; i < foo.length(); i++) {
  char c = foo[i];
  Serial.print(c);
}
Serial.print("\r\n");


I worked with this awhile, with no luck...

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