Skip to content

Error in IDE code example: 'Debounce' #5311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
OldSteve2 opened this issue Aug 29, 2016 · 4 comments
Closed

Error in IDE code example: 'Debounce' #5311

OldSteve2 opened this issue Aug 29, 2016 · 4 comments

Comments

@OldSteve2
Copy link

In the 'Debounce' example provided with the IDE, under "File >Examples >Digital", the value of 'millis()' is stored in a 'long' variable type, which is not large enough:-

long lastDebounceTime = 0;  // the last time the output pin was toggled
// then:-
lastDebounceTime = millis();

It should be stored in an 'unsigned long'.
As a result of this error, many new users have picked up the same bad habit.
Is it possible to have that example modified, and 'long' replaced by 'unsigned long'?
This would save many new users from potential hard-to-detect problems if their code runs for long periods.

Thanks,
... Steve

@dlabun
Copy link

dlabun commented Aug 29, 2016

Which IDE version are you using?

@OldSteve2
Copy link
Author

OldSteve2 commented Aug 29, 2016

V1.6.9
I originally noticed the error in the Arduino Tutorials section, here:-
https://www.arduino.cc/en/Tutorial/Debounce
then was reminded that it's also an example provided with the IDE.
Edit: I should add that I did check, and the same example is provided with IDE V1.6.11, and still has the same error.

agdl added a commit that referenced this issue Aug 30, 2016
As requested in #5311 to avoid overflow issues.
@agdl agdl closed this as completed Aug 30, 2016
@agdl
Copy link
Member

agdl commented Aug 30, 2016

Thank you!

@OldSteve2
Copy link
Author

Thank you very much for fixing this. It's very much appreciated.
(Now I can feel comfortable referring people to that example.)

Keep up the good work,
... Steve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants