Arduino Forum

International => India => Topic started by: mrameshwaram on May 20, 2020, 08:33 am

Title: IF statement to be used inside FOR loop with sensor input
Post by: mrameshwaram on May 20, 2020, 08:33 am
hello,
I am new to Arduino,

I want to do the following stuff in Arduino:

1. Read the signal from sensor and will store it as x. for example x=6.

2. if x=6, "I want to run two motors one after another after getting a signal from IR sensor and stop". This process  should run for X=6 times after each signal input from IR sensor.
I tried this so many times with IF statement inside FOR loop but failed.

3.The loop should end and wait for next X value. It may be 6 or 12 or any thing.

your help will be appreciated.
Title: Re: IF statement to be used inside FOR loop with sensor input
Post by: TheMemberFormerlyKnownAsAWOL on May 27, 2020, 06:30 pm
Post what you already tried.

Tell is why it fell short of your expectations.
Title: Re: IF statement to be used inside FOR loop with sensor input
Post by: TheUNOGuy on Jul 02, 2020, 05:00 pm
You can use a while loop to wait for the input:

while ( !irrecv.decode(&results) );
x = results.value;

if ( x == 6 ) {
   // Run the motors
}