void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Enter a number greater than 0");
Serial.setTimeout(10); //this is the time bit takes for the serial communicator to
// time out. reducing this time means some things can be recieved quicker, but if it takes longer
// to run the code that the time out time is, then nothing will be printed.
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0){
int var = Serial.parseInt(); //this passes the value as an integer. Using parseFloat will pass a decimal number
if (var > 0){
Serial.println(var);
}
else{
Serial.println("Enter a valid number");
}
} // to send a string, you have to use readString. The variable var must be changed to a String variable.
}
// the reason why you get a zero after every number is becasue new line ending is enabled
// this is \n. - on IDE you can change the communication to have no ending