Brewhouse/lib/Button/Button.h
2023-01-25 21:00:25 -05:00

23 lines
363 B
C++

#ifndef button_h
#define button_h
#include "Arduino.h"
class Button
{
private:
uint8_t btn;
uint16_t state;
public:
void begin(uint8_t button) {
btn = button;
state = 0;
pinMode(btn, INPUT_PULLUP);
}
bool pressed() {
state = (state<<1) | digitalRead(btn) | 0xfe00;
return (state == 0xff00);
}
};
#endif