commit a0d2674217fd4a2b6052925078ad057c9f8e86f7 Author: James Devine Date: Wed Jan 17 23:22:35 2018 +0100 diff --git a/Pushbuttontest.ino b/Pushbuttontest.ino new file mode 100644 index 0000000..2188d21 --- /dev/null +++ b/Pushbuttontest.ino @@ -0,0 +1,74 @@ + +/* ClickButton library demo + + OUtput a message on Serial according to different clicks on one button. + + Short clicks: + + Single click - + Double click - + Triple click - + + Long clicks (hold button for one second or longer on last click): + + Single-click - + Double-click - + Triple-click - + + 2010, 2013 raron + + GNU GPLv3 license +*/ +#include "clickButton.h" + + +// the Button +const int buttonPin1 = 4; +ClickButton button1(buttonPin1, LOW, CLICKBTN_PULLUP); + +// Button results +int function = 0; + + +void setup() +{ + Serial.begin(9600); + pinMode(D4, INPUT_PULLUP); + + // Setup button timers (all in milliseconds / ms) + // (These are default if not set, but changeable for convenience) + button1.debounceTime = 20; // Debounce timer in ms + button1.multiclickTime = 250; // Time limit for multi clicks + button1.longClickTime = 1000; // time until "held-down clicks" register +} + + +void loop() +{ + // Update button state + button1.Update(); + + // Save click codes in LEDfunction, as click codes are reset at next Update() + if(button1.clicks != 0) function = button1.clicks; + + if(function == 1) { + bool success; + success = Particle.publish("ButtonPress", "SinglePush", 0, PUBLIC); + if (!success) { + Serial.println("failedtopublish"); // get here if event publish did not work + } + }; + + if(function == 2) Serial.println("DOUBLE click"); + + if(function == 3) Serial.println("TRIPLE click"); + + if(function == -1) Serial.println("SINGLE LONG click"); + + if(function == -2) Serial.println("DOUBLE LONG click"); + + if(function == -3) Serial.println("TRIPLE LONG click"); + + function = 0; + delay(5); +}