Skip to content

Commit 2960d3a

Browse files
committed
Merge branch 'feature/detachAll' into develop
2 parents 5690ec6 + f4e1fad commit 2960d3a

File tree

3 files changed

+89
-12
lines changed

3 files changed

+89
-12
lines changed

keywords.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ Servo KEYWORD1 Servo
1111
#######################################
1212
# Methods and Functions (KEYWORD2)
1313
#######################################
14-
attach KEYWORD2
15-
detach KEYWORD2
16-
write KEYWORD2
17-
writeMicroseconds KEYWORD2
14+
attach KEYWORD2
15+
detach KEYWORD2
16+
detachAll KEYWORD2
17+
write KEYWORD2
18+
writeMicroseconds KEYWORD2
1819

1920
#######################################
2021
# Constants (LITERAL1)

src/Servo_Hardware_PWM.cpp

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1313
Servo::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+
276351
void 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
}

src/Servo_Hardware_PWM.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Servo
6868
Servo();
6969
void attach(int pin); //attach the given pin
7070
void detach(); //detach the used pin
71+
void detachAll(); //automatically detaches all used pins
7172
void write(int value); //write angle in degrees
7273
void writeMicroseconds(int value); //write pulse width in microseconds
7374
private:

0 commit comments

Comments
 (0)