Hello,
I have a sketch that start with a while-loop to check a button to be pressed and if so continues with the program. The arduino is running 24/7 and everything works fine but it appears that at some point (a very long while) the while-loop ends, obviously although the button was not pressed.
Is it possible that the while loop ends after a very long time by itself? I read that there is this problem with millis sometimes when it counts up to a very large number and starts with 0 again. Probably my problem is somehow related with this problem?
Or is it a save fact that a while-loop never (in terms of really never!) ends until a true breaks it? can anyone help with this? thanks in advance
do {
buttonState = digitalRead(switch);
} while (buttonState == HIGH);
Please post your actual code, this snippet is using a reserved word incorrectly:
buttonState = digitalRead(switch);
^~~~~~
exit status 1
expected primary-expression before 'switch'
No, while loops work, you can infer that buttonState wasn't always HIGH.
Also please post the entire sketch, the problem may be somewhere else. For instance does this while-loop ever get executed - can't tell from a snippet.
pin 13 is used for the switch and its configured as input_pullup.
thats why I wonder if it can even be possible to get "low" by any noise or something else.
I thought using it as input_pullup makes it very stable.
the while loop I posted is just to understand the concept as an example ("switch" is not the name it has in the actual sketch).
The while loop works fine with everything that comes after, so I thought it makes no sense to post all the code that comes after the initial while loop concept.
It just seems that for some reason the while loop ends without buttonevent and this only when it has been in the while-loop for a long time (appr. 2 days)
So I guess there seems to be a reason that gives Pin 13 a "low" occasionally.
could this be soldering-issues?
ok, I didn´t think about that.
so you think using another pin than 13 could help? or do you have another suggestion? I first used the pin w/o input_pullup and put a pulldown resistor, but that didn´t seem to work stable, so I decided to use it with the input_pullup.
if you pull the pin HIGH or LOW in the right way, there is no reason why this would not work (besides as mentioned before a possible watchdog biting you)