Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define servoPin 9
- #define t_periodo 20000
- #define t_min 900
- #define t_max 2300
- void setup() {
- pinMode(servoPin, OUTPUT);
- }
- void loop() {
- // Pulso a cada 20ms
- // INCREMENTO
- for(int i=0;i<=180;i+=1){
- digitalWrite(servoPin, HIGH);
- delayMicroseconds(t_min + (i*((t_max-t_min)/180))); // tempo em nível alto
- digitalWrite(servoPin, LOW);
- delayMicroseconds(t_periodo - (t_min + (i*((t_max-t_min)/180))));
- delay(20);
- }
- // DECREMENTO
- for(int i=180;i>0;i-=1){
- digitalWrite(servoPin, HIGH);
- delayMicroseconds(t_min + (i*((t_max-t_min)/180))); // tempo em nível alto
- digitalWrite(servoPin, LOW);
- delayMicroseconds(t_periodo - (t_min + (i*((t_max-t_min)/180))));
- delay(20);
- }
- }
Add Comment
Please, Sign In to add comment