InputEvents v1.4.0
An easy to use but comprehensive Event Library for Buttons, Encoders, Encoder Buttons, Analog Inputs, Joysticks and Switches.
GpioPinAdapter.h
1#ifndef GpioPinAdapter_h
2#define GpioPinAdapter_h
3
4#include <Arduino.h>
5#include "PinAdapter.h"
6
11class GpioPinAdapter : public PinAdapter {
12
13 public:
27 GpioPinAdapter(byte pin, uint8_t mode = INPUT_PULLUP)
28 : buttonPin(pin),
29 _pinMode(mode)
30 { }
31
32 void begin() {
33 pinMode(buttonPin, _pinMode); //Set pullup first
34 // Top tip From PJRC's Encoder - without this delay the
35 // long-press doesn't fire on first press.
36 // allow time for a passive R-C filter to charge
37 // through the pullup resistors, before anything reads
38 // the initial state
39 delayMicroseconds(2000); //Delay
40 }
41
42 bool read() {
43 return digitalRead(buttonPin);
44 }
45
46 private:
47 byte buttonPin;
48 uint8_t _pinMode = INPUT_PULLUP;
49
50};
51
52#endif
This is the default PinAdapter for regular GPIO pins.
Definition: GpioPinAdapter.h:11
bool read()
Read the current state of the pin.
Definition: GpioPinAdapter.h:42
void begin()
Initialise the pin adapter. Must be safe for repeated calls (Idempotent)
Definition: GpioPinAdapter.h:32
GpioPinAdapter(byte pin, uint8_t mode=INPUT_PULLUP)
Construct a new Gpio Pin Adapter.
Definition: GpioPinAdapter.h:27
The interface specification for button, encoder button and switch pins.
Definition: PinAdapter.h:8