-
Notifications
You must be signed in to change notification settings - Fork 234
Relative Rotary Encoder SENSOR
Jaume Olivé Petrus edited this page Aug 25, 2017
·
10 revisions
| What | Comments | |
|---|---|---|
| Identifier | REL_ROT_ENCODER | |
| Interface | 3 GPIO | GPIO 1: A signal |
| GPIO 2: B signal | ||
| GPIO 3: SW signal (switch) | ||
| Provides | dir | -1: counter clockwise |
| 0: no movement | ||
| 1: clockwise | ||
| val | encoder value | |
| sw | 0: switch released | |
| 1: switch pushed | ||
| Properties | none | |
![]() |
Notes:
- This sensor requires debouncing by hardware
In this example an encoder is attached at GPIO26 (A), GPIO14 (B) and GPIO21 (SW)
s = sensor.attach("REL_ROT_ENCODER", pio.GPIO26, pio.GPIO14, pio.GPIO21)
s:callback(
function(magnitude)
if (magnitude["dir"] == -1) then
print("ccw, value "..magnitude["val"])
elseif (magnitude["dir"] == 1) then
print("cw, value "..magnitude["val"])
end
end
)
s:callback(
function(magnitude)
if (magnitude["sw"] == 0) then
print("released")
elseif (magnitude["sw"] == 1) then
print("pressed")
end
end
)
