lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi Flyer31,

you do not need to call a delay function to wait for an input to become stable. And definitely not one per input. You do not want to have to wait for 150ms for some action, trust me that is annoying. Actually debouncing works by detecting and reporting the changed value immediately, but ignore further changes for the debounce time. Usually switches don't bounce before they switch, the bounce after they travelled to their new position.

I had successfully implemented a digital input module (sensing switches) that keep a last read state, last sent state, and a time stamp when the read value did change the last time. A changed value is sent immediately if the last change is longer in the past than the debounce time and read and sent value are different. Actually my code used only one byte for the millisecond time stamp (Arduino C++ code, but talks to a Lua script)

Oliver