When a const int variable is multiplied by an unsigned long variable what is the resultant data type?
i.e. the following is the last function in a sketch (attached) that flashes a 10 segment LED bar graph like a binary counter display. LEDs 1-7 worked fine. LEDs 8-10 only worked if the flash interval was reduced ultimately down to 50ms to get LED10 to work, until I changed the variable type for the flash interval to unsigned long also. It looked like the result of the "(currentMillis%(512*I)) was overflowing when millis() went above 64000 so LED 8, 9 and 10 never went high. Once I change the flash interval type it worked fine with flash interval set to 500.
I did not see anywhere I looked where the data type of two dissimilar variables multiplied together was defined. Can anyone help me to understand?
const int I=500; // flash interval
unsigned long LED10Interval = 512*I; //interval to blink LED10 LED (milliseconds)
void manageLED10() { //LED10 function
currentMillis = millis(); //capture the current time
if(currentMillis - previousMillisLED10 >= LED10Interval) { //check if time to change LED10 LED yet
LED10State = (LED10State == HIGH) ? LOW : HIGH; //if state is high change to low
digitalWrite(LED10Pin, LED10State); //change output of pin to match state
previousMillisLED10 = (currentMillis-(currentMillis%(512*I))); //store the time of this change
}
}
Binary_Counter.ino (11.4 KB)