Pages: [1]   Go Down
Author Topic: PWM not working after detach servos  (Read 101 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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!
Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11672
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: