• Assume, you have an Espruino Pico, and you have added a button on pin B3 to 3.3V, you proceed as follows:

    pinMode(B3,"input_pulldown");
    var SWBtn = require("SWButton");
      , mySWBtn = new SWBtn(function(k){
        console.log("Btn on B3 detected " + k); // log key press pattern
      },B3);
    

    mySWBtn is now working on pin B3. You need to set the pin mode, otherwise you do not get predictable results, because you put a watch on a float.

    PS: above example assumes also that you download / copy-paste the SWButton code from url on git into your modules folder with the name WSButton.js. You can of course keep the url in the require(...).

  • i have espruino Original, and with code I placed above it is not working with button installed on board, I can call this button from IDE by BTN and BTN1 (and button works with other examples), but not with the code I placed above

    i also try it like this, and still doesn't work

    pinMode(B12,"input_pulldown");//i understand B12 is corresponding to BTN or BTN1 on espruino code
    
    var SWBtn = require("https://raw.githubusercontent.c­om/muet/EspruinoDocs/master/modules/SWBu­tton.js");
    
    var mySWBtn = new SWBtn(function(k){
        console.log("Btn on B3 detected " + k); // log key press pattern
      },B12);
    
About

Avatar for bigplik @bigplik started