26 lines
676 B
C
26 lines
676 B
C
|
#ifndef BUTTON_H
|
||
|
#define BUTTON_H
|
||
|
|
||
|
#include <Arduino.h>
|
||
|
|
||
|
class Button
|
||
|
{
|
||
|
public:
|
||
|
Button();
|
||
|
void update(long millis, boolean state); //millis: current time, state: state of button
|
||
|
boolean buttonPressed(); //true (once after update) when button released and not hold down long enough
|
||
|
boolean buttonHold(); //true (once after update) when button held down for long enough.
|
||
|
private:
|
||
|
long _millis_lastinput;
|
||
|
long _timebuttonpressed;
|
||
|
|
||
|
//Short press (true when button short pressed, on release)
|
||
|
boolean _button=false;
|
||
|
|
||
|
//long press (true when button is held down for BUTTONTIMEHOLD, on time elapsed)
|
||
|
boolean _button_hold=false;
|
||
|
|
||
|
};
|
||
|
|
||
|
#endif
|