Last active
February 2, 2020 22:01
-
-
Save tomiti/8d6aac4c492049bc4118f1787a96decb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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