Shop OBEX P1 Docs P2 Docs Learn Events
Best way to split quantities — Parallax Forums

Best way to split quantities

docwisdomdocwisdom Posts: 28
edited 2009-10-08 19:40 in BASIC Stamp
I have a serial input coming from a POS system with a quantity. I want to divide the quantity by the 6 output machines so each output machine maintains even quantity and one doesnt run out prematurely. Then have the remainder come out of the next unused output machine.

for example

input quantity 13
machine output
1: 3
2: 2
3: 2
4: 2
5: 2
6: 2

input quantity 13
machine output
1: 2
2: 3
3: 2
4: 2
5: 2
6: 2

input quantity 13
machine output
1: 2
2: 2
3: 3
4: 2
5: 2
6: 2

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-08 18:35
    You probably would want to keep the counts in an array with 6 elements. You'd have a subroutine that would supply the number of the next machine to use. The subroutine would go through the array and save the number of the first machine with the lowest output count (and what that count was ... to compare against the other machines). After going through all the output machines, you'd have the number of the next machine to use. If a machine fails, you'd set its count to the maximum possible (either 255 or 65535) so that machine is never chosen. When the POS system reports an increased value, you'd increment the count for the machine that was used and select a new machine to use.
  • docwisdomdocwisdom Posts: 28
    edited 2009-10-08 19:40
    Thanks!

    I took that an put it in a for loop and came up with this...works great!

    fk_rolls = QTY

    fk_hopr(0) = $00
    fk_hopr(1) = $00
    fk_hopr(2) = $00
    fk_hopr(3) = $00
    fk_hopr(4) = $00
    fk_hopr(5) = $00
    FOR q = 1 TO fk_rolls
    fk_hopr(i) = fk_hopr(i)+1
    i = i+1
    IF i = 6 THEN i = 0
    NEXT
    DEBUG ? fk_hopr(0)
    DEBUG ? fk_hopr(1)
    DEBUG ? fk_hopr(2)
    DEBUG ? fk_hopr(3)
    DEBUG ? fk_hopr(4)
    DEBUG ? fk_hopr(5)
Sign In or Register to comment.