j5e icon indicating copy to clipboard operation
j5e copied to clipboard

Should LED default to PWM

Open dtex opened this issue 4 years ago • 2 comments

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?

dtex avatar Jul 13 '20 15:07 dtex

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.

phoddie avatar Jul 13 '20 16:07 phoddie

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.

dtex avatar Jul 13 '20 21:07 dtex