You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • The diode idea sounds good. One other thing you could look at is if you make a potential divider with 2 resistors, you could read the analog value of the pin to get the voltage, but you could also use setWatch on it so you get called back as soon as the voltage drops

  • I just wired it up.
    Used a 10k resistor to pull D7 against Vin (about 12,5 V from my fully charged LiPo).
    Capacitor is a 1000uF / 25V.

    Strange thing: The display flickers and blacks out rhythmically while D7 is not configured.

    I used this script to test powerdown detection:

    function onInit() {
    
      pinMode( D7, "input_pulldown" );
    
      setWatch(function(e) {
        //LED.set();
        console.log( "power out" );
        var t=0;
        setInterval(function() {
          console.log( "t=", t++ );
        }, 1000 );
      }, D7, { edge: "falling"});
    }
    

    It gives me about 6 seconds console feedback before dying with the LED off:

    power out
    t= 0
    t= 1
    t= 2
    t= 3
    t= 4
    t= 5
    t= 6
    

    With LED set immediately after power down it is only two seconds (still enough for some cleanup probably).

    So basically it seems to work.

    @Gordon: is it normal that it behaves strange when certain pins are used as inputs bot not configured yet?

About

Avatar for Gordon @Gordon started