-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlongpush.cpp
60 lines (46 loc) · 1.18 KB
/
longpush.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* Simple blinking by pushing the button or rotary
*
* Dependency: git clone https://github.com/2ni/Button in lib/
*
*/
#include <Arduino.h>
#include "base_functions.h"
#include <Rotary.h> // git clone https://github.com/buxtronix/arduino/blob/master/libraries/Rotary into lib/
#include <Button.h>
Rotary rotary = Rotary(ROTARY_A, ROTARY_B);
int counter = 0;
void buttonPressed(Button::pushType type) {
if (type == Button::SHORT_PUSH) {
DL("short push");
} else if (type == Button::LONG_PUSH) {
DL("long push");
}
}
Button button = Button(ROTARY_BUTTON, LED, buttonPressed);
void rotate() {
unsigned char result = rotary.process();
if (result == DIR_CW) {
counter++;
DF("counter: %d\n", counter);
} else if (result == DIR_CCW) {
counter--;
DF("counter: %d\n", counter);
}
}
void setup() {
pinMode(LED, OUTPUT);
// uart
Serial.begin(115200);
Serial.setTimeout(2000);
while(!Serial) { }
DL("Hello there.");
blink(1, 100);
button.setup();
// connect_to_wifi();
attachInterrupt(digitalPinToInterrupt(ROTARY_A), rotate, CHANGE);
attachInterrupt(digitalPinToInterrupt(ROTARY_B), rotate, CHANGE);
}
void loop() {
button.read();
}