Hello everybody, I try to make an HMI on Codesys in language ST, whitch controls engines. And for example I have a button  « Left » witch is linked to a variable « ButtonLeft »whitch allows to turn left. When I rest above, the button stays in 1 and the engine continues to turn even when I release the button. That's why I shall like putting it on a rising edge. I saw the function R_Trig but I do not know how to use it. Anybody has an example or can help me? I have made something like this. That is correct? Does my variable « ButtonLeft » will return to 0 when I’ll stop push the button. Thank’s a lot.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It sounds like you want it to only turn left as long as you have the button held down. R_TRIG is not necessary in the situation. All you need to do is tie the input (Button) to the turn left output. If your input (Button) is staying true when you release it then it is not setup correctly. How do you have the <g> button connected to the variable <buttonleft>?</buttonleft></g>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Comingback4u hat geschrieben:
It sounds like you want it to only turn left as long as you have the button held down. R_TRIG is not necessary in the situation. All you need to do is tie the input (Button) to the turn left output. If your input (Button) is staying true when you release it then it is not setup correctly. How do you have the <g> button connected to the variable <buttonleft>?</buttonleft></g>
Before, it is what I made, I put
If (ButtonLeft == 1) Then
pin1: = 0;
pin2: = 1;
pin3: = 1;
End_If
but the problem is that, when I pressed on the button and when it passed in 1. It stays in 1, of the blow the engine continues to turn on its left.
Excuse-me it was a mistake, the variable ButtonLeft is linked to my Button « Left »
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It looks like you just need to add an else statement so it would look like:
IFButtonLeft=1THEN
  //PutlogicinheretoturnontheoutputifButtonLeftisactive
  pin1:=0;
  pin2:=1;
  pin3:=1;ELSE
  //PutlogicinheretoturnofftheoutputifButtonLeftisnotactive
  pin1:=0;
  pin2:=0;
  pin3:=0;END_IF
Without the else statement your outputs will never turn off.
A cleaner approach without using an IF/ELSE statement would be:
pin1:=0;pin2:=ButtonLeft=1;pin3:=ButtonLeft=1;
This would turn on pin2/3 if ButtonLeft is active if all data types are type BOOL.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Comingback4u hat geschrieben:
It looks like you just need to add an else statement so it would look like:
IFButtonLeft=1THEN
  //PutlogicinheretoturnontheoutputifButtonLeftisactive
  pin1:=0;
  pin2:=1;
  pin3:=1;ELSE
  //PutlogicinheretoturnofftheoutputifButtonLeftisnotactive
  pin1:=0;
  pin2:=0;
  pin3:=0;END_IF
No I really need a rising Edge because,
Pin1:=0;
Pin2:=0;
Pin3:=0;
Is a combination to reverse.
Do you know how to use a rising edge please? There is a library to add?
Without the else statement your outputs will never turn off.
A cleaner approach without using an IF/ELSE statement would be:
pin1:=0;pin2:=ButtonLeft=1;pin3:=ButtonLeft=1;
This would turn on pin2/3 if ButtonLeft is active if all data types are type BOOL.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I guess I have no idea what you are asking then. R_TRIG is in the standard library and by your example you already know how to use it. Just remember that the output Q is only TRUE for one cycle. After that one cycle it gets reset back to false so your pins will stay on even without the button being pressed.
VAR
  fb_LeftButtonRTrig: R_TRIG;
  xLeftButton: BOOL;END_VARfb_LeftButtonRTrig(CLK:=xLeftButton);IFfb_LeftButtonRTrig.QTHEN //Setpinstotrueifleftbuttonispressed
  pin1:=0;
  pin2:=1;
  pin3:=1;END_IF
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Comingback4u hat geschrieben:
I guess I have no idea what you are asking then. R_TRIG is in the standard library and by your example you already know how to use it. Just remember that the output Q is only TRUE for one cycle. After that one cycle it gets reset back to false so your pins will stay on even without the button being pressed.
VAR
  fb_LeftButtonRTrig: R_TRIG;
  xLeftButton: BOOL;END_VARfb_LeftButtonRTrig(CLK:=xLeftButton);IFfb_LeftButtonRTrig.QTHEN //Setpinstotrueifleftbuttonispressed
  pin1:=0;
  pin2:=1;
  pin3:=1;END_IF
