Join us today!

Notifications
Clear all

[Solved] Momentary Push Button and LED - Programming Challenge

19 Posts
6 Users
14 Reactions
1,092 Views
twinControls
Posts: 115
Admin
Topic starter
(@twincontrols)
Member
Joined: 2 years ago

You have one momentary push button and one LED. When you press the push button and let it go once, LED will turn on and stay on. When you press and let it go again, LED will turn off and stay off. Your push button input is HIGH only when you are pressing it, it is a momentary push button so it does not hold its state when you release the button.  You can only use ladder logic with maximum 3 rungs/networks and no math function blocks are allowed. 

Share your answer with the community ! 🧐

Reply
18 Replies
7 Replies
ehixenbaugh
(@ehixenbaugh)
Joined: 2 years ago

Trusted Member
Posts: 33

@twincontrols What is the difference between this concept and a toggle button? 

In a Toggle Button, you would usually use a one-shot. In TwinCAT, there is nothing that is referred to as a one-shot, but there is something similar called a Command-Edge Detection in TwinCAT

https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/2532295307.html&id=

Is this the same thing?

Reply
ehixenbaugh
(@ehixenbaugh)
Joined: 2 years ago

Trusted Member
Posts: 33
(@joris)
Joined: 2 years ago

Eminent Member
Posts: 17

@ehixenbaugh Are you tested this piece of code?

Reply
ehixenbaugh
(@ehixenbaugh)
Joined: 2 years ago

Trusted Member
Posts: 33

@joris I tried it yesterday and it did not work. I looked at it again this morning and realized I should be checking the status of the LED when the PB is pressed (not the status of the PB!). Attached is my corrected solution.

twincat tgglbutton corrected
Reply
(@joris)
Joined: 2 years ago

Eminent Member
Posts: 17

@ehixenbaugh I am reassured. It's better this way. 😀 👍

Reply
twinControls
Admin
(@twincontrols)
Joined: 2 years ago

Member
Posts: 115

@ehixenbaugh You can think of one-shot in RS5000 studio as R_TRIG in TwinCAT. Or adding an edge detection to a contact in ladder logic with the 'P' symbol.

Reply
ehixenbaugh
(@ehixenbaugh)
Joined: 2 years ago

Trusted Member
Posts: 33

@twincontrols Ok, Thanks! This actually makes more sense to me in TwinCAT then in Studio 5000 because usually when I am one-shotting in a rung, it is for one particular bit. I don't like seeing in someone's code when they have more than one input and there is a one-shot that succeeds those inputs.

twincat tgglbutton corrected
Reply
Posts: 8
(@time2learn)
Active Member
Joined: 2 years ago

Great idea on the forum topic! This seemed simple at first, but surprisingly took some brain power to work it out.

 

Button

 

Reply
1 Reply
twinControls
Admin
(@twincontrols)
Joined: 2 years ago

Member
Posts: 115

@time2learn Great job at solving it using only one rung! 👍 It does sound simple and easy when you're reading it indeed 😀 It just requires a bit thinking.

Reply
Posts: 30
 Alex
(@alex)
Eminent Member
Joined: 2 years ago

In 3 lines

Reply
5 Replies
 Alex
(@alex)
Joined: 2 years ago

Eminent Member
Posts: 30

My screenshot was not uploaded

Reply
twinControls
Admin
(@twincontrols)
Joined: 2 years ago

Member
Posts: 115

@alex Interesting. Could you try again? 

How to insert a file

Reply
 Alex
(@alex)
Joined: 2 years ago

Eminent Member
Posts: 30
twinControls
Admin
(@twincontrols)
Joined: 2 years ago

Member
Posts: 115

@alex You almost got it right! It seems that your pushbutton doesn't clear itself after you set it TRUE. In the code, you'd need to clear Pushbutton variable also to demonstrate the full simulation experience.

Reply
 Alex
(@alex)
Joined: 2 years ago

Eminent Member
Posts: 30

@twincontrols, sorry missing something.

When Pb is pressed it should be On, when PB is released it should be Off.

Reply
Posts: 17
(@joris)
Eminent Member
Joined: 2 years ago

Without Set Reset

Capture

 

Reply
1 Reply
twinControls
Admin
(@twincontrols)
Joined: 2 years ago

Member
Posts: 115

@joris It is nice seeing a solution in TIA Portal too! 🙂 Nice and clean! Maybe you could solve it using only one rung too!

Reply
Posts: 2
(@flowks)
New Member
Joined: 2 years ago

I like to use XOR for those use cases. Logically similar to the TIA solution from above, but imho easier to read.

2022 12 12 14 44 07 Screenshot
Reply
Share: