dtex / j5e

Framework for embedded devices using ECMA-419, the ECMAScript® embedded systems API specification, based on Johnny-Five's API
https://www.j5e.dev/
MIT License
64 stars 6 forks source link

Should LED default to PWM #69

Open dtex opened 4 years ago

dtex commented 4 years ago

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?

phoddie commented 4 years ago

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.

dtex commented 4 years ago

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.