Moddable-OpenSource / moddable

Tools for developers to create truly open IoT products using standard JavaScript on low cost microcontrollers.
http://www.moddable.com
1.32k stars 236 forks source link

ESP32: Digital.write makes a glitch noise #1403

Closed ghamaya closed 2 weeks ago

ghamaya commented 3 weeks ago

When you use the Digital module for critical control, it is better to use clear description. Below sample (pin:4, pin:5) shows the difference.

import Timer from "timer";
import Digital from "pins/digital";
let outpin = new Digital({pin: 5, mode: Digital.Output})
let blink = 0;
Timer.repeat(() => {
    blink = blink ^ 1;
    Digital.write(4, blink);    // pin: 4
    outpin.write(blink);        // pin: 5
}, 200);

digitalout2

phoddie commented 2 weeks ago

Interesting image, thank you.

The Digital.write() API doesn't fully initialize the pin itself. It assumes that has been done elsewhere. The Digital instance does full initialization.

The ECMA-419 IO APIs (which include Digital) eliminate this ambiguity by only provide the write method on an instance.

So, yes, it is better to use either the new Digital or ECMA-419'digital.