Skip to content

Does your debounce have an issue with tmr.now() rollover? #2

@marcelstoer

Description

@marcelstoer

Your debounce code at https://github.com/hackhitchin/esp8266-co-uk/blob/master/tutorials/introduction-to-gpio-api.md was (indirectly) discussed at http://www.esp8266.com/viewtopic.php?f=24&t=4833&start=5#p29127. It essentially says

tmr.now() rolls over at 2147 seconds - the NodeMCU API page indicates uint31, not uint32, which means it wraps to zero when it reaches the max value for int32. The value (now - last) will be negative when (last) gets really big and (now) wraps around.

And it goes on to propose adding if delta < 0 then delta = delta + 2147483647 end; as a remedy.

-> https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en#tmrnow

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions