Go Down

Topic: Millis() Timing goes way off over time. (Read 1 time) previous topic - next topic

PaulS

#20
Mar 03, 2012, 02:26 am Last Edit: Mar 03, 2012, 02:28 am by PaulS Reason: 1
Quote
Still nowhere in the function is previousMilis[] used.

void Zone(unsigned long on, unsigned long off, int i, unsigned long previousMilis[]){
 currentMillis[ i ] = millis();
 if (currentMillis[ i ] - previousMillis[ i ]> off){
   previousMillis[ i ]=currentMillis[ i ];
   while(millis()-previousMillis[ i ]<=on){
     digitalWrite(relayPin[ i ],HIGH);
   }
   digitalWrite(relayPin[ i ],LOW);
 }
}
Looks like it's used to me...

No code box because you can't highlight in a code box, like you used to be able to do.

Nick Gammon

Interesting though all this is ...

If I may suggest to the OP:

http://gammon.com.au/blink

I don't think turning on timers to water plants is rocket science. You should be able to make it work quite easily.

Looking at the code above:

Quote
Code: [Select]
while(millis()-previousMillis[ i ]<=on){
      digitalWrite(relayPin[ i ],HIGH);
    }


You don't need to keep turning the pin on. Once it's on, it's on. You could make it:

Code: [Select]

digitalWrite(relayPin[ i ],HIGH);  // turn on pin
while(millis()-previousMillis[ i ]<=on)  // my delay technique
{   }


or just:

Code: [Select]

digitalWrite(relayPin[ i ],HIGH);  // turn on pin
delay (on);


However this, fairly obviously, only lets you water one lot of plants at once. Does it matter? I doubt the plants will care.

dxw00d

Might also be worth looking at the recent blink series of threads by Morris Dovey.

GoForSmoke

#23
Mar 03, 2012, 11:50 am Last Edit: Mar 03, 2012, 11:53 am by GoForSmoke Reason: 1
Paul;

previousMilis

is not

previousMillis

How many times have you seen just 1 character make all the difference? If I had a dollar for every time.....
I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

PaulS

Quote
previousMilis

is not

previousMillis

Until you mentioned that, I was reading this thread with the font size at a reasonable level. With old(er) eyes, the two l's looked just like 1. I had to increase the font size significantly to see that there were indeed two l's in the name used, versus one in the argument.

Sorry about that...

Go Up