j5e
j5e copied to clipboard
Should LED default to PWM
Whether an LED can do PWM values depends on the IO it is driving. When a user instantiates an LED without specifying an IO, we assume it will be on builtin/digital
. i.e.:
const blinker = await new LED(12); // uses builtin/digital
const pulser = await new LED({ pin: 14, IO: "builtin/pwm" });
Should it be the other way around?
One detail to consider: PWM is a limited resource on some hosts. The ESP32, for example, as a limited number of PWM channels. You probably don't want to silently use those up on instances that only need digital (on/off).
If they don't specify the IO, could you take that as a signal that a it is acceptable to change the IO after instantiation? Then you can default to digital and upgrade to PWM if needed.
That makes sense. If they don't explicitly choose a provider or pass in an IO, we assume Digital. If a call is made to a method that requires PWM, we destroy and reopen the IO instance as PWM.
I'll give it a shot.