Announcement

Collapse
No announcement yet.

Warning Newbie - Input Sequence Program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts


  • Warning Newbie - Input Sequence Program

    First, I am loving the Productivity 1000 and all the training videos. I am a long time PLC user, but very new to PLC programming. I have ancient programming knowledge, so that helps from a logic standpoint.

    Some background. I have an Escape Room that we create puzzles. I want to use a PLC for my next build. So far I have been able to replicate everything I need except a button press puzzle.

    I have 4 buttons. Red / Blue / Green / Yellow. I want 5 momentary button presses in a certain order and within 15 seconds. So Red, Red, Blue, Green, Yellow. After 5 button presses, there will be one of two outcomes. A pass scenario, or a fail scenario. It should also do the fail scenario if it times out from the first button press. So lets assume the output is Pass light and Fail Light (I can do the rest from there). Anyone willing to help point a newbie in the right direction to start?


  • #2
    Sounds like a fun project
    Here is some code that may get you started
    Did not have a chance to test, so you may have to edit it some

    Put the correct color number in rows of an array
    Set the index value to zero

    When a button is pressed, increment the index value and compare to the current array row selected for pass/fail
    If fail, reset index to zero
    If pass at level 5, then win

    This assumes only one button can be pressed at a time


    Click image for larger version

Name:	ColorGuess1.png
Views:	106
Size:	49.0 KB
ID:	126512

    Comment



    • #3
      Thank you! This should get me pointed in the right direction for sure.

      Comment



      • #4
        Glad to help.

        Comment



        • #5
          As another option to use, I believe this one should work too:

          Click image for larger version

Name:	ButtonCombo.png
Views:	96
Size:	92.5 KB
ID:	126547


          functionality:

          Each button is assigned a different number.
          Each time a button is pressed it loads that value into a register/array and pushes all values that were in array to the side.
          When all 5 columns have a value in it (from 5 button presses), then the array gets all numbers reset back to 0 unless the value of each column had the specific number combination needed to pass. If the number check did not pass, a fail condition is set to let the players know that things have reset.
          At the first button press of any button it starts a timer, if the timer elapses then the array gets reset back to 0 and a fail condition starts so the players are notified that things have reset.
          during a fail event, the fail status stays on for a half second. You can change this behavior as it applies to your use.
          During a pass or fail, the array is reset back to 0 so it is ready to use again after you have cleared pass or fail modes once players have left the room.

          My method above will not reset the array upon the first wrong button press, it will only reset after 5 presses and the combination has failed or at 15 seconds. This may be bad if you want the players to be able to eventually deduce the combination through trial and error (instead of following clues) of hitting things and having a fail condition come up upon the very first wrong press.




          If you do want players to deduce the combination from trial and error as they attempt different combinations then you can include this section of code. It will reset and do a fail mode after the first wrong button press in the combination:

          Click image for larger version

Name:	ButtonCombo_ResetAfterFirstWrong.png
Views:	91
Size:	46.7 KB
ID:	126546
          Last edited by MikeN; 11-12-2019, 05:40 PM.

          Comment



          • #6
            Originally posted by MikeN View Post
            I believe this should work as well as a second option:

            {"alt":"Click image for larger version Name:\tButtonCombo.png Views:\t0 Size:\t67.2 KB ID:\t126528","data-align":"none","data-attachmentid":"126528","data-size":"thumb"}


            My method will not reset the array upon the first wrong button press, it will only reset after 5 presses and the combination has failed or at 15 seconds. This may be bad if you want the players to be able to eventually deduce the combination through trial and error (instead of following clues) of hitting things and having a fail condition come up upon the very first wrong press.
            This is my goal. For this particular puzzle, I want them to find the code from some written clues, not process of elimination. Thank you!

            Comment



            • #7
              I felt like doing an exercise. Here's an approach that assigns a unique numeric value to each button, and calculates the sum. Quite a bit shorter code.
              Attached Files

              Comment

              Working...
              X