Digital Hourglass will not execute at 600 000 ms (10mins)

The Subject line describes my problem. The project runs perfectly at Intervals of 600, 1000 and 2000 but any longer than that results in no execution. I van copied the code as per the manual and have verified same, line for line. My knowlegde is very basic and I would like to know where to start troubleshooting. Hope someone can help?

Start by telling people what a "Digital Hourglass" is....

Start by telling people what a "Digital Hourglass" is....

eso . . .

Make sure the varibales are of a typ that can contain lare numbers, such as "unsigned long".

Variables and constants, for instance 600000ul for 600,000 as unsigned long.

const int switchPin = 8;
unsigned long previousTime = 0;
int switchState = 0;
int prevSwitchState = 0;

int led = 2;
long interval = 600000;

Part of the code - Note that the 600 0000 was captured a a long integer with no thousand separator (Commas or spaces) so I do not know if this is what you may think the problem is. As you can see - I have entered this code correctly.

long interval = 600000L ;

Constants without the L or UL are of type int (which is 16 bit) and will not
always do what you think. Long constants need an L, unsigned constants may need a
U if the value is outside the range of the signed integer type.

On Arduinos (other than Due)

byte: 0 … 255
char: -128…127
unsigned int: 0 … 65535
int: -32768 … 32767 — this is the default for all unqualified integer constants.
unsigned long 0 … 4294967295
long: -2147483648 … 2147483647

The Due has 32 bit ints and unsigned ints, longs are 64 bit IIRC

I am running win 7 64bit and I have now tried with 600000L - no execution and then I tried with 600000UL - still no execution. I stepped down the time to 600ms and gradually increased it, at 4000ms - all 6 LED light up at 4 second intervals. At 6000ms - only 1 to 5 lights up before the loop starts again. So the highest reliable speed is 4000Ms - using as is - or with the L or with the UL.. What I am trying to ascertain is the reliability on this device - which, reading your comment, seems to be erratic. I do tertiary training and would like to offer a more factual answer. Is this possible? I appreciate your help so far.

Digital hourglass is Project 8 of the Arduino Beginner level. In short, you connect 6 LED's and a tilt switch and then you program the hardware so that no1 LED lights up after 10 minutes, no 2 and then 3 and so forth until all six are alight. If you then tilt the board, the circuit is broken and the process starts again. Sorry for not mentioning this upfront.

MarkT:

long interval = 600000L ;

Constants without the L or UL are of type int (which is 16 bit) and will not
always do what you think. Long constants need an L, unsigned constants may need a
U if the value is outside the range of the signed integer type.

Really? I just ran this code on an Arduino Uno and it printed "600000"

void setup()
{
  long interval=600000;
  Serial.begin(9600);
  Serial.println(interval);
}

void loop()
{
}

ashbren:
I am running win 7 64bit and I have now tried with 600000L - no execution and then I tried with 600000UL - still no execution. I stepped down the time to 600ms and gradually increased it, at 4000ms - all 6 LED light up at 4 second intervals. At 6000ms - only 1 to 5 lights up before the loop starts again. So the highest reliable speed is 4000Ms - using as is - or with the L or with the UL..

Nobody can help without seeing the exact code you're trying to use. In its entirety.

ashbren:
What I am trying to ascertain is the reliability on this device - which, reading your comment, seems to be erratic.

The "devices" are totally reliable. What may be erratic is the code people try to run on them.

Thanks for your assistance so far: here is the entire code:

const int switchPin = 8;
unsigned long previousTime = 0;
int switchState = 0;
int prevSwitchState = 0;

int led = 2;
long interval = 60000UL;

void setup () {
for (int x = 2; x <8;x++){
pinMode (x,OUTPUT);
}
pinMode (switchPin, INPUT);
}
void loop() {
unsigned long currentTime = millis();
if (currentTime - previousTime > interval) {
previousTime = currentTime;
digitalWrite (led,HIGH);
led++;
if (led == 7) {
}
}
switchState = digitalRead (switchPin);
if (switchState != prevSwitchState){
for (int x = 2; x < 8; x++) {
digitalWrite(x,LOW);
}
led = 2;
previousTime = currentTime;
}
prevSwitchState = switchState;
}

Suspect that the problem is declaring 'interval' as long and not unsigned long. All variables an constants used to hold time values in milliseconds should be unsigned long.

The following program, with "interval" declared as long, blinks the LED about every 60 seconds. I did not test 600 seconds, but I strongly suspect that will work too.

unsigned long previousTime = 0;
int led = 13;
long interval = 60000UL;

void setup () {
    pinMode (led,OUTPUT);
}
void loop() {
  unsigned long currentTime = millis();
  if (currentTime - previousTime > interval) {
    previousTime = currentTime;
  digitalWrite (led,HIGH);
  delay(100);
   }
  digitalWrite(led,LOW);
}

johnwasser:
Suspect that the problem is declaring 'interval' as long and not unsigned long. All variables an constants used to hold time values in milliseconds should be unsigned long.

Nope. That will make no difference.

I just ran this code and it works perfectly:

int led = 2;
long interval = 600000;
unsigned long previousTime = 0;

void setup ()
{
  Serial.begin(9600);
  for (int x = 2; x <8;x++){
    pinMode (x,OUTPUT);
  }
}

void loop()
{
  unsigned long currentTime = millis()*500;
  if (currentTime - previousTime > interval) {
    previousTime = currentTime;
    Serial.print("Led: ");
    Serial.println(led);
    digitalWrite (led,HIGH);
    led++;
    if (led == 7) {
    }
  }
}

(Apart from the obvious bug of incrementing “led” forever).

Maybe the problem is your switch.

Not the same code as in the manual - You are running the serial monitor - which is cool - but the one line is different - copied below:

unsigned long currentTime = millis()*500;

void loop() {
unsigned long currentTime = millis();

You are doing calculations with the variable - which brings it withing the ranges that I have mentioned. The execution takes place - but at one second intervals. (Practically tested this now)

Is the manual perhaps incorrect?

(If you have received this already - sorry - but IE is screwing up again

ashbren:
Not the same code as in the manual - You are running the serial monitor - which is cool - but the one line is different - copied below:

unsigned long currentTime = millis()*500;

Yep. The point is to prove that "600000" works, not that I'm prepared to sit there for an hour waiting for it to reach 7.

You can remove the "*500" if you're not convinced.

Thank you for your response. I do not know if you are just volunteering information or if you are actually working for Ardunio. If you are volunteering the information, I can understand your irritation. If you are working for Arduino: - I have purchased your product to support you and in this process, to bring a number of new customers to support you. I will become an facilitator - so I'll be working for Arduino - but not for a salary.

The very first interface with the product is your manual. Once the user becomes more adroit - he will experiment with code - but should have confidence that the basic code in the manual is correct. So all I really want to know from you is if the code in the manual is incorrect.

I have posted you the code exactly as I have captured it so that you could run it on your side - and if this exact code works on your side - then it may be that I have faulty components - because the hardware is functional but at much lower time spans.

I do not expect you to wait an hour. The project will not execute the first step which is to take place in 10 minutes. Can you please do this for me?

ashbren:
Thank you for your response. I do not know if you are just volunteering information or if you are actually working for Ardunio. ...

FYI,
99.99% of the people answering on the forum are volunteers, including the moderators. The owners are seldom seen here although they do finance the forum to keep it on line. So it is a user2user forum, and not a help desk with a 1 hr SLA or so..