Skip to content

Instantly share code, notes, and snippets.

@cheewee2000
Created October 24, 2018 16:33
Show Gist options
  • Save cheewee2000/7d5e9f83a1d7d61ae176d028b363db6a to your computer and use it in GitHub Desktop.
Save cheewee2000/7d5e9f83a1d7d61ae176d028b363db6a to your computer and use it in GitHub Desktop.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int servoPos;
void setup() {
//start serial communication at 9600baud (pulses per second)
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
//check if there's anything in Serial RX
if (Serial.available() > 0) {
servoPos = Serial.readStringUntil("\n").toInt();
myservo.write(servoPos);// tell servo to go to position 0-180
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment