Skip to content

Undefined behaviour (bug) in button debouncing tutorial code #10

Open
@mrexodia

Description

@mrexodia

The documentation page: https://www.arduino.cc/en/Tutorial/Debounce has an error in the code.

The variable buttonState at line 40 is uninitialized which will cause undefined behaviour the first time line 75 if (reading != buttonState) is executed.

Usually (based on testing) buttonState is not equal to reading which results in detection of a button press on startup that did not happen. Since reading is HIGH when the button is not pressed, the correct initial value for buttonState is also HIGH. When changing this, the example functions correctly and the LED is on after the program started.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy