Skip to content

Instantly share code, notes, and snippets.

@mfkenson
Created March 1, 2023 09:11
Show Gist options
  • Save mfkenson/4784b45dedc86f5ffc9f273e684d6e39 to your computer and use it in GitHub Desktop.
Save mfkenson/4784b45dedc86f5ffc9f273e684d6e39 to your computer and use it in GitHub Desktop.
#include <Servo.h>
Servo myservo;
void setup() {
Serial.begin(9600);
myservo.attach(7);
myservo.writeMicroseconds(1500);
}
void loop() {
while (Serial.available() > 0) {
int microsec = Serial.parseInt();
if (Serial.read() == '\n') {
microsec = constrain(microsec, 1000, 2000);
myservo.writeMicroseconds(microsec);
Serial.println(microsec);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment