/* Assignment: Lab 8 Part 2 - Servo Control with Serial Input
Class: MECH 3032 - Circuits and System Lab
Description: Write an Arduino sketch that receives the servo motor
angular position from serial input. The servo motor position
will change based on the given valid angle.
Author: Breanna Herrera
Date: 4/5/24
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
long readByte;
void setup() {
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
if(Serial.available() > 0) {
readByte = Serial.parseInt();
if((readByte > 0) && (readByte <= 170)) {
Serial.print("Angle(degrees): ");
Serial.println(readByte);
myservo.write(readByte);
}
}
}