Problem in defining a variable as multiplication 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; // &lt;---- 
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 &gt;= onPeriod ) {
    onState = !onState;
    startTime = millis();
    digitalWrite(enbPin, onState);
    Serial.println(onState);
  }
}
unsigned long onPeriod = 60ul * 1000; 

ul makes 60 to unsigned long and then the calculation has place for result.

without ul the constants and the result are int and it overflows