-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWheel.cpp
More file actions
44 lines (38 loc) · 1.03 KB
/
Copy pathWheel.cpp
File metadata and controls
44 lines (38 loc) · 1.03 KB
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
#include <Arduino.h>
#include <RotaryEncoder.h>
#include "CFG.h"
#include "PINS.h"
#include "Wheel.h"
// Encoder is https://www.jaycar.co.nz/rotary-encoder-with-pushbutton/p/SR1230
Wheel wheel;
RotaryEncoder encoder(PIN_ENCODER_A, PIN_ENCODER_B, RotaryEncoder::LatchMode::TWO03);
void Wheel::Init()
{
attachInterrupt(PIN_ENCODER_A, isr, CHANGE);
attachInterrupt(PIN_ENCODER_B, isr, CHANGE);
}
void Wheel::Update()
{
encoder.tick();
}
int Wheel::GetRotation() // -1, 0 or +1
{
RotaryEncoder::Direction dir = encoder.getDirection();
#if CFG_ROTATE_LCD
if (dir == RotaryEncoder::Direction::CLOCKWISE)
return -1;
else if (dir == RotaryEncoder::Direction::COUNTERCLOCKWISE)
return +1;
#else
if (dir == RotaryEncoder::Direction::CLOCKWISE)
return +1;
else if (dir == RotaryEncoder::Direction::COUNTERCLOCKWISE)
return -1;
#endif
return 0;
}
// This interrupt routine will be called on any change of one of the input signals
void Wheel::isr()
{
encoder.tick();
}