Pages: [1]   Go Down
Author Topic: Question about millis()  (Read 481 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i'm using a code for right to my led display using millis.
my question is what happen after approximately 50 days.

the code is :

/*
 
 */
#include <LedDisplay.h>

// Define pins for the LED display.
// You can change these, just re-wire your board:
#define dataPin 6              // connects to the display's data in
#define registerSelect 7       // the display's register select pin
#define clockPin 8             // the display's clock pin
#define enable 9               // the display's chip enable pin
#define reset 10               // the display's reset pin
#define displayLength 8        // number of bytes needed to pad the string
// create am instance of the LED display:
LedDisplay myDisplay = LedDisplay(dataPin, registerSelect, clockPin,
enable, reset, displayLength);

int lcdstate = 0; //estado do LCD
long previousMillis = 0;
long interval = 1000;
int brightness = 15;        // screen brightness
char open[] = {' ','O','p','e','n',' ',' ',' '};
char door[] = {' ','D','o','o','r',' ',' ',' ',};
//char del[]={' ',' ',' ',' ',' ',' ',' ',' ',};
void setup() {
  Serial.begin(9600);

  // initialize the display library:
  myDisplay.begin();
  myDisplay.setString("Open");
  myDisplay.home();
  myDisplay.setBrightness(brightness);
}

void loop() {
      if (millis()- previousMillis > interval) {
        previousMillis = millis();
        if (lcdstate == 0){
            myDisplay.home();
            for (int thisPosition = 0; thisPosition < 8; thisPosition++)
              {
               myDisplay.write(open[thisPosition]);
              }
            lcdstate = 1;
        }
        else {    
            myDisplay.home();
            for (int thisPosition = 0; thisPosition < 8; thisPosition++)
             {
              myDisplay.write(door[thisPosition]);
             }
            lcdstate = 0;
        }
        
}
}
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13085
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Change this...

Code:
long previousMillis = 0;
long interval = 1000;

...to this...

Code:
unsigned long previousMillis = 0;
unsigned long interval = 1000;

...and you should be good to go.  I believe you can test by using "unsigned short" instead of "unsigned long".  The roll-over should occur in just over one minute.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

tks for help
Logged

Pages: [1]   Go Up
Jump to: