My delays, won't!

I wrote a program that needs a little bit of timing. The LCD gets garbled if it is updated too quickly and things like that.

Trouble is, nothing I do to the timing seems to work! I have a couple of delay()s at the outset that don’t last as long as I would expect, so I made a little timekeeping class called Next like this:

class classNext { 
  public:
    unsigned long int observe, button, lcd,atArrow,stArrow;
}; 

// Initially everything needs to be updated
classNext Next = {0,0,0,0,0};

This way I can set up blocks like this that are triggered regularly and not too quickly:

  // Update visuals every <lcdUpdateMs>.
  if (Next.lcd < millis() ) {
    // update LCD
    updateLCD();
    Next.lcd = millis() + lcdUpdateMs;
  }

But this doesn’t work either! My lcd is still changing like crazy at intervals that are much faster than I would like, despite the fact that lcdUpdateMs is equal to 1000!

Anyone have any idea what is going on here?

I’m using a Sainsmart Arduino Uno, arduino 1.0.5 and an AVRISP Mkii with the following libraries:

#include <Wire.h>
#include <i2cmaster.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
classNext Next = {0,0,0,0,0};

What is this supposed to be doing? You look like you are assigning an array to a class instance. That doesn't work.

It's very easy to write a short sketch to demonstrate that delay() is working properly, and it would be strange if it wasn't.

Have you studied the blink-without-delay example for a better way to manage timing?

Don't introduce unnecessarily complex stuff into code.

...R

This is the same as blink without delay but with a single class to keep track of all the timing variables. I'll try it without the class and see if that helps I guess.

Edit: No change

I'll try it without the class and see if that helps I guess.

There's nothing wrong with using a class. If you want help with it, snippets are not the way to go.

I added an LED blink into the LCD if statement and it blinked so fast I couldn't even see it. When I added a delay(1000) it slowed down enough to see, but it is still blinking about twice as fast (20 toggles in 9.66 seconds)

// Update visuals every <lcdUpdateMs>.
  if (Next.lcd < millis() ) {
    // update LCD
    updateLCD();
    Next.lcd = millis() + lcdUpdateMs;
  }

I see a failure if the program ever runs for more than 49 days.

Use subtraction for time or the roll-over will get ya.

PaulS:
snippets are not the way to go.

I agree with this. I can usually figure out this kind of thing, but I don’t have enough code in this case. It sounds like you’re not using a good design pattern overall, and that can lead to errors, but it’s impossible to say without all the code. It is highly likely your code is broken because of some tiny error like a < when you meant > or something like that. Impossible for us to help find that kind of thing if we can’t see it.

Hi, I agree with the last two posts, a full copy of your sketch would help.

Tom....... :)