@Jack
I definitely want to keep it simple, so a memory card isn't the answer at this point. But as you say, it is a consideration for a future, more ambitious, revision. My favorite fortune was always "Turn over for fortune." of course, this was printed on both sides, lol.
@ JEDtoo
I must say, I wasn't expecting anyone to take the time to code a, full blown, working example. Thank you for that.
I am glad to see that I was on the right track with the use of PROGMEM and flash memory. I wasn't sure of the proper syntax and your example really helped me to see how it all works together.
I altered the code to output to LCD and eliminated the LED feedback, I'll revisit pin 13 later to control the LCD backlight. Now I just need to work on figuring out how to get the long text strings to properly wrap to the next line. The simple solution would be to scroll the text, but I like like the idea of wrapping it.
//Electronic "Fortune Cookie" 001
// Written by JEDtoo on the arduino.cc forum on 1 March 2012
// as a demo for program memory.
// Use at your own risk - no performance at any task is implied.
// If your girlfriend doesn't like her "fortune" that is your
// business, not mine.
//
// Modified by xJaymz to suit purposes on 6 March 2012
#include <LiquidCrystal.h>
#include <avr/pgmspace.h>
prog_char s1[] PROGMEM = "Test Fortune 1 Long String";
prog_char s2[] PROGMEM = "Test Fortune 2 Long String";
prog_char s3[] PROGMEM = "Test Fortune 3 Long String";
prog_char s4[] PROGMEM = "Test Fortune 4 Long String";
prog_char s5[] PROGMEM = "Test Fortune 5 Long String";
prog_char s6[] PROGMEM = "Test Fortune 6 Long String";
prog_char s7[] PROGMEM = "Test Fortune 7 Long String";
prog_char s8[] PROGMEM = "Test Fortune 8 Long String";
prog_char s9[] PROGMEM = "Test Fortune 9 Long String";
prog_char s10[] PROGMEM = "Test Fortune 10 Long String";
prog_char s11[] PROGMEM = "Test Fortune 11 Long String";
prog_char s12[] PROGMEM = "Test Fortune 12 Long String";
prog_char s13[] PROGMEM = "Test Fortune 13 Long String";
prog_char s14[] PROGMEM = "Test Fortune 14 Long String";
prog_char s15[] PROGMEM = "Test Fortune 15 Long String";
prog_char s16[] PROGMEM = "Test Fortune 16 Long String";
prog_char s17[] PROGMEM = "Test Fortune 17 Long String";
prog_char s18[] PROGMEM = "Test Fortune 18 Long String";
prog_char s19[] PROGMEM = "Test Fortune 19 Long String";
prog_char s20[] PROGMEM = "Test Fortune 20 Long String";
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// this table is in ordinary memory but has pointers
// that reference the flash PROGMEM
const char *str_tab[] = {
s1, s2, s3, s4, s5, s6, s7, s8, s9, s10,
s11,s12,s13,s14,s15,s16,s17,s18,s19,s20 };
const int Number_of_fortunes=20;
#define Longest_fort 100 // buffer size for messages
unsigned long count=0;
const int buttonPin = 6; // the number of the pushbutton pin
void setup() {
// set up the LCD's number of columns and rows
lcd.begin(16, 2);
// Print a message to the LCD
lcd.print("Welcome Message");
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH); // set pullup on
}
void loop() {
if (BUTTON_PUSHED()) {
lcd.clear();
say_it();
}
while (BUTTON_PUSHED()) continue; // wait for button up
delay(50); // delay to debounce
count++;
}
void say_it() {
int i;
char str[Longest_fort]; // temp storage for fortune
strcpy_P(str, str_tab[count % Number_of_fortunes]);
lcd.print(str); // print from temp storage
}
int BUTTON_PUSHED() {
if (digitalRead(buttonPin) == LOW) // is button pulling down?
return 1; // YES, it is pushed
return(0); // NOPE
}
Any advice?
Thanks
James