I am trying to modify downloaded Arduino program. Right now it seems to read ASCII code corresponding to a keyboard key pressed. It has three options as shown. If I want the servo to turn its shaft say by 6 steps then I need to press appropriate keyboard key six times (in Serial Monitor window). What I want to do is to input an integer (in Serial Monitor window), say 57 and have the server move by corresponding numbers of steps (say each step = 1 degree, thus turning servo by 57 degrees). Right now if I wanted to rotate the shaft by one degree I would have to press the key 57 times. How do I change the read statement (or the program) to get needed result? I have limited programming skills.
Code
snip
25. int centerServo; // center servo position
26. int pulseWidth; // servo pulse width
27. int moveServo; // raw user input
28. long lastPulse = 0; // recorded time (ms) of the last pulse
29.
30.
31. void setup() {
32. pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
33. centerServo = maxPulse - ((maxPulse - minPulse)/2);
34. pulseWidth = centerServo; // Give the servo a starting point (or it floats)
35. Serial.begin(9600);
36. Serial.println(" Arduino Serial Servo Control");
37. Serial.println("Press < or > to move, spacebar to center");
38. Serial.println();
39. }
40.
41. void loop() {
42. // wait for serial input
43. if (Serial.available() > 0) {
44. // read the incoming byte:
45. moveServo = Serial.read();
46.
47. // ASCII '<' is 44, ASCII '>' is 46 (comma and period, really)
48. if (moveServo == 44) { pulseWidth = pulseWidth - turnRate; }
49. if (moveServo == 46) { pulseWidth = pulseWidth + turnRate; }
50. if (moveServo == 32) { pulseWidth = centerServo; }
snip