int InputTXT_Int() {
int val;
while (Serial.available() == 0) ; // Wait here until input buffer has a character
{
val = Serial.parseInt(); // returns the first valid integer point number from the Serial buffer
while (Serial.available() > 0)
{ Serial.read() ; } // clear the keyboard buffer
}
return val;
}
float InputTXT_Float() {
float val;
while (Serial.available() == 0) ; // Wait here until input buffer has a character
{
val = Serial.parseFloat(); // returns the first valid floating point number from the Serial buffer
while (Serial.available() > 0) // .parseFloat() can leave non-numeric characters
{ Serial.read() ; } // clear the keyboard buffer
}
return val;
}
int Motor = 9 ;
void setup() {
Serial.begin(9600);
pinMode(Motor, OUTPUT);
}
void loop() {
int speed , time ;
Serial.println("-----Key Speed and Time to Motor Work-----");
Serial.print("Speed Motor (1-255) = ");
speed = InputTXT_Int();
Serial.println(speed);
Serial.print("Time Motor On (Sec) = ");
time = InputTXT_Int();
Serial.println(time);
digitalWrite(Motor, speed);
delay(time*1000);
digitalWrite(Motor, LOW);
Serial.println();
}