Page 1 of 2
Loop While!
Posted: Thu Oct 09, 2025 2:00 pm
by jgu1
Hi all!
In a project where I have to control a Garageport , control a motor up and down (only need the controlling).
I have tryed to make a program where I have a 2ch remote, one for up and one for down. I want to when I press the Up button the port start opening and stop at the end by a endswitch, but if I want to stop on the middle on the way up I press the Up button again but the remotebutton does not work the endswitch work in real world, all work in simulation.
I use in the loop : RemoteUP = 1 || Endestop_Up = 1 (Also tested with OR) the endstop wok fine, but not the Up botton. hope it make sense.
Any help please what do I wrong
Br Jorgen
Re: Loop While!
Posted: Thu Oct 09, 2025 3:27 pm
by mnfisher
Hi Jorgen,
In 'Up' - it checks if RemoteUp = 1 then immediately does a loop PortB->RemoteUp while RemoteUp = 0 should this be until RemoteUp = 0?
Martin
Re: Loop While!
Posted: Thu Oct 09, 2025 7:20 pm
by jgu1
Hi MArtin!
Thanks for answer.
I guess you mean like this: RemoteDown = 0 || Endestop_Down = 1 (Same for UP) just runs through the loop. Just test it but not working. Now the moter sop when I relase the Down button.
This is what I want :
- first time I press Down go to first loop so this loop wait until I release the down button
- When I release the down button the flow should go to next loop and wait utill I press the down button again OR endstop go high, then leave the loop and the motor switch off.
Maybe I am wrong but in my opinion or wish (Maybe wrong) if I said: RemoteDown = 1 || Endestop_Down = 1 then leave th loop and stop the motor?
Hope you understand my explanation

Re: Loop While!
Posted: Thu Oct 09, 2025 9:05 pm
by mnfisher
Yes - I think I follow:
So maybe something along the lines of:
In Up:
Code: Select all
Read RemoteUp
Read EndStopUp
If (RemoteUp == 1) && (EndStop == 0) // RemoteUp pressed and door isn't already up
Loop
Read RemoteUp
Until RemoteUp == 0 // Wait for button to be released
StartMotor to raise door
Loop
Read EndStopUp
Read RemoteUp
Read RemoteDown // In case user changes mind - and wants to reverse direction
Until RemoteUp || RemoteDown || EndStopUp // Stop if either button is pressed or endstop (top) hit
StopMotor
As PseudoCode - but hopefully gets the logic for what you want? Could be altered to start the motor whilst RemoteUp is pressed - but then should check EndStopUp and RemoteDown in the first loop too (what happens if the user presses both buttons?)
Martin
Re: Loop While!
Posted: Fri Oct 10, 2025 1:13 am
by viktor_au
Please change it, Jorgen.
In the gate (door,etc) I used 4 states.
0. Gate is moving
1. Gate is closed
2. Gate is opened.
3. Errors
----------------
Note: this is an old draft block-diagram.
Moving state is a complex one. Plenty of possible errors.
In case of an error, stop the gate and id the error.
Re: Loop While!
Posted: Fri Oct 10, 2025 9:00 am
by jgu1
Hi Martin and Victor_Au!
I am very grateful for your help, I understand some of what you write, not all of it. I have made a new program in a completely different way, it takes up more space but it works perfectly.
I just can't understand why my OR function doesn't work when I wait in a loop, and it annoys me (see picture)
Maybe I am wrong but, is it correct that, that, stayin the loop until RemoteUP = 1 || Endestop_Up = 1 if one of these getting high leave the loop?
Only Endstop work. It work fine in simulation
New program att. but not so simplifiet as the first
Jorgen
Re: Loop While!
Posted: Fri Oct 10, 2025 8:33 pm
by mnfisher
Hi Jorgen,
I'd recommend some parenthesis around the parts of the OR
So if (A = 1) || (B = 1)....
Alternatively - as A and B are 0 or 1 (RemoteUp and EndStop!) - declare them as boolean (true = 1 and false = 0)
and then just if A || B ... (Use || for OR and && for AND - though bitwise OR should work for 0 and 1)
Viktor - has a really good suggestion - if the motor pulls a high current (stalled - due to crushing your car?) - then the motor should stop!
Martin
Re: Loop While!
Posted: Fri Oct 10, 2025 10:49 pm
by viktor_au
Hi Jorgen
A few questions.
How do you control the motor?
Is this project for an existing garage door with motor, electronics, etc?
Do you design a new garage door with your electronics?
Looks like you use only two buttons: up and down.
What is the reason of an interrupt?
You have four macros inside an interrupt macro.
Basically all your main program inside the interrupt macro.
Thanks.
Re: Loop While!
Posted: Sat Oct 11, 2025 9:19 am
by jgu1
Hi both. Thanks again.
I think I've tried all the tests.
I tryed all these:
UNTIL(RemoteDown == 1 || Endestop_Down == 1)
UNTIL(RemoteDown = 1 OR Endestop_Down = 1)
WHILE(RemoteDown == 0 && Endestop_Down == 0)
UNTIL((RemoteDown == 0) && (Endestop_Down == 0))
And your suggest Martin (RemoteDown == 1) || (Endestop_Down == 1)

none of them work
I sense that one of the variables is not being read in FC as soon as there are two variables, bugs?
@Victor_au :
A program , I have a 2CH remote TX/RX.
I understand your concern. It is an existing garage gate where the control has burned out. Fortunately, the control that controls up or down still works. I only need to deliver a signal for up and one for down and endstop. So I thought "piece of cake" in Flowcode, but I got ???? with the OR function. The reason why I need the OR function is that the user has the possibities to stop the motor the before the endstop if he wish, and start it again and maybe continue or run the other way.
I made a new control program as you can see and it works perfectly, I have even put a timer in there that means that if one of the end stops fails it will stop the motor after a time, reset the Arduino. By the way, the void(* resetFunc) (void) = 0; in Suplementary code and in Cblock resetFunc(); doesn't work either, so I made my own by restetting by HW.
You ask:
" What is the reason of an interrupt?
You have four macros inside an interrupt macro.
Basically all your main program inside the interrupt macro."
A dirty way to make as many interrupt input I wish by help of timer and to awoid the OR function in a loop, it work perfectly, if you wish I can add some comment in the program for better understanding?
Maybe the MM team will look into OR funktion and check if I am rigth or not, until then I will use the new control I have made.
Again thank“s to you both:)
Jorgen
Re: Loop While!
Posted: Sat Oct 11, 2025 10:12 am
by viktor_au
Understood Jorgen.
The remote controller is the original one, isn't it?.
I am not sure if it is wired or wireless one.
You say, that ' a new control program works perfectly'.
I hope somebody help you with a small problems.
All the best.