Millis() misunderstanding
i've been trying wrap head around how millis() works..
scenario:
output , gate going input 3 on arduino board
after arduino senses high value 60+ seconds
print (blah)
i don't understand how express millis()
unsigned long time;
time = millis();
if(digitalread(andin) == high >= 60 seconds) {
serial.println("blah");
}
it keeps incrementing since code executed? need compare time since andin goes high against millis()?

scenario:
output , gate going input 3 on arduino board
after arduino senses high value 60+ seconds
print (blah)
i don't understand how express millis()
unsigned long time;
time = millis();
if(digitalread(andin) == high >= 60 seconds) {
serial.println("blah");
}
it keeps incrementing since code executed? need compare time since andin goes high against millis()?

you need capture time pin when high , check if 60 seconds has elapses since then. don't want happen after lets assume want print statement appear once until pin goes low again.
to can store millis value if pin high - if pin not high.
the code isn't tested hope give ideas on how proceed
to can store millis value if pin high - if pin not high.
code: [select]
unsigned long starttime;
boolean hasprinted;
if(digitalread(andin) == high){
if(starttime == 0)
starttime = millis();
else if (millis() >= starttime + 60000 && hasprinted == false){
serial.println("blah");
hasprinted = true;
}
}
else{
// pin has gone low
starttime = 0;
hasprinted = false;
} the code isn't tested hope give ideas on how proceed
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Millis() misunderstanding
arduino
Comments
Post a Comment