You are reading a single comment by @Rollo and its replies. Click here to read the full conversation.
  • Hello, I'm having problems with Pico and magnetic reed switches.

    The idea is that on board LED indicate state of that switch i.e. green LED on when open, green LED off when closed. It all works well at first but when I quickly toggle the switch for a little while then LED gets "out of sync" with my switch, that is it lights green when closed.

    I'm having this issue both with pull-up and pull-down connections, tried with a different switch and debounce values. I must be missing something - but what? :)

    Example code:

    var door = new Pin(A8);
    var ledOpen = LED2;
    var ledHold = LED1;
    
    E.on("init", function () {
      door.mode("input");
    });
    
    function doorOpenedHandler() {
      ledOpen.set();
    }
    
    function doorHeldHandler() {
      ledHold.set();
    }
    
    function doorClosedHandler() {
      ledOpen.reset();
      ledHold.reset();
    }
    
    setWatch(function () {
      doorOpenedHandler();
    }, door, {repeat: true, edge: "falling", debounce: 0});
    
    setWatch(function () {
      doorHeldHandler();
    }, door, {repeat: true, edge: "falling", debounce: 2000});
    
    setWatch(function () {
      doorClosedHandler();
    }, door, {repeat: true, edge: "rising", debounce: 0});
    

About

Avatar for Rollo @Rollo started