LCD random message

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:

  1. I would like the program to display the intro message, until a button is pressed. (This works)
  2. I would like each message to display for about 30 sec (and advance on its own).
  3. 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);                         
}

With your description in mind, I was surprised not to find the random() function used in the program.

I think using random() would make the code easier for a 4th grader to understand, though the randomSeed() call does add some complexity.

random() will also be necessary if you want the messages to show in random order while auto advancing because your current system will increment count a consistent number of times in 30 seconds.

Ulcerdonor:

  lcd.print("Mrs Bardonners");

Don't forget punctuation. Wouldn't want to teach any bad habits!

I also recommend using more descriptive variable names, always using curly brackets, and doing a Tools > Auto Format on your code to make it easier to understand.

Thanks Delta G for the idea. I did everything you suggested and it fixed the issue of continuing once the button is pressed. Now, it does not randomly display each message. They are all displayed in the same order I put them in at the beginning. I have a little experience using random seed, but I think that's the wrong path. Do you have a suggestion?

Thanks Bryan