My example sketch uses strings which can hog lots of memory. I'm looking for ways to reduce that memory demand. In the sketch below, memory isn't a problem, but with other sketches, it is.
I tried char with multiple characters, but that didn't work.
Any ideas? My example sketch appears below.
//Add, subtract and multiply calcutator for two input numbers. Input and output via the Serial Monitor. See note after the sketch.
//Multiply doesn't work with large input numbers. DE 1/29/20
//When using Quit, the IDE will ask for save or not.
int numberA;
int numberB;
int sum;
int diff;
int product;
int both;
String msgA="Enter 1st number, then hit Enter.";
String msgB="Enter 2nd number, then hit Enter.";
String msgA1="Your 1st number is: ";
String msgB1="Your 2nd number is: ";
void setup() {
Serial.begin(9600);
Serial.println("A simple add/multiply/total calcutator. No large numbers please.");
Serial.println();
} //end setup
void loop() {
//get 1st number
Serial.println(msgA);
while (Serial.available()==0){//waiting for 1st number
}
numberA=Serial.parseInt();//get 1st number
Serial.print(msgA1);
Serial.println(numberA);
Serial.println();
//get 2nd number
Serial.print(msgB);
while (Serial.available()==0){//waiting for 2nd number
}
numberB=Serial.parseInt();//get 2nd numbe
Serial.println();
Serial.print(msgB1);
Serial.println(numberB);
Serial.println();
//calculate answers
sum = numberA+numberB;
delay(100);
diff = numberA-numberB;
delay(100);
product = numberA*numberB;
delay(100);
both = sum+product;
//print answers
Serial.print("The SUM is ");
Serial.println(sum);
Serial.print("The DIFFERENCE is ");
Serial.println(diff);
Serial.print("The PRODUCT is ");
Serial.println(product);
Serial.print("Added TOGETHER (sum + product) they are ");
Serial.println(both);
}
//NOTE !! Serial-monitor must be set to NO LINE ENDING to avoid extra zeros in the println(number) display. Also use auto scroll.