MCPcopy Create free account
hub / github.com/RobTillaart/Arduino / rotaryDecoder

Class rotaryDecoder

libraries/rotaryDecoder/rotaryDecoder.h:17–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16
17class rotaryDecoder
18{
19public:
20 explicit rotaryDecoder(const int8_t address, TwoWire *wire = &Wire);
21
22#if defined (ESP8266) || defined(ESP32)
23 bool begin(uint8_t sda, uint8_t scl, uint8_t count = 4);
24#endif
25
26 bool begin(uint8_t count = 4);
27 bool isConnected();
28
29 void readInitialState();
30
31 // for polling version,
32 // checkChange is bit faster than a call to update
33 // so useful if there are only a few updates
34 bool checkChange();
35
36 // read and update the counters
37 bool update(); // assumes two directions => +1 and -1
38 bool updateSingle(); // assumes single direction => + ++ +++
39
40 // re = rotary encoder
41 int32_t getValue(uint8_t re) { return _encoder[re]; };
42 void setValue(uint8_t re, int32_t value = 0) { _encoder[re] = value; };
43
44 // DEBUG
45 uint8_t getLastPosition(uint8_t re) { return _lastPos[re]; };
46
47
48private:
49 uint8_t _count = 0;
50 uint8_t _lastValue = 0;
51 uint8_t _lastPos[4] = { 0,0,0,0 };
52 int32_t _encoder[4] = { 0,0,0,0 };
53
54 uint8_t _read8();
55 uint8_t _address;
56 TwoWire * _wire;
57};
58
59
60// -- END OF FILE --

Callers 1

unittestFunction · 0.85

Calls

no outgoing calls

Tested by 1

unittestFunction · 0.68