diff --git a/cores/nRF5/HardwarePWM.cpp b/cores/nRF5/HardwarePWM.cpp index 89d05887..5cf601ce 100644 --- a/cores/nRF5/HardwarePWM.cpp +++ b/cores/nRF5/HardwarePWM.cpp @@ -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);