I have discovered a strange error in my Arduino. It's not in the code. I think it's a hardware bug in the ALU of the microcontroller, maybe in clone only.
So there is a variable called feedLimit
and its value is 30, which doesn't really matter.
When I print the answer of feedLimit301000 using this command Serial.println(feedLimit*30*1000)
The answer printed on the serial monitor is 30528, which is obviously incorrect. But when I print feedLimit*30000, the answer is correct (300000). The answer should be the same in both cases but it's not. I have attached the code as well as a screenshot of the output.
Can somebody please let me know if this is a bug in Arduino or something else? I have never experienced this kind of bug at the hardware level.
Thanks.
int interval, interval2;
int feedingTime = 3; //Must feed once every 3 minutes
int feedLimit = 30; //If fed 10 times or more within feedingTime span, the fiesh dies
int dieAfter = 30; //Will die if its not fed in 10 minutes
int feedCounter = 0; //Counts how many time fed in feedingTime span
void setup() {
Serial.begin(9600);
pinMode(btnPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
Serial.println(feedLimit);
Serial.println(feedLimit*60*1000);
Serial.println(feedLimit*60000);
}