Hi, I am trying to help my daughter (4th grade) build a small display for her teacher as a end of the school year gift. Her teacher has several short quotes and favorite words she always uses. I have modified and experimented with a older code I found but I'm having some problems. I have spent several hours trying to get everything working, but I'm not getting anywhere. We're on the verge of giving up.
Problems:
- I would like the program to display the intro message, until a button is pressed. (This works)
- I would like each message to display for about 30 sec (and advance on its own).
- I would like both top and bottom display to be random (This works at the moment)
Right now I turn the Arduino on and the title message displays until the button is pressed, then a random message appears until I press the button again... The messages are random so all is good other than self advancing.
I believe once it advances on its own, all it should need is a delay between messages.
I have been able to get it to advance on its own, but then the messages are in order.
Can some please point me into the right direction?
Thanks
Bryan
#include <LiquidCrystal.h>
#include <pgmspace.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const char cs1[] PROGMEM = "Be Kind";
const char cs2[] PROGMEM = "Think of others";
const char cs3[] PROGMEM = "Smile";
const char cs4[] PROGMEM = "Laugh";
const char cs5[] PROGMEM = "Love";
const char cs6[] PROGMEM = "Go for it!";
const char cs7[] PROGMEM = "Be a leader";
const char cs8[] PROGMEM = "GREAT JOB";
const char cs9[] PROGMEM = "Stay Focused";
const char cs10[] PROGMEM = "Keep it up!!!";
const char bl11[] PROGMEM = "Lucky number 7";
const char bl12[] PROGMEM = "Day will be great";
const char bl13[] PROGMEM = "test";
const char bl14[] PROGMEM = "random";
const char bl15[] PROGMEM = "";
const char bl16[] PROGMEM = "";
const char *str_tab[] = {
cs1, cs2, cs3, cs4, cs5, cs6, cs7, cs8, cs9, cs10};
const int Number_of_Checksteps=10;
const char *bl_tab[] = {
bl11, bl12, bl13, bl14, bl15, bl16};
const int Number_of_Kicks=6;
#define Longest_fort 100
unsigned long count=0;
int run;
int buttonPin;
void setup() {
buttonPin = 6;
pinMode(buttonPin, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.print("Mrs Bardonners");
lcd.setCursor(0,1);
lcd.print("4th grade class");
delay (1000);
}
void loop() {
if (BUTTON_PUSHED()) {
lcd.clear();
say_it();
}
while (BUTTON_PUSHED()) continue;
delay(50);
count++;
}
void say_it() {
int i;
char str[Longest_fort];
strcpy_P(str, str_tab[count % Number_of_Checksteps]);
lcd.print(str);
lcd.setCursor(0,1);
char bl[Longest_fort];
strcpy_P(bl, bl_tab[count % Number_of_Kicks]);
lcd.print(bl);
}
int BUTTON_PUSHED() {
if (digitalRead(buttonPin) == LOW)
return 1;
return(0);
}