I bought an Amazon Dash button and am using the dash-button library. I have this code:
var DashButton = require("dash-button");
const DASH_BUTTON_MAC_ADDRESS = "xx:xx:xx:xx:xx:xx";
let button = new DashButton(DASH_BUTTON_MAC_ADDRESS);
console.log("ready");
let subscription = button.addListener(function(){
let date = new Date();
console.log(date.toTimeString() + ": button pressed!");
});
The function gets called twice sometimes in a button press. Here is the output:
ready
10:48:29 GMT+0000 (UTC): button pressed! - first button press
10:48:39 GMT+0000 (UTC): button pressed! - second button press
10:48:40 GMT+0000 (UTC): button pressed! - second button press
Is there any way to add a sort of cooldown to a function so that it can be only called every x seconds?