forked from whitecatboard/Lua-RTOS-ESP32
-
Notifications
You must be signed in to change notification settings - Fork 0
Relative Rotary Encoder SENSOR
Jaume Olivé Petrus edited this page Aug 29, 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 pressed |
|
Properties | none | |
Callbacks? | yes |
Notes:
- This sensor requires debouncing by hardware
-- Attach encoder. Signal assignments are:
-- A: GPIO26
-- B: GPIO14
-- SW: GPIO21
s = sensor.attach("REL_ROT_ENCODER", pio.GPIO26, pio.GPIO14, pio.GPIO21)
-- Register a callback. Callback is executed when some sensor property changes.
s:callback(
function(data)
if (data.dir == -1) then
print("ccw, value "..data.val)
elseif (data.dir == 1) then
print("cw, value "..data.val)
end
if (data.sw == 1) then
print("sw on")
elseif (data.sw == 0) then
print("sw off")
end
end
)