I have a simplest code to turn on and off a led. The variable holding time definition is onTime, using Arduino Nano.
When it is written as: onTime=1000*30, all is good.
When onTime is greater than this, if loop does not return true value when needed ( see code below ).
BUT when writing it implicit as onTime=60000, and not onTime=1000*60 code run OK.
I'm guessing that value of 30*1000 - has to be something with int value.
CODE:
int enbPin = 10;
bool onState = true;
unsigned long onPeriod = 60*1000; // <----
unsigned long startTime = millis();
void setup() {
// put your setup code hee, to run once:
Serial.begin(9600);
pinMode(enbPin, OUTPUT);
digitalWrite(enbPin, onState);
Serial.println("START");
}
void loop() {
// put your main code here, to run repeatedly:
if (millis() - startTime >= onPeriod ) {
onState = !onState;
startTime = millis();
digitalWrite(enbPin, onState);
Serial.println(onState);
}
}
onTime