You are reading a single comment by @allObjects and its replies.
Click here to read the full conversation.
-
in reply to @allObjects
sorry but still not clear,
I used your parts of code above and still have some errorsdo I need some setWatch to make it run?
is this example below enough to run or there is missing part?
in my case this code doesn't detect any buttonvar SWBtn = require("https://raw.githubusercontent.com/muet/EspruinoDocs/master/modules/SWButton.js"); var mySWBtn = new SWBtn(function(k){ console.log("BTN1 detected " + k); // log key press pattern if (k === "L" ) { LED1.set(); } else if (k === "LS" ) { LED1.reset(); } else if (k === "LL" ) { LED2.set(); } else if (k === "LLS") { LED2.reset(); } });
@bigplik, you just pass a second argument into the constructor. The second argument is the button / pin and is optional. If absent, it is BTN1.
The constructor accepts three arguments of which latter two are optional:
If you construct the software button disabled, you can enable - as well as disable - it anytime in the code:
With application code controlled enabling/disabling of the SW Button you can ensure unambiguous UI behavior.
Since SWButton (what you get from module) is a constructor, you can setup multiple SW Buttons, like:
To see the code, just open in the browser the url in the require. You will notice that it includes much more information - including inline doc and examples. SW button is quite 'open': you even can configure the (detection) timings meeting custom requirements: