Simple code....receives a single number from the serial console and multiplies it by 10,000.
receivedChar=Serial.read(); //The character is read. It's 0-9 Serial.println(receivedChar); // Check it's been received OK long asInteger=receivedChar -'0'; // Convert it to a number Serial.println(asInteger); //print the number out to check it's not changed long newInteger=10000*asInteger; //Multiply it by 10000 so it;s in the range 10000 to 90000 Serial.println(newInteger); //print it out to check Arduino can do hard sums.
When character input is 1, this outputs 1 as the character, 1 as the 'asInteger' and 10,000 as the newInteger - perfect!
2 produces 20,000, and 3 as 30,000 as expected.
But 4 produces -25536.
long is supposed to be +/- 2 billion plus loose change?
If I replace ' long' with 'unsigned long' then it works.....all the way up to 90,000
What obvious thing am I completely missing here?
It's running on a nano (not that I can see why that would make a difference)