I have no explanation of why it does not work but I do wonder why you want to do it. Why not be consistent and use analogWrite() or digitalWrite() for both ?
Why does the function call digitalWrite(LEDR, LOW); not switch off LEDR?
Google Bard:
There are two reasons why the function call digitalWrite(LEDR, LOW); doesn't switch off LEDR in the provided code:
PWM (Pulse Width Modulation): The function analogWrite(LEDR, 1); sets the LEDR pin to PWM mode. In PWM mode, the pin is not fully turned on or off, but rather modulated to produce a varying voltage level. This allows for more precise control over the brightness of an LED or the speed of a motor.
Prioritization: When multiple functions try to control the same pin, the function with the highest priority takes precedence. In this case, the analogWrite(LEDR, 1); call has a higher priority than the digitalWrite(LEDR, LOW); call. This means that the PWM signal from analogWrite() will override the setting from digitalWrite(), keeping the LED partially on even when digitalWrite() tries to turn it off.
To effectively switch off the LED, you would need to either:
Turn off PWM Mode: Use digitalWrite(LEDR, LOW); before calling analogWrite(LEDR, 1); to ensure that the pin is not in PWM mode. This will prevent the PWM signal from overriding the digitalWrite() command.
Use analogWrite(LEDR, 0);: This will set the PWM signal to 0, effectively turning off the LED. However, this will not allow you to control the brightness of the LED.
Google Bard:
The reason why the function call digitalWrite(LEDR, LOW); does not switch off LEDR is because analogWrite() function overrides the pinMode().
The analogWrite() function is used to control the brightness of an LED by setting the duty cycle of the signal. The duty cycle is the percentage of time that the pin is high. For example, a duty cycle of 100% means that the pin is high all the time, while a duty cycle of 0% means that the pin is low all the time.
When you call analogWrite(LEDR, 1), you are setting the duty cycle of LEDR to 100%. This means that the pin is essentially always high, and the LED will be on.
The digitalWrite() function, on the other hand, is used to set the state of a pin to either HIGH or LOW. When you call digitalWrite(LEDR, LOW), you are setting the state of LEDR to LOW. However, since the pin is already set to HIGH by analogWrite(), the digitalWrite() function has no effect.
To turn off LEDR, you need to remove the analogWrite() function call. This will allow the digitalWrite() function to set the state of the pin to LOW and effectively turn off the LED.
No mention of the fact that the WiFiNINA library is #included and that the code will therefore not compile
Really ?
No mention either that the analogWrite() function of the Uno actually calls digitalWrite() if values of 0 or 255 are used or that it sets the pinMode() of the pin to OUTPUT
Bard is very sorry. It want you to know:
"
My apologies for overlooking the inclusion of the WiFiNINA library in the provided code. The inclusion of the WiFiNINA library is indeed problematic, as the Arduino Uno does not support WiFi connectivity natively. Attempting to use the WiFiNINA library with an Arduino Uno will result in compiler errors due to missing hardware support.
To address this issue, you can either remove the inclusion of the WiFiNINA library or select a different board that supports WiFi connectivity, such as the Arduino Uno WiFi Rev2. If you choose to remove the WiFiNINA library, the provided code will function as intended, controlling the LEDs as described.
"