InputEvents v1.4.0
An easy to use but comprehensive Event Library for Buttons, Encoders, Encoder Buttons, Analog Inputs, Joysticks and Switches.
PinMixerAdapter.h
1#ifndef PinMixerAdapter_h
2#define PinMixerAdapter_h
3
4#include <Arduino.h>
5#include "PinAdapter.h"
6
12
13 public:
24 : pin1(pin1), pin2(pin2)
25 { }
26
27 void begin() {
28 pin1->begin();
29 pin2->begin();
30 currentStatePin1 = previousStatePin1 = pin1->read();
31 currentStatePin2 = previousStatePin2 = pin2->read();
32 state = currentStatePin1; //we have to choose one...
33 }
34
35 bool read() {
36 //Only update state if the either of the pixer pin states have changed
37 currentStatePin1 = pin1->read();
38 if ( currentStatePin1 != previousStatePin1 ) {
39 previousStatePin1 = currentStatePin1;
40 state = currentStatePin1;
41 }
42 currentStatePin2 = pin2->read();
43 if ( currentStatePin2 != previousStatePin2 ) {
44 previousStatePin2 = currentStatePin2;
45 state = currentStatePin2;
46 }
47 return state;
48 }
49
50 private:
51 PinAdapter* pin1;
52 PinAdapter* pin2;
53 bool state; //the returned state
54 bool currentStatePin1;
55 bool previousStatePin1;
56 bool currentStatePin2;
57 bool previousStatePin2;
58
59};
60
61#endif
The interface specification for button, encoder button and switch pins.
Definition: PinAdapter.h:8
virtual bool read()=0
Read the current state of the pin.
virtual void begin()=0
Initialise the pin adapter. Must be safe for repeated calls (Idempotent)
This is the default PinAdapter for regular GPIO pins.
Definition: PinMixerAdapter.h:11
void begin()
Initialise the pin adapter. Must be safe for repeated calls (Idempotent)
Definition: PinMixerAdapter.h:27
bool read()
Read the current state of the pin.
Definition: PinMixerAdapter.h:35
PinMixerAdapter(PinAdapter *pin1, PinAdapter *pin2)
Takes two PinAdapter classes and mixes their read() calls. Initial state is taken from pin1.
Definition: PinMixerAdapter.h:23