Edges in Text
Part of the Structured Text section of Coddy's PLC Programming journey. Lesson 9 of 17.
In text there are no P and N contacts. Edges come from two blocks: R_TRIG gives Q for one scan when CLK goes from FALSE to TRUE, F_TRIG for one scan when it goes from TRUE to FALSE.
VAR
Press : R_TRIG;
END_VAR
Press(CLK := PB1);
IF Press.Q THEN
Green := NOT Green;
END_IF;This is the one-button toggle. Green := NOT Green; flips the lamp, and the IF lets it flip only on the scan of the press. Without the edge, the lamp would flip on every scan the button is held.
Challenge
EasyMake PB1 a toggle: the first press lights Green, the next turns it off. Holding PB1 must not make it flicker.
Press Run, try it on the machine, then Check.
Try it yourself
VAR
Press : R_TRIG;
END_VAR
// Call Press with PB1, then flip Green on Press.Q
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Structured Text
Practice on your own: PLC playground