Go Down

Topic: PWM not working after detach servos (Read 255 times) previous topic - next topic

xun_yang

As pointed out by http://arduino.cc/en/Reference/ServoDetach, pwm on pin 9 and 10 should be available once I detached the servo. However it doesn't work with my example:

This one has an LED attached to pin 9, and servo attached to pin 4.

Code: [Select]
#include <Servo.h>

Servo srv;
int srvPos=0;

void setup(){
}
void loop(){
  analogWrite(9,100);
  delay(1000);
  analogWrite(9,0);
  runServo();
}

void runServo(){
  srv.attach(4);
  srvPos+=50;
  srvPos=srvPos%360;
  int toWrite;
  if(srvPos>180)toWrite=360-srvPos;
  else toWrite=srvPos;
 
  srv.write(toWrite);
  delay(1000);
  srv.detach();
}


Does anybody know why detach doesn't work here? Thanks!

MarkT

Looking at the code of the Servo library it appears just to inhibit timer
interrupts when a timer is no longer needed for Servo use, not reset its
mode and period for analogWrite().

Either the Servo library or its documentation has a bug that should be reported.
[ I won't respond to messages, use the forum please ]

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy