Please forgive my novice coding skills here. I'm trying to create a servo control that takes in angles input from the Serial Monitor, and turns the servo to that given position. For some reason, whenever I try to type in a number with two digits, the code reads that as two separate numbers and turns the servo to each digit as an angle (from 0 to 9 degrees). I suspect this is a simple coding issue, but any help or advice would be appreciated. Code is appended below.
GEP
Code:
#include <Servo.h>
Servo ServoA;
void setup()
{
Serial.begin(9600);
ServoA.attach(9);
Serial.print('Ready for angle prompt!');
Serial.println();
Serial.print("Please assign an angle for Servo A [0 to 180 degrees]");
Serial.println();
}
void loop()
{
if (Serial.available() > 00)
{
int AngValA = Serial.read();
if (AngValA >= '0' && AngValA <= '180' )
{
AngValA = AngValA - '0';
AngValA = map(AngValA, 0, 180, 0, 180);
ServoA.write(AngValA);
Serial.print("Servo A set to: ");
Serial.print(AngValA, DEC);
Serial.println();
}
}
}