IF statmenet for a certain time

Thank you very much..

Yeah...absolutely correct...regarding using && function....will be completely wrong.....whe we are using return function........will think abt it later how to protect from ..single failure of limit switch damaging.....one thing is to count and limit max no. of steps...of stepper motor after it moves from nearly top to to or from nearly bottom to bottom....

In the sketch provided above.....we are returning a condition to the if statement... ...
For example when we return ..
boolean DoorIsUp()
{
return digitalRead(Limithighhigh) == HIGH);
}

if (gesture == GESTURE_UP && DoorIsDown())
{
// Start lifting the door at high speed.
digitalWrite(dirPin, HIGH);
unsigned stepDelay = 5;

Here we need to digitally read the limithighhigh before the if statement....so that when it calls the (door is down) function...it can check present state compared to return value ie digitalRead(Limithigh)==HIGH.....

or is it otherway round ......I am not sure what will return .function.send back......only a condition digitalread(limithigh==HIGH) if only a condition then we must read the pin before that after each movement of stepper in while looo.....or the value......say if digitalread (limithigh==LOW) then...what....will happen to the condition.....as it is declared a boolean..thx..

Would you be more comfortable if the function was written like this?

boolean DoorIsUp()
{
  int buttonState1 = digitalRead(Limithighhigh);
  return buttonState1 == HIGH;
}

It produces the same result, just in a more round-about way.

Ok.thx..got your point..

Is there a way to write the code for stepper motor without stopping the code in delay time.....??

Yes, there is. If the sketch had other stuff to do, I would redesign it as a Finite State Machine. Then you could use a millis() timer to determine if it was time to do a step.

Ok.thx.

Hi just a small help ..In this code instead of ADPS I am using DF Robot gesture sensor..using DFRobot_Gesture_Touch.h......but when I am running ....this code sometimes ..when it reads gesture down ...and door is not down it moves the door down...but after that again in the loop..it detects gesture up and door is down after the first part of the code....so it again moves it up.....which is not desired......actually code is little different than this ....but I observed through ...serial monitor ....after detecting gesture.....it does as per the code...but when it goes to the start condition of checking the gesture it has some gesture stored in it causing unintentional door movement.....it happens few times not consistently .....tried to put timer and delays..still not working out 100Percent......thx...

It sounds like the problem is that the gesture sensor is reading and buffering a gesture while the door is moving. A possible fix is to empty the gesture sensor when the more is complete:

  while (APDS.gestureAvailable())
    APDS.readGesture();

Put that after the 'while (!DoorIsUp())' and 'while (!DoorIsDown())' loops.

Bingo...Thx now working 100%..does arduino has any software to convert flow charts/logic gates into a Finite state Machines...

Not as far as I know, that's something you have to do manually.

But if by "flow charts" you mean the old school box and diamond jobs which typically do not show states, this would be a good opportunity to eschew those and design projects with state diagrams along the lines of the below. Then the code using switch..case almost falls out at your feet.

image

source