Well I realized that to execute a code in IDE arduino by pressing enter in the keyboard is not automatic, but must be programmed, could you please explain to me how I can set this function?
Here is a code that shows the sum of evens and odd of products just when you write a negative number, I'd like to change it; I mean I'd like to run the program by typing the enter key of mi computer keyboard please.
long SumOfEvens = 0;
long ProductOfOdds = 1;
void setup()
{
Serial.begin(115200);
delay(200);
Serial.println("Enter numbers, separated by spaces or commas.");
Serial.println("Enter a negative number to indicate the end of input.");
}
void loop()
{
if (Serial.available() == 0)
return; // Nothing to do
int number = Serial.parseInt();
// Throw away any line ending characters
while (Serial.peek() == '\n' || Serial.peek() == '\r')
Serial.read();
if (number < 0)
{
// Negative number: End of input
Serial.print("Sum of even numbers: ");
Serial.println(SumOfEvens);
Serial.print("Product of odd numbers: ");
Serial.println(ProductOfOdds);
// Reset
SumOfEvens = 0;
ProductOfOdds = 1;
}
else if ((number % 2) == 0)
{
// Even
SumOfEvens += number;
}
else
{
// Odd
ProductOfOdds *= number;
}
}