Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomiti/8d6aac4c492049bc4118f1787a96decb to your computer and use it in GitHub Desktop.
Save tomiti/8d6aac4c492049bc4118f1787a96decb to your computer and use it in GitHub Desktop.
#define T_SAFE 10 // minimum low/high in one duty cycle to avoid zero value
#define T_MIN 500 // min value for HIGH period
#define T_MAX 2500 // max value for HIGH period
#define T T_MAX+T_SAFE // duty cycle for servo motor in micro-seconds
int servo_pin = 9; // PWM pin
void setup() {
pinMode(servo_pin, OUTPUT); // sets the pin as output
// start at angle = 0
th = T_MIN;
tl = T - th;
// rotate motor using pulse-width
digitalWrite(servo_pin, HIGH);
delayMicroseconds(th);
digitalWrite(servo_pin, LOW);
delayMicroseconds(tl);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment