Announcement

Collapse
No announcement yet.

Copying multiple single character's into a single data register (FIFO?)

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


  • Copying multiple single character's into a single data register (FIFO?)

    Hey guys,

    I have a scenario where I need to fill a data register with characters, likely alpha numeric.

    Lets say I have 4 momentary push buttons, button 1 has a value of "a", button 2 has a value of "b" and so on.

    I need to copy those button presses to a register that will contain up to 8 characters. So if button 1 is pressed, then 2, then 1, then 2, 3, 4, 3, 2, the register would contain "ABABCDCB". If button 4 was then pressed again, the first "A" would get pushed out and the resulting data would be "BABCDCBD". Ultimately there will be a given preset value and I'll use compare to compare the preset "combination" to the characters flowing in to the register to complete the rung.

    I'm using Productivity 2000 hardware and there is a FIFO instruction, but I'm having a difficult time wrapping my head around some of the terminology of peek, push, pop, etc. The instruction seems overly complex for my needs. Ideally this would be something I could convert to Click as well.

    I would love to hear some thoughts. I've been grinding on this off and on all day and I can't find a suitable way.


  • #2
    Load the button pushes into the first element of an array and then use the Shift rotate array instruction to shift them through the array.

    Comment



    • #3
      Originally posted by techme View Post
      Load the button pushes into the first element of an array and then use the Shift rotate array instruction to shift them through the array.
      I understand what you're saying, but I have zero experience with arrays (more so, I don't understand the logic of arrays. I'm pretty much self taught and have never came across a need to use them).

      I've gone through the help file for the SRA instruction I simply don't know what I'm looking at.

      Does anyone have any sample logic? AD doesn't have anything in the example programs about arrays.

      Comment



      • #4
        There is no 'logic' to arrays. An array is simply a data storage unit.
        The data must be of the same datatype. The 'construction' of an array in a PAC can be either ONE or TWO dimensions.
        Think of the 'dimensions' as ROWS and COLUMNS - like a spreadsheet.
        You can access each element of an array by specifying the ROW/COLUMN of the particular element (think worksheet CELL.)
        In a single dimension array, you can only specify the COLUMN in parentheses -- arrayname(COLUMNNUMBER).
        In a two-dimension array you specify ROW in parentheses and COLUMN in parentheses-- arrayname(ROWNUMBER),(COLUMNNUMBER).

        Code:
        .Assume that the arrays are named (1D) ArrayA and (2D) ArrayB
        .
        .      One dimension array
        .   col  1    2    3    4    5
        .     +----+----+----+----+----+
        .     | 32 | 15 | 19 | 5  |  0 |
        .     +----+----+----+----+----+
        . ArrayA(1) value = 32
        . ArrayA(1) value = 15
        . ArrayA(1) value = 19
        . ArrayA(1) value =  5
        . ArrayA(1) value =  0
        .
        .      Two dimension array
        .   col  1    2    3    4    5    6
        . row +----+----+----+----+----+----+
        .  1  |  5 |  2 |  8 |  1 | 10 | 99 |
        .     +----+----+----+----+----+----+
        .  2  | 123|  9 | 55 | 43 | 23 | 88 | 
        .     +----+----+----+----+----+----+
        .  3  | 11 | 21 | 22 | 32 | 43 | 33 | 
        .     +----+----+----+----+----+----+
        . ArrayB(1),(1) =   5
        . ArrayB(1),(2) =   2
        . ArrayB(1),(3) =   8
        . ArrayB(1),(4) =   1
        . ArrayB(1),(5) =  10
        . ArrayB(1),(6) =  99
        .
        . ArrayB(2),(1) = 123
        . ArrayB(2),(2) =   9
        . ArrayB(2),(3) =  55
        . ArrayB(2),(4) =  43
        . ArrayB(2),(5) =  23
        . ArrayB(2),(6) =  88
        .
        . ArrayB(3),(1) =  11
        . ArrayB(3),(2) =  21
        . ArrayB(3),(3) =  22
        . ArrayB(3),(4) =  32
        . ArrayB(3),(5) =  43
        . ArrayB(3),(6) =  33
        .
        .
        In the PAC, the array construction allows several instructions to work iteratively over the array (Copy Array, Fill Array, and Shift/Rotate Array) and allows another instruction to make specific analyses of the contents of the array (Array Statisics.)

        In my understanding of techme's post:
        After a clear/reset or initialization of your 'game' (I assume that this is another 'breakout/escape room' game) count the total number presses of the four buttons.
        For each COUNT (1 - 8) of the buttons presses, use this number as your INDEX into the array, and copy the alpha character/numeric into that location.
        When the total button press COUNT is between 9 and 16, use the button press as a trigger to shift the alpha character(value) back out of the array. Use the FIRST element of the array as the OUTGOING(outflow) character(value) position.
        You will probably need to provide an Inflow value also.
        When the total button press count is greater than 16, do whatever your game requires -- ignore or reset the whole thing.

        However ShiftRotate Array DOES NOT support shifting STRING arrays. So, probably need to use numerics and represent them as A B C D in the player presentation!
        You can convert numerics to string, but the numeric must be in an array! - See the CPC instruction.
        Last edited by kewakl; 05-20-2017, 07:01 PM.

        Comment



        • #5
          Originally posted by kewakl View Post
          There is no 'logic' to arrays. An array is simply a data storage unit.
          The data must be of the same datatype. The 'construction' of an array in a PAC can be either ONE or TWO dimensions.
          Think of the 'dimensions' as ROWS and COLUMNS - like a spreadsheet.
          You can access each element of an array by specifying the ROW/COLUMN of the particular element (think worksheet CELL.)
          In a single dimension array, you can only specify the COLUMN in parentheses -- arrayname(COLUMNNUMBER).
          In a two-dimension array you specify ROW in parentheses and COLUMN in parentheses-- arrayname(ROWNUMBER),(COLUMNNUMBER).

          Code:
          .Assume that the arrays are named (1D) ArrayA and (2D) ArrayB
          .
          . One dimension array
          . col 1 2 3 4 5
          . +----+----+----+----+----+
          . | 32 | 15 | 19 | 5 | 0 |
          . +----+----+----+----+----+
          . ArrayA(1) value = 32
          . ArrayA(1) value = 15
          . ArrayA(1) value = 19
          . ArrayA(1) value = 5
          . ArrayA(1) value = 0
          .
          . Two dimension array
          . col 1 2 3 4 5 6
          . row +----+----+----+----+----+----+
          . 1 | 5 | 2 | 8 | 1 | 10 | 99 |
          . +----+----+----+----+----+----+
          . 2 | 123| 9 | 55 | 43 | 23 | 88 | 
          . +----+----+----+----+----+----+
          . 3 | 11 | 21 | 22 | 32 | 43 | 33 | 
          . +----+----+----+----+----+----+
          . ArrayB(1),(1) = 5
          . ArrayB(1),(2) = 2
          . ArrayB(1),(3) = 8
          . ArrayB(1),(4) = 1
          . ArrayB(1),(5) = 10
          . ArrayB(1),(6) = 99
          .
          . ArrayB(2),(1) = 123
          . ArrayB(2),(2) = 9
          . ArrayB(2),(3) = 55
          . ArrayB(2),(4) = 43
          . ArrayB(2),(5) = 23
          . ArrayB(2),(6) = 88
          .
          . ArrayB(3),(1) = 11
          . ArrayB(3),(2) = 21
          . ArrayB(3),(3) = 22
          . ArrayB(3),(4) = 32
          . ArrayB(3),(5) = 43
          . ArrayB(3),(6) = 33
          .
          .
          In the PAC, the array construction allows several instructions to work iteratively over the array (Copy Array, Fill Array, and Shift/Rotate Array) and allows another instruction to make specific analyses of the contents of the array (Array Statisics.)
          Thank you for the description of an array. I finally "got it" with your post. I was absolutely over thinking it and seeing it visually like that really helped. It also didn't help that when the SRA function created the array on the fly for me, it created it as a 1x1 array (I was not aware of this and it kept throwing error messages).

          I cannot believe I've been doing things without array's for so long. I have 40 rungs of copy and math instructions in all of my programs that could have been handled in one rung of SRA and STA. I guess the only silver lining is the way I have been doing it is "backwards compatible" with Click's since it's just copying and moving data with basic instructions.

          Originally posted by kewakl View Post
          In my understanding of techme's post:
          After a clear/reset or initialization of your 'game' (I assume that this is another 'breakout/escape room' game) count the total number presses of the four buttons.
          For each COUNT (1 - 8) of the buttons presses, use this number as your INDEX into the array, and copy the alpha character/numeric into that location.
          When the total button press COUNT is between 9 and 16, use the button press as a trigger to shift the alpha character(value) back out of the array. Use the FIRST element of the array as the OUTGOING(outflow) character(value) position.
          You will probably need to provide an Inflow value also.
          When the total button press count is greater than 16, do whatever your game requires -- ignore or reset the whole thing.

          However ShiftRotate Array DOES NOT support shifting STRING arrays. So, probably need to use numerics and represent them as A B C D in the player presentation!
          You can convert numerics to string, but the numeric must be in an array! - See the CPC instruction.

          You have a good memory, yes this is for a escape room.

          I think my needs are a little easier than what you're thinking. I've attached a semi-working program now that I have a understanding of how arrays work.

          I have my buttons shifting a 2 digit integer into the array. That part works great. I have a copy array instruction setup for copying the current "combination" into a "preset" combination array. That part works.

          At this point I'm stumped at how to compare the two arrays, or get the data out of the array into some other form that I can compare, which is all I need. Ultimately if "ARRAY_Button_Panel_Combo_Entered" equals "ARRAY_Button_Panel_Preset_Combo", it's a win. There is no reset function based on buttons pressed or anything. If the player pressed the "1" button 100 times, then finally enters 1, 2, 3, 4, 5, 6, 7, 8, it wins.

          Initially I wanted to use characters as I have a similar program already done, but it doesn't seem to work with two digit integers, so I can't use more than 10 buttons. I've attached a slimmed down version of that program as well (without all of the reprogram and "game specific" bits in it. I would love to get a working version of that program going that can use more than 10 inputs.

          Attached Files

          Comment



          • #6
            When I get time, I'll attempt to address the second part of your last post -- unless someone else can help.

            About
            I cannot believe I've been doing things without array's for so long. I have 40 rungs of copy and math instructions in all of my programs that could have been handled in one rung of SRA and STA. I guess the only silver lining is the way I have been doing it is "backwards compatible" with Click's since it's just copying and moving data with basic instructions.
            --Backwards compatible and easy to remember - tomorrow!

            CLICK doesn't support arrays, but arrays can be 'emulated.' I have a post in this thread that may help you with that.

            Comment



            • #7
              Compare two arrays:
              There is no native instruction to do so.
              The arrays must be the same DATATYPE and considerations must be made to ensure that you only iterate through the valid SIZE restraint of the smaller array (if they are NOT the same size)
              (However a SINGLE 'D' of a 2D array can be compared to a 1D array)
              This method can be used to compare sections of arrays, just add (VALID) offsets. -- maybe another ascii demo -- later

              compare two 1D arrays
              Code:
              .
              .
              .          Trig                    
              .-----------]^[---------------------------------+ CPD
              .                                               | 0         Compare_FAIL
              .                                               | 1         Compare_PASS
              .                                               |
              .                                               +-----------------------------
              .
              .
              .          Trig                                 |
              .-----------]^[---------------------------------+ For   Number of Loops [ loopMax ]     Current Loop Count [ loopCt ]
              .                                               |
              .                                               +-----------------------------
              .
              .
              .   Compare 1D array -- (element by element) to another 1D array
              .   If indexed element in first array IS NOT EQUAL to the corresponding
              .   element in the second array, SET CompareFAIL and break out of loop.
              .   You could save the loopCt value to know the location of the first discrepancy.
              .   Also, you could remove the BREAK and continue, if you need to.
              .   i.e. count number of discrepancies, save list of all discrepancies...
              .
              .  a1D_1(loopCt)  a1D_2(loopCt)          Compare_FAIL        
              .--------------]<>[------------------+------------(S)
              .                                    |
              .                                    |
              .                                    |                  
              .                                    +----------+ Break
              .                                               |
              .                                               +---------
              .
              .
              .         loopCt  loopMax   Compare_FAIL      Compare_PASS
              .--------------]=>[-------------]/[----------------(S)
              .
              .
              .-----------------------------------------------+ NEXT
              .                                               |
              .                                               +-----------------------------


              compare one 1D array to one 2D array. - same control structure, just the comparison rung, and the inclusion of a tag 'DIM' is different
              DIM is the dimension index, the row of the 2D array that you wish to compare to the 1D array
              Code:
              .
              .  a1D_1(loopCt)  a2D_2(DIM)),(loopCt)          Compare_FAIL        
              .--------------]<>[------------------+------------(S)
              .                                    |
              .                                    |
              .                                    |                  
              .                                    +----------+ Break
              .                                               |
              .                                               +---------
              Last edited by kewakl; 05-25-2017, 05:48 AM.

              Comment



              • #8
                Thank you for the description of an array. I finally "got it" with your post. I was absolutely over thinking it and seeing it visually like that really helped.
                Thank you.
                Graphically representing structures helps a lot.
                EVERYTHING is an array. A single item can be described as a single dimension array of ONE item.

                A loaf of sliced bread is a 1 X 20 array
                A carton of a dozen eggs is a 2 X 6 array
                ------------------And these are just rectangular arrays.

                It also didn't help that when the SRA function created the array on the fly for me, it created it as a 1x1 array (I was not aware of this and it kept throwing error messages).
                ?
                The software doesn't arbitrarily 'create' arrays. When you are accepting your instruction (SRA) as 'finished' the SW will prompt you to create any tags for any 'names' in fields that are not reconciled to a tag in the tag database. You can MODIFY the tags as you need (according to size and datatype of the instruction's field tag-compatibility.)

                Initially I wanted to use characters as I have a similar program already done, but it doesn't seem to work with two digit integers, so I can't use more than 10 buttons. I've attached a slimmed down version of that program as well (without all of the reprogram and "game specific" bits in it. I would love to get a working version of that program going that can use more than 10 inputs.
                What is the restriction for 10 buttons?
                Last edited by kewakl; 05-25-2017, 05:59 AM.

                Comment



                • #9
                  compare portions of two 1D arrays
                  Code:
                  .
                  .
                  .          Trig                    
                  .-----------]^[---------------------------------+ CPD
                  .                                               | 0         Compare_FAIL
                  .                                               | 1         Compare_PASS
                  .                                               | 10        arrRangeOffset
                  .                                               +-----------------------------
                  .
                  .
                  .          Trig                                 |
                  .-----------]^[---------------------------------+ For   Number of Loops [ loopMax ]     Current Loop Count [ loopCt ]
                  .                                               |
                  .                                               +-----------------------------
                  .
                  . arrRangeOffset 'off-sets' the pointed-to array index 10 places up the array
                  . so:
                  . the For Loop loops through 1 to loopMax,
                  . the comparison actually compares 11 to (loopMax + 10)
                  . loopMax + 10 needs to be within the bounds of the arrays to work properly.
                  . you can MATH the lower and upper bounds of the array pointers so that you can compare as little or as much as required.
                  .
                  .                                               |
                  .-----------------------------------------------+ Math            Result [ arrPtr ]
                  .                                               |
                  .                                               | loopCt + arrRangeOffset
                  THANK YOU FORUM SOFTWARE FOR ARBITRARILY INSERTING CODE TAGS INTO MY CODE! GOTTA LOVE IT! I've deleted them three times and they magically reappear.
                  I think that I shall make an offering to the Goddess FRIGG. Maybe she can get this forum software fixed! What the Frigg?
                  Code:
                  .                                               |
                  .                                               +-----------------------------
                  .
                  .
                  .
                  .
                  .  a1D_1(arrPtr)   a1D_2(arrPtr)            Compare_FAIL        
                  .--------------]<>[------------------+------------(S)
                  .                                    |
                  .                                    |
                  .                                    |                  
                  .                                    +----------+ Break
                  .                                               |
                  .                                               +---------
                  .
                  .
                  .         loopCt  loopMax   Compare_FAIL      Compare_PASS
                  .--------------]=>[-------------]/[----------------(S)
                  .
                  .
                  .-----------------------------------------------+ NEXT
                  .                                               |
                  .                                               +-----------------------------
                  Last edited by kewakl; 05-25-2017, 06:21 AM.

                  Comment



                  • #10
                    If button 4 was then pressed again, the first "A" would get pushed out and the resulting data would be "BABCDCBD".
                    In your posted PAC program, rung 9, add a limit (compare) contact this limit would be the button press count lessthan/equalto 8.

                    Then add another(a modded copy of rung 9 should work) SRA rung, that when the count is greaterthan 8, start shifting LEFT RIGHT to get the values back out, in the order in which they were entered.
                    Look for this value to be in DATA_Button_Panel_Outflow
                    Last edited by kewakl; 05-25-2017, 09:18 AM.

                    Comment



                    • #11

                      Code:
                       This isn't code, but I need the formatting!
                      Tags:
                      SysID         Name           Range      Value      Retentive      Description
                      (TYPE)                      (ARRAY)
                      AR1US16       BTN_VAL        1-32        any           Y      Values to put into button press history
                      AR1S16        NUMS           1-32        none          N      Your button press history
                      AR1C          BTNS           1-32        none          N      Your button press states
                      
                      C             OverFlo                                  N      .
                      C             RST                                      N      Reset the whole procedure/history
                      S16           InFlo                                    N      .
                      S16           OutFlo                                   N      .
                      S16           MaxBTNS                     4            Y      Number of buttons to monitor
                      S16           MaxBTN_Press                8            Y      Number of BUTTON PRESSES
                      
                      S32           BTN_PRESS_bitfield                       N      Numeric (PACKED) bitfield of
                                                                                    any/all currently pressed buttons
                      S32           BTN_PRESSED                              N      Numeric position of FIRST found button press
                      S32           BTN_PRESS_VAL                            N      Numeric (displayed) value of found button
                      S32           BTN_PRESS_CT                             N      Count of how many buttons have been pressed
                      Code:
                      .                                                  |   Pack Bits
                      .--------------------------------------------------+ PKB     BTN_PRESS_bitfield
                      .                                                  |
                      .                                                  | Bit#    Input
                      .                                                  |  1      BTNS(1)
                      .                                                  |  1      BTNS(2)
                      .                                                  |  ~      ~
                      .                                                  |  31     BTNS(31)
                      .                                                  |  32     BTNS(32)
                      .                                                  +------------------------
                      .
                      .  BTN_PRESS_bitfield        0                     | For Loop
                      .-----------------------]>[------------------------+ Number of Loops [ MaxButtons] Current Loop Count [loopCt]
                      .                                                  |
                      .                                                  +------------------------
                      .
                      .  BTNS(loopCt)                                  BTNS(loopCt)
                      .----------] [------+------------------------------(RST)
                      .                   |
                      .                   |                              |
                      .                   +------------------------------+ MATH  [ BTN_PRESS_CT ]
                      .                   |                              | BTN_PRESS_CT + 1
                      .                   |                              +-----------------------
                      .                   |
                      .                   |
                      .                   |BTN_PRESS_CT  8               |
                      .                   +---------]<=[-----+-----------+ CPD
                      .                   |                  |           | BTN_VAL(BTN_PRESSED)       InFlo
                      .                   |                  |           +-----------------------
                      .                   |                  |
                      BREAK FOR THE NORSE GODDESS
                      Code:
                      .                   |                  |
                      .                   |                  |           |
                      .                   |                  +-----------+SRA
                      .                   |                              | 1D Array [ NUMS ]    Overflow [ OverFlo ]
                      .                   |                              | Start Index [ 1 ]    Outflow  [ OutFlo  ]
                      .                   |                              | End Index   [ MaxBTN_Press ]
                      .                   |                              | Inflow      [ InFlo ]
                      .                   |                              | Shift Array Elements Left
                      .                   |                              +-----------------------
                      .                   |
                      .                   |
                      .                   |BTN_PRESS_CT  8               |
                      .                   +---------]>[------+-----------+ CPD
                      .                   |                  |           | 0                InFlo
                      .                   |                  |           +-----------------------
                      .                   |                  |
                      .                   |                  |
                      .                   |                  |           |
                      .                   |                  +-----------+SRA
                      .                   |                              | 1D Array [ NUMS ]    Overflow [ OverFlo ]
                      .                   |                              | Start Index [ 1 ]    Outflow  [ OutFlo  ]
                      .                   |                              | End Index   [ MaxBTN_Press ]
                      .                   |                              | Inflow      [ InFlo ]
                      .                   |                              | Shift Array Elements Right
                      .                   |                              +-----------------------
                      .                   |
                      .                   |                              |
                      .                   +------------------------------+ BREAK
                      .                                                  |
                      .                                                  +-----------------------
                      .
                      .
                      .                                                  |
                      .--------------------------------------------------+ Next
                      .                                                  |
                      .                                                  +------------------------
                      .
                      .                                                  |
                      .--------------------------------------------------+ FLA
                      .                                                  | Input [ 0 ]   Array [ BTNS ]
                      .                                                  |      Start Column   [  1   ]
                      .                                                  |      End Column     [ 32   ]
                      .                                                  |
                      .                                                  +------------------------
                      .                                                   
                      .            RST                                   |    
                      .----+-------] [-------+------+--------------------+ CPD
                      .    |                 |      |                    | 0      BTN_PRESS_bitfield
                      .    |    FirstScan    |      |                    |        BTN_PRESS_CT
                      .    +-------] [-------+      |                    |        BTN_PRESS_VAL
                      .                             |                    |        BTN_PRESSED
                      .                             |                    |        InFlo
                      .                             |                    |        OutFlo
                      .                             |                    +------------------------
                      .                             |                     
                      .                             |                    |
                      .                             +--------------------+ FLA
                      .                             |                    | Input [ 0 ]   Array [ NUMS ]
                      .                             |                    |      Start Column   [  1   ]
                      .                             |                    |      End Column     [ 32   ]
                      .                             |                    |
                      .                             |                    +------------------------
                      .                             | 
                      .                             |                    |
                      .                             +--------------------+ FLA
                      .                             |                    | Input [ 0 ]   Array [ BTNS ]
                      .                             |                    |      Start Column   [  1   ]
                      .                             |                    |      End Column     [ 32   ]
                      .                             |                    |
                      .                             |                    +------------------------
                      .                             |                   
                      .                             |                     RST
                      .                             +--------------------(RST)                   
                      If I have left something out, mixed some text, let me know.
                      Last edited by kewakl; 05-25-2017, 09:32 AM.

                      Comment

                      Working...
                      X