Simulated Boards led not turning off

Trying to code a calculator that takes the answer of the sum and inputs the answer as the time for the LED to be On. Program seems to be in working order until i get above 42 seconds. Any ideas?

// a very simple addition calculator
int a;
int b;
int c;
int led=13; 



void setup() {
Serial.begin(9600); 
pinMode(led, OUTPUT);
}  
void loop() {
 Serial.println("Enter a number"); // the println adds a new line to he output window
 while(!Serial.available()); // wait till a number has been entered
 a = Serial.parseInt(); // treat as an Integer and read the whole number
 Serial.println("Enter another number");
 while(!Serial.available());
 b = Serial.parseInt();
 Serial.println("Enter another number");
while(!Serial.available());
 c = Serial.parseInt();
 Serial.println((a+b*c)); // Print the sum of a and b and c
 Serial.print("You typed in "); // Echo what the user has typed in
 Serial.print("The LED should stay on for "); 
 Serial.println(a+b*c);
 Serial.println("seconds");
 digitalWrite(led, HIGH);
 delay((a+b*c)*1000);
 digitalWrite(led, LOW);
 delay(1000);

}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use [color = red]code tags[/color] (the </> icon above the compose window) to make it easier to read and copy for examination

You are likely over the max value an int can represent

Try changing a,b and c to long instead of int

Are you sure it is 42 and not 32? 2 byte int max value is 32767

Thank you for the replies, changing int to long has solved the issue

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.