• The delay function is tricky - it'd be nice to add it but in a way it encourages coding in a style that works very badly with Espruino. As you'd see with your previous code, having loops that don't return will effectively stall the interpreter and will stop other things from being executed - it's one of the reasons why web browser JavaScript doesn't have anything similar (afaik) either.

    It also exposes the slow-ish speed of execution, for instance:

    digitalWrite(LED1,1);
    delay(1);
    digitalWrite(LED1,0);
    

    Won't keep the LED on for 1ms, it'll probably end up being maybe 0.1ms more (don't know - haven't tested it) because of the relatively slow execution speed. I can pretty much guarantee that as soon as I add the delay function I'll get complaints about exactly that kind of problem :)

    There aren't pages on power management at the moment, but I've put it on my list of things to add. In short, something like this:

    setInterval(function() {
      doStuff();
    }, 60000);
    setDeepSleep(1);
    

    or

    setWatch(function() {
      doStuff();
    }, BTN, true);
    setDeepSleep(1);
    

    Will instantly be very power efficient, dropping the device into a state where it draws around 100uA.

    However at the moment I haven't got
    wake from USB working, so you're best off always having a setWatch on BTN so you can insert the USB cable and press BTN to wake the device up so that it connects again.

About

Avatar for Gordon @Gordon started