Pages: 1 [2]   Go Down
Author Topic: help using the flash.h library and functions  (Read 2346 times)
0 Members and 1 Guest are viewing this topic.
South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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/

Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Seems to be pretty simple, according to the documentation:

Code:
LiquidCrystal lcd();
// ...

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

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Seems to be pretty simple, according to the documentation:

Code:
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,
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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");
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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...
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just tested this, and it does work:

Code:
#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.
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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! smiley-sad
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
void sendMsg(_FLASH_STRING str) {
  int i = 0;
  while (1) {
    Serial.print(str[i]);
    i++;
    if (i == str.length()) break;
  }
}
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

Pages: 1 [2]   Go Up
Jump to: