Skip to content

Instantly share code, notes, and snippets.

@TareObjects
Created February 9, 2018 23:32
Show Gist options
  • Save TareObjects/12106bf52ba1bc9176805749ab9f3943 to your computer and use it in GitHub Desktop.
Save TareObjects/12106bf52ba1bc9176805749ab9f3943 to your computer and use it in GitHub Desktop.
#define servoPin 12
void setup() {
Serial.begin(115200);
pinMode(servoPin, OUTPUT);
}
void loop() {
for (float pos = -90; pos <= 90; pos += 0.1) {
float msec = pos / 90.0 * 0.5 + 1.5;
long limitUSec = msec * 1000;
digitalWrite(servoPin, HIGH);
delayMicroseconds(limitUSec);
digitalWrite(servoPin, LOW);
delayMicroseconds(10000-limitUSec);
delay(10);
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment