Sign in to follow this  
Followers 0
wjdeas

Need to program a button to randomly choose 5 out of 7 outputs

3 posts in this topic

I'm new to writing programs, especially in Omron so any help will be greatly appreciated. I mainly just use PLC's for troubleshooting at work and that's usually S7. Now I'm using my spare time to learn a little programming. I figure the more I know the better off I'll be. Anyway, the problem I'm faced with is trying to get one button ("shuffle") to randomly choose 5 out of 7 outputs. In addition to this I need the order of the 5 outputs to be random as well. This is going to be used for shooting targets. I'll have seven targets and I need to randomly choose five of them to pop up in a random order. Then press the shuffle and five more are randomly chosen and pop up in a random order... I've looked at a couple of random number generators on this site but I'm not sure how to transfer that to chosing an output. Any thoughts.

Share this post


Link to post
Share on other sites
You'll need to understand the relationship between Binary, Hexadecimal, Decimal numbers. You'll need a Decimal number between 0 and 127 for 7 outputs. 127 Dec = 7F Hex = 1111111 Bin. Use your Windows calculator in Scientific mode to play with other values. Your Binary result will be your outputs with Bit 0 to the far right >. Let's say you choose memory location W3 to store your result. You would access your bits using the addresses (Right Side) W3.00, W3.01, W3.02...... W3.06 (Left Side). Now the beauty of using Omron for this task is, they have an instruction that will count the bits for you! Have a look at the BCNT(067) instruction. Edited by IO_Rack

Share this post


Link to post
Share on other sites
Very interesting task! Here you are. For better understanding, the program does not use indirect addressing and value decoding into bits. EDIT NOTE: On Oct.13, the attached file has been modified to correct a minor error. Targets Random 5 of 7.cxp Edited by Sergei Troizky

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0