EasyButton icon indicating copy to clipboard operation
EasyButton copied to clipboard

Delay in Reading

Open Abhesheksh opened this issue 3 years ago • 3 comments

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

Abhesheksh avatar Nov 23 '21 16:11 Abhesheksh

Will take a look

evert-arias avatar Mar 12 '22 18:03 evert-arias

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

JFClaeys avatar Apr 02 '22 14:04 JFClaeys

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.

Abhesheksh avatar Apr 02 '22 14:04 Abhesheksh