Skip to content
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

Delay in Reading #65

Open
Abhesheksh opened this issue Nov 23, 2021 · 3 comments
Open

Delay in Reading #65

Abhesheksh opened this issue Nov 23, 2021 · 3 comments
Assignees

Comments

@Abhesheksh
Copy link

Abhesheksh commented Nov 23, 2021

Here is my code below. I am using the Easybutton library for reading the button state. Problem is that in the loop function, even when I press my button for 2 seconds, it does not detect that and takes more time to detect, and even the detection is unreliable. I am sure there is a problem in my code, just can't figure it out. Please help.

Platform : NodeMCU
IDE : Arduino

@evert-arias evert-arias self-assigned this Mar 12, 2022
@evert-arias
Copy link
Owner

Will take a look

@JFClaeys
Copy link

JFClaeys commented Apr 2, 2022

I checked the submitted code and the very first thing that I noticed is the use of Delay(xx).
There is no need of it apart controlling the blinking of LEDs.

While delays can be usefull sometimes, they have the side effect of stopping the cpu until amount of time is reached.

Instead, try to implement a status driven type of code, where you each task required a previous one is coded with a flag (status) indicating (or not) to perform it.
Your while(googleFails < googleFailsMax and yahooFails < yahooFailsMax){ loop, for exemple, is a compact code that could be explosed in 2-3 methods all in the same loop.
So you would need only one button read, a toggling led (based on a count of tick since last executed) type of method) and small methods who would be called when necessary.

So yes, the problem is the code: Delays and too compact code

@Abhesheksh
Copy link
Author

I checked the submitted code and the very first thing that I noticed is the use of Delay(xx). There is no need of it apart controlling the blinking of LEDs.

While delays can be usefull sometimes, they have the side effect of stopping the cpu until amount of time is reached.

Instead, try to implement a status driven type of code, where you each task required a previous one is coded with a flag (status) indicating (or not) to perform it. Your while(googleFails < googleFailsMax and yahooFails < yahooFailsMax){ loop, for exemple, is a compact code that could be explosed in 2-3 methods all in the same loop. So you would need only one button read, a toggling led (based on a count of tick since last executed) type of method) and small methods who would be called when necessary.

So yes, the problem is the code: Delays and too compact code

Thanks, removed the delay functions and code now runs without issue.

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