A tiny ~2kb library to provide higher level events allowing advanced options via user input with the config button. In addition it provides visual feedback (LEDs) to the user to make counting easier.
Note: The purpose of the button may change in the future.
npm install tessel-button --save
var button = require('tessel-button');
// Hold Count Event
button.on('hold', function(count){
console.log("HOLD COUNT", count);
switch(count){
case 1: flushLogs(); break;
case 2: checkWifi(); break;
case 3: clearLogs(); break;
case 4: reset(); break;
default:
break;
}
});
// Quick Tap Event
button.on('click', function(clicks){
console.log('CLICK COUNT', clicks);
});
You should see the pattern.
Count | LED2 | LED1 | Conn | Error |
---|---|---|---|---|
1 | X | |||
2 | X | X | ||
3 | X | X | X | |
4 | X | X | X | X |
5 | X | X | X | |
6 | X | X | ||
7 | X | |||
8 | ||||
9 | X | |||
10 | X | X | ||
11 | X | X | X | |
12 | X | X | X | X |
13 | X | X | X | |
14 | X | X | ||
15 | X |
Default
: 500
This option controls the time that needs to elapse before the hold count is incremented.
Default
: 300
The time in between presses in order for a group of clicks to count. This value should be lower then button.hold_duration
.
add an event listener onto the button
. Returns the hold count.
button.on('hold', function(count){
});
add an event listener onto the button
. Returns the click count.
button.on('click', function(count){
});
I have notice bizarre behavior when registering multiple listeners on the button
press
and release
events. Haven't had time to research it deeper. I believe there maybe an issue inside the firmware.