-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRotaryEncoderWithButton.h
47 lines (39 loc) · 1.01 KB
/
RotaryEncoderWithButton.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* RotaryEncoderWithButton
*
* Created on: Aug 9, 2014
* Author: Konstantin Gredeskoul
*
* (c) 2014 All rights reserved. Please see LICENSE.
*
* Example of such Rotary Encoder is this one:
* https://www.adafruit.com/products/377
*
*/
#ifndef RotaryEncoderWithButton_H_
#define RotaryEncoderWithButton_H_
#if defined(ARDUINO) && ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#include <pins_arduino.h>
#endif
#define DEBOUNCE_DELAY 50
// once you press the button, no other events to the button matter
// until this time has passed.
#define BUTTON_PRESS_DELAY 300
class RotaryEncoderWithButton {
public:
RotaryEncoderWithButton(uint8_t rotaryPinA, uint8_t rotaryPinB, uint8_t buttonPin);
void begin();
bool buttonClicked();
uint8_t GetCounter();
void ReadAB();
private:
uint8_t _rotaryPinA, _rotaryPinB, _buttonPin;
bool _hasNotReadRotary;
unsigned long int _lastButtonPressedAt;
signed long int _lastRotaryValue;
uint8_t counter;
};
#endif /* RotaryEncoderWithButton_H_ */