Loading...
Pages: 1 2 [3]   Go Down
Author Topic: Help with Loops and IFs??  (Read 618 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
God Member
*****
Karma: 9
Posts: 836
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"Haha. Well that kind of stinks.... There's got to be a way to do it, no? smiley-sad

I need the program to get to a certain point where it gets stuck in a loop waiting for an input to go HIGH. Once it goes HIGH I would like it to fall through to the rest of the code."



This is wrong thinking in arduino-world.    You don't want the program to get stuck in a loop in your code.  The loop() function cycles indefinitely to do this,  anyway.   If you want to "wait for something",   you exit from the loop() function  and then it will restart from the top,  to check your condition again.
Logged

Long Island, NY
Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry to beat a dead horse, but I have a followup question.

In the following code, once the input goes HIGH and thus continues on to the rest of the program while the pin continue to be monitored or only when the program/compiler sees that line again?

Code:
while(digitalRead(somePin) == LOW)
{
   keepDoingThis();
}
Logged

Queens, New York
Offline Offline
Edison Member
*
Karma: 27
Posts: 1539
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It will only loop if the condition is true. If the condition is false, then it will get out of the loop.
Logged

UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino

Arduino Tutorials, coming soon.

"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown

Pages: 1 2 [3]   Go Up
Print
 
Jump to: