var mySWBtn = new SWBtn(function(k){
console.log("BTN1 detected " + k);
if/*sel*/ (k === "S") { LED1.set(); // one short press on
} else if (k === "L") { LED1.reset(); // one long press off
}
});
If you have a button on a pin - for example, A8 - use this:
var mySWBtn = new SWBtn(function(k){
console.log("Button on A8 detected " + k);
if/*sel*/ (k === "S") { LED1.set(); // one short press on
} else if (k === "L") { LED1.reset(); // one long press off
}
},A8);
More sophisticated, you can go with this:
var fs = // functions
{ "S": function() { LED1.set(); }
, "L": function() { LED1.reset(); }
};
var mySWBtn = new SWBtn(function(k){ if (fs[k]) fs[k](); }, A8);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Example below assumes default button BTN1.
If you have a button on a pin - for example, A8 - use this:
More sophisticated, you can go with this:
Note: Code only partially tested. ;-)