Nano 33 BLE digitalWrite <> analogWrite

From reset, digitalWrite to LEDR, LEDB and LEDG works as expected after the appropriate pinMode commands are issued. THEN analogWrite to any or all of those pins also works as expected. THEN, however, going back to digitalWrite (LEDR, LOW) (for example) leaves the LEDs with (apparently) the PWM that was in place when the analogWrite command was executed. In desperation, I added this (in an attempt to restore the original conditions before a subsequent digitalWrite):

void RGBLedsOff()
{
  pinMode(LEDR, INPUT); 
  pinMode(LEDG, INPUT);
  pinMode(LEDB, INPUT);
  pinMode(LEDR, OUTPUT);
  pinMode(LEDG, OUTPUT);
  pinMode(LEDB, OUTPUT);
  digitalWrite(LEDR, HIGH);
  digitalWrite(LEDG, HIGH);
  digitalWrite(LEDB, HIGH);
  Serial.println ("RGBLedsOff");
}

only to find that the LEDs are still on (lit) with the last PWM values.

Is it possible to disconnect the PWM from the 3 colour LED after it has been connected?

The issue is discussed here.
https://forum.arduino.cc/t/nice-use-of-onboard-rgb-led-digitalwrite-after-analogwrite-fails/654483

It appears that you need to use mbed syntax to manage this.

Thank you for that pointer. The solution illustrated there (and honest: I looked for something of the sort in the fora!) is not what one hopes to find in the best of all possible worlds, but there it is.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.