Ok. Yes I just wanted to Enter my « If » only when I pressed my button. So In my code, R_Trig doesn’t appaer in color. That’s normal? There is a library to add? Because the program is not running. Thank’s a lot for your precious help
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Best I can do I guess is give you an example project. If you run this example and simulation you will see how when you press the left button it will turn pin2/3 on.
Johan10 hat geschrieben:
Hello everybody, I try to make an HMI on Codesys in language ST, whitch controls engines. And for example I have a button  « Left » witch is linked to a variable « ButtonLeft »whitch allows to turn left. When I rest above, the button stays in 1 and the engine continues to turn even when I release the button. That's why I shall like putting it on a rising edge. I saw the function R_Trig but I do not know how to use it. Anybody has an example or can help me? I have made something like this. That is correct? Does my variable « ButtonLeft » will return to 0 when I’ll stop push the button. Thank’s a lot.
You don't need any code to fix your problem i think. I believe your button configuration is just done wrongly. Im quite sure that under input configuration you had put your variable to field "Toggle". Instead of this you should put it to fied "TAP".
See picture below...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everybody, I try to make an HMI on Codesys in language ST, whitch controls engines. And for example I have a button  « Left » witch is linked to a variable « ButtonLeft »whitch allows to turn left. When I rest above, the button stays in 1 and the engine continues to turn even when I release the button. That's why I shall like putting it on a rising edge. I saw the function R_Trig but I do not know how to use it. Anybody has an example or can help me? I have made something like this. That is correct? Does my variable « ButtonLeft » will return to 0 when I’ll stop push the button. Thank’s a lot.
It sounds like you want it to only turn left as long as you have the button held down. R_TRIG is not necessary in the situation. All you need to do is tie the input (Button) to the turn left output. If your input (Button) is staying true when you release it then it is not setup correctly. How do you have the <g> button connected to the variable <buttonleft>?</buttonleft></g>
Before, it is what I made, I put
If (ButtonLeft == 1) Then
pin1: = 0;
pin2: = 1;
pin3: = 1;
End_If
but the problem is that, when I pressed on the button and when it passed in 1. It stays in 1, of the blow the engine continues to turn on its left.
Excuse-me it was a mistake, the variable ButtonLeft is linked to my Button « Left »
It looks like you just need to add an else statement so it would look like:
Without the else statement your outputs will never turn off.
A cleaner approach without using an IF/ELSE statement would be:
This would turn on pin2/3 if ButtonLeft is active if all data types are type BOOL.
No I really need a rising Edge because,
Pin1:=0;
Pin2:=0;
Pin3:=0;
Is a combination to reverse.
Do you know how to use a rising edge please? There is a library to add?
Without the else statement your outputs will never turn off.
A cleaner approach without using an IF/ELSE statement would be:
This would turn on pin2/3 if ButtonLeft is active if all data types are type BOOL.
I guess I have no idea what you are asking then. R_TRIG is in the standard library and by your example you already know how to use it. Just remember that the output Q is only TRUE for one cycle. After that one cycle it gets reset back to false so your pins will stay on even without the button being pressed.
Ok. Yes I just wanted to Enter my « If » only when I pressed my button. So In my code, R_Trig doesn’t appaer in color. That’s normal? There is a library to add? Because the program is not running. Thank’s a lot for your precious help
Best I can do I guess is give you an example project. If you run this example and simulation you will see how when you press the left button it will turn pin2/3 on.
RTrigExample.project [120.1 KiB]
You don't need any code to fix your problem i think. I believe your button configuration is just done wrongly. Im quite sure that under input configuration you had put your variable to field "Toggle". Instead of this you should put it to fied "TAP".
See picture below...