Allow HardwarePWM::addPin method to return true if _count == MAX_CHANNELS, but pin passed was already configured. Return false if trying to add a new pin more than MAX_CHANNELS.

This commit is contained in:
Brandyn Burbank committed 2017-11-05 18:58:41 -07:00
1 parent 49568c0a72
commit e61fbe9a68
1 file changed
+7 -1
+7 -1
View File
@@ -78,7 +78,7 @@ void HardwarePWM::setClockDiv(uint8_t div)
*/
bool HardwarePWM::addPin(uint8_t pin)
{
VERIFY( isPinValid(pin) && (_count < MAX_CHANNELS) );
VERIFY( isPinValid(pin) && (_count <= MAX_CHANNELS) );
// Check if pin is already configured
for(uint8_t i=0; i<_count; i++)
@@ -86,6 +86,12 @@ bool HardwarePWM::addPin(uint8_t pin)
if (_pwm->PSEL.OUT[i] == pin) return true;
}
if ((_count >= MAX_CHANNELS))
{
//Pin not already configured, but this HardwarePWM is full
return false;
}
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);