SYNOPSIS
rising, falling = gpio.edge([group, ] nr)
DESCRIPTION
Some GPIO inputs support automatic edge counting. Whenever the signal at the input changes, the respective edge counter increments by one. Edge counters are 16-bit and roll over to zero after reaching 65535.
RETURN VALUE
Returns two values, the counts of the rising and falling edge counters, respectively.
EXAMPLE
Your software must be able to cope with the edge counter rolling over. One way of doing this is shown here. The example function calculates the number of edges that where detected since the last call to the function. By using a subtraction and masking the result to 16 bits, any wrap-around is cancelled out. Only the rising edge is used, to keep the example simple.
>
>
>
>
>
>
>
>
last_rise = 0
function edgedelta()
local next_rise = gpio.edge(...)
local rise = (next_rise - last_rise) & 0xFFFF
last_rise = next_rise
return rise
end