• Hey everyone,
    does analogWrite(PIN, 0.5) use less power than digitalWrite(PIN, 1)?
    I'm making a power-critical project and I would like to know if analogWriting an LED half-brightness uses less energy than digitalWriting it to full 1.

    Thanks!

  • Hi,

    You're using a Pico? So it's an STM32...

    http://www.espruino.com/Power+Consumptio­n has some figures for power usage, but basically:

    • Without setDeepSleep(1), the Pico will be drawing 11mA, but the main oscillator will be running all the time. In that case, using analogWrite(PIN, 0.5) will use less power than digitalWrite, but it's still quite a lot.
    • If you have setDeepSleep(1) then the main oscillator will be off, so hardware PWM won't work. However the Pico will be drawing 0.02mA (so way less).

    You could try: analogWrite(pin,0.5,{freq:50,forceSoft:t­rue}) and setDeepSleep(1). That'll use software PWM, however because the chip is able to sleep properly for most of the time it may well be more power efficient.

    Your other options are:

    • use pinMode(pin, "input_pullup") which will turn on the 40k Internal pullup resistor. It's not much but with modern efficient LEDs it can be pretty good - and it works great with setDeepSleep
    • I don't know if all your LEDs are wired in parallel or if you're scanning? One option is just to 'pulse' them every so often:

      var LED_PINS = [ A0, A1, ... ];
      setDeepSleep(1);
      setInterval(function() {
      digitalWrite(LED_PINS, value_to_display);
      digitalWrite(LED_PINS,0);
      }, 50); // 20 times a second
      

    It's a bit like software PWM but it'll work much better with multiple LEDs.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

does analogWrite(PIN, 0.5) use less power than digitalWrite(PIN, 1)?

Posted by Avatar for BootySnorkeler @BootySnorkeler

Actions