array without delay

so Ive been through a couple of blink without delay tutorial and Im trying to adapt what Ive learnt from there to print an array of characters on an lcd screen every second

#include <LiquidCrystal.h>

int nextCount = 1000;
long int lcdCount;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

char* count[]={"1 second", "2 seconds", "3 seconds"};
int sec = 3;

void setup()
{
  lcdCount = millis();
  lcd.begin(16, 2);
  lcd.clear();
  Serial.begin(9600);
}

void loop()
{
  if(millis() >= lcdCount)
  {
  lcd.clear();
  for(int i = 0; i < sec; i++)
  {
    lcd.setCursor(3,0);
    lcd.print(count[i]);
    Serial.println(count[i]);
  }
  }
  lcdCount = millis() + nextCount;
 }

so what I was trying to attempt here is that it would count the seconds on the lcd, using the serial read it appears to print all 3 quotes together at the beginning of the sketch and then that's it

im kinda stumped

  1. make all time related variable type unsigned long

  2. You never change the values of count[0], count[1], count[2] that I can see,
    so the display will not change.

"nextCount" is a poor choice of name for a constant that is a time delay.
How about "display_delay"?

And "lcdCount" can be "lcd_time" much clearer...

You need to subtract before compare if comparing time values as
they wrap-around, whereas the difference cannot wrap if the delay
is reasonable.

void loop()
{
  if (millis() - lcd_time >= display_delay) // subtract before compare
  {
    lcd_time += display_delay ; // move target a fixed delay
    ... stuff ....
  }
 }

thanks mark, I get what your saying.
With it taking the lcd_time from the millis will show wether or not an interval of 1000 has passed
Ive implemented this and this is how it looks

#include <LiquidCrystal.h>

int display_delay = 1000;
unsigned long int lcd_time = 0;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

char* count[]={"1 second", "2 seconds", "3 seconds"};
const int sec = 3;

void setup()
{
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.clear();
}

void loop()
{
  if(millis() - lcd_time >= display_delay)
  {
  lcd_time += display_delay ;
  lcd.clear();
  for(int i = 0; i < sec; i++)
  {
    lcd.setCursor(3,0);
    lcd.print(count[i]);
    Serial.println(count[i]);
  }
  }
}

what happens now is every second it prints all three quotes rather than working its way through the array
this an be seen in the serial monitor
I was basing the original idea for this on a bit of code that I wrote with a delay

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char* count[]={"1 second", "2 seconds", "3 seconds"};
const int sec = 3;
const int time[sec] = {1, 1, 1};
const int sec_length = 1000;

void setup()
{
  lcd.begin(16, 2);
  lcd.clear();
  Serial.begin(9600);
}

void loop()
{
  lcd.clear();
  for (int i = 0; i < sec; i++)//array through the notes
      {

        lcd.setCursor(3,0);
        lcd.print(count[i]);
        delay(time[i] * sec_length);
      }
}

this work perfectly, working its way through the array in second intervals
you were saying crossroads that there was any value for count
is was thinking the value input is in the char* count[] array

evancleary:

Try:

int i=0;  //put this before setup()

void loop(){
    if(millis() - lcd_time >= display_delay) {
        lcd_time += display_delay ;
        lcd.clear();
        lcd.setCursor(3,0);
       lcd.print(count[i]);
       Serial.println(count[i]);
        i++;
        if(i>=3) i = 0;
     }
}

that works a treat!
Henry best your the best
thanks!

only thing is I would still like to put this into a for function so that I may add a break function
any ideas on why the for function wasn't working as intended?

any ideas on why the for function wasn't working as intended

Because "for" isn't a function?

not too sure on what your definition of function is I was under the impression that if, else, while, for and the likes were functions

for arrays I have used before using the for (whatever it is) as I have done in the original piece worked
as in the programme made its way through the array

any ideas on why the for function wasn't working as intended?

What was the intention?

if you take a look at the original code I posted up I want to be able to display an array of quotes "1 second" "2 seconds" "3 seconds" in second intervals using an array with for (int 1 = 0; i < sec; i++) but without using a delay instead using millis

I have already achieved this with a speaker playing at the same time
the idea is part of an overall larger project for a breathalyzer where readings from pressure sensor will taking in the mean time and if pressure drop or raises too high due to breath rate then the programme will break out of the array and ask for the test to be restarted

I have this done with the delay, only thing is once I add the actual sensor the reading start becoming "screwy" the reason Im suspecting for this is that the delays used are causing them to become scramble so im trying to set up the sketch without delays so that it might run smoother