// Adding two numbers together
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
// Read the first number
Serial.println("Enter the first number:");
while (Serial.available() == 0) {} // checks if any data has been sent to the Arduino from the Serial Monitor. If data is available, the code inside the if statement will execute.
int num1 = Serial.parseInt(); // reads the next available integer number from the Serial Monitor, which the user types in.
// Read the second number
(Serial.available() > 0);
Serial.println("Enter the second number:");
while (Serial.available() == 0) {} // enter data
int num2 = Serial.parseInt(); // second number
// Add the two numbers
int sum = num1 + num2;
// Print the result - processing outputs
Serial.print("The sum of ");
Serial.print(num1);
Serial.print(" and ");
Serial.print(num2);
Serial.print(" is ");
Serial.println(sum);
// delay for output
delay(8000);
}
}