Open FemmeVerbeek opened 4 years ago
Hi @FemmeVerbeek
analogWrite(LED_PWR, 10);
should just work in any condition unless you already have more than 4 other PWM active (I just tested it). The reason is this assert (https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pwmout_api.c#L146) that checks how many PWM channels are already in use.
Is this your case?
Hi Martino,
Thx for looking into it. I was making art with the onboard leds.
:-)
It looks like analog calling the 5th channel is what caused the
hanging problem.
Apparently assigning a PWM channel stops digitalWrite from
working on that pin .
Is there a (user friendly) way to free up the Pin channel in a
sketch, so that digitalWrite works again? Possibly reassign the
channel to another pin?
Kind regards
Femme Verbeek.
code
void setup()
{ pinMode(LED_BUILTIN,OUTPUT);
analogWrite(LED_BUILTIN,75);
digitalWrite(LED_BUILTIN,1);
delay(1000);
digitalWrite(LED_BUILTIN,0);
}
void loop(){}
I've hit this problem also. digitalWrite after an analogWrite to the same pin does not work. Once I saw this report I changed my digitalWrite calls into analogWrite with values of 0 or 255 and my project is working properly. BTW: I have four analogWrite pins in use.
It looks like two bugs to me.
my not so beautiful workaround
void digitalWrite2(int pinnr , boolean pinhigh){ if (pinnr==LED_PWR) digitalWrite(LED_PWR, pinhigh); else analogWrite(pinnr, 255*pinhigh); } void analogWrite2(int pinnr ,uint8_t value){ if (pinnr==LED_PWR) digitalWrite(pinnr,value>127); else analogWrite(pinnr,value); }
It would be better to solve it by redefining the functions itself but so that it still compiles for other boards.