@@ -7,8 +7,8 @@ For information about the library, license and author, see Servo_Hardware_PWM.h
77#include < Arduino.h>
88#include < Servo_Hardware_PWM.h>
99
10- int servoCount = 0 ;
11- bool pinActive[MAX_SERVOS] = {false };
10+ static int servoCount = 0 ;
11+ static bool pinActive[MAX_SERVOS] = {false };
1212
1313Servo::Servo ()
1414{
@@ -273,6 +273,81 @@ void Servo::detach()
273273 }
274274}
275275
276+ void Servo::detachAll () {
277+ if (pinActive[0 ] == true )
278+ {
279+ // resetting the control register A and B:
280+ TCCR3A = 0x0 ;
281+ TCCR3B = 0x0 ;
282+ // resetting the TOP value:
283+ OCR3A = 0x0 ;
284+
285+ OCR3B = 0x0 ; // resetting the pulse width
286+ DDRE ^= (1 << PE4); // bit 4 (pin 2) stop output
287+ pinActive[0 ] = false ;
288+ }
289+ if (pinActive[1 ] == true )
290+ {
291+ // resetting the control register A and B:
292+ TCCR3A = 0x0 ;
293+ TCCR3B = 0x0 ;
294+ // resetting the TOP value:
295+ OCR3A = 0x0 ;
296+
297+ OCR3C = 0x0 ; // resetting the pulse width
298+ DDRE ^= (1 << PE5); // bit 5 (pin 3) stop output
299+ pinActive[1 ] = false ;
300+ }
301+ if (pinActive[2 ] == true )
302+ {
303+ // resetting the control register A and B:
304+ TCCR4A = 0x0 ;
305+ TCCR4B = 0x0 ;
306+ // resetting the TOP value:
307+ OCR4A = 0x0 ;
308+
309+ OCR4B = 0x0 ; // resetting the pulse width
310+ DDRH ^= (1 << PH4); // bit 4 (pin 7) stop output
311+ pinActive[2 ] = false ;
312+ }
313+ if (pinActive[3 ] == true )
314+ {
315+ // resetting the control register A and B:
316+ TCCR4A = 0x0 ;
317+ TCCR4B = 0x0 ;
318+ // resetting the TOP value:
319+ OCR4A = 0x0 ;
320+
321+ OCR4C = 0x0 ; // resetting the pulse width
322+ DDRH ^= (1 << PH5); // bit 5 (pin 8) stop output
323+ pinActive[3 ] = false ;
324+ }
325+ if (pinActive[4 ] == true )
326+ {
327+ // resetting the control register A and B:
328+ TCCR5A = 0x0 ;
329+ TCCR5B = 0x0 ;
330+ // resetting the TOP value:
331+ OCR5A = 0x0 ;
332+
333+ OCR5C = 0x0 ; // resetting the pulse width
334+ DDRL ^= (1 << PL5); // bit 5 (pin 44) stop output
335+ pinActive[4 ] = false ;
336+ }
337+ if (pinActive[5 ] == true )
338+ {
339+ // resetting the control register A and B:
340+ TCCR5A = 0x0 ;
341+ TCCR5B = 0x0 ;
342+ // resetting the TOP value:
343+ OCR5A = 0x0 ;
344+
345+ OCR5B = 0x0 ; // resetting the pulse width
346+ DDRL ^= (1 << PL4); // bit 4 (pin 45) stop output
347+ pinActive[5 ] = false ;
348+ }
349+ }
350+
276351void Servo::write (int value)
277352{
278353 if (value < 0 )
@@ -297,27 +372,27 @@ void Servo::writeMicroseconds(int value)
297372 else if (value > MAX_PULSE_WIDTH) {
298373 value = MAX_PULSE_WIDTH;
299374 }
300- if (this ->servoPin == 2 ) {
375+ if (this ->servoPin == 2 && pinActive[ 0 ] == true ) {
301376 OCR3B = 0x0 ;
302377 OCR3B = value * 2 ;
303378 }
304- else if (this ->servoPin == 3 ) {
379+ else if (this ->servoPin == 3 && pinActive[ 1 ] == true ) {
305380 OCR3C = 0x0 ;
306381 OCR3C = value * 2 ;
307382 }
308- else if (this ->servoPin == 7 ) {
383+ else if (this ->servoPin == 7 && pinActive[ 2 ] == true ) {
309384 OCR4B = 0x0 ;
310385 OCR4B = value * 2 ;
311386 }
312- else if (this ->servoPin == 8 ) {
387+ else if (this ->servoPin == 8 && pinActive[ 3 ] == true ) {
313388 OCR4C = 0x0 ;
314389 OCR4C = value * 2 ;
315390 }
316- else if (this ->servoPin == 44 ) {
391+ else if (this ->servoPin == 44 && pinActive[ 4 ] == true ) {
317392 OCR5C = 0x0 ;
318393 OCR5C = value * 2 ;
319394 }
320- else if (this ->servoPin == 45 ) {
395+ else if (this ->servoPin == 45 && pinActive[ 5 ] == true ) {
321396 OCR5B = 0x0 ;
322397 OCR5B = value * 2 ;
323398 }
0 commit comments