Tessel Button
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.
Install
npm install tessel-button --save
Usage
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);
});
Visual Feedback
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 |
Options
button.hold_duration
Default
: 500
This option controls the time that needs to elapse before the hold count is incremented.
button.click_timeout
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
.
Events
hold
add an event listener onto the button
. Returns the hold count.
button.on('hold', function(count){
});
click
add an event listener onto the button
. Returns the click count.
button.on('click', function(count){
});
Issues
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.