November 22, 2024, 03:34:17 PM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Prop-1 controlling 3 DC-16's

Started by gadget-evilusions, September 16, 2010, 07:57:50 AM

Previous topic - Next topic

gadget-evilusions

I am using a prop-1 to control 3 dc-16's serially. I am making a sort of lottery style game. I have 40 lights hooked up to the first 40 outputs of the dc-16's. Is there a way to randomly select and turn on 1 of those 40 outputs after seeing a contact closure on p6 of the prop-1?
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

Give this a try (I didn't hook it up but feel very confident it will do what you want).

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400


' -----[ Variables ]-------------------------------------------------------

SYMBOL  timer           = B2
SYMBOL  ball            = B3
SYMBOL  addr            = B4
SYMBOL  idx             = B5
SYMBOL  last            = B6

SYMBOL  lottery         = W5


' -----[ Initialization ]--------------------------------------------------

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000000                              ' no local outputs

  PAUSE 100                                     ' let DC-16s power up
  GOSUB Clear_DC16s                             ' clear all

  ball = 99


' -----[ Program Code ]----------------------------------------------------

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery                                ' randomize
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input


Show_Ball:
  RANDOM lottery                                ' re-stir
  ball = lottery // 40                          ' ball = 0 to 39
  IF ball = last THEN Show_Ball                 ' prevent repeat
    last = ball                                 ' save for next time

  addr = ball / 16                              ' calc address (0 to 2)
  idx  = ball // 16 + 1                         ' calc channel (1 to 16)

  GOSUB Clear_DC16s
  SEROUT Sio, Baud, ("!DC16", addr, "P", idx, IsOn)
  PAUSE 3000

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

Clear_DC16s:
  SEROUT Sio, Baud, ("!DC16", $FF, "X")
  '
  ' alternate SEROUT code if above does not work with your DC16s (pre 1.5)
  '
  ' SEROUT Sio, Baud, ("!DC16", %00, "X")
  ' SEROUT Sio, Baud, ("!DC16", %01, "X")
  ' SEROUT Sio, Baud, ("!DC16", %10, "X")
  '
  RETURN

' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

Thank you Jon. I am ordering the DC-16's right now so I imagine they are 1.5 version.

Just so i know, how does $FF work?
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

$FF (255) is the global address which means all devices respond to this address (as long as the command does not require the unit to send a serial message back).  Order you DC16s soon, we're almost out and that board will be replaced by a cool new product.
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

I am revisiting this game and wanting to modify it. It has worked great, but I would like to "rig" the game a little.

Is there a way to make it bias to a certain range of values? We want to make, for example, 1 thru 10, our bigger prizes, and have them come up less often than 11-40. So we would want it to light up big prize only once out of 20 cycles, and light up one of the 11-40 smaller prizes the rest of the time.

Thank you for any help.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

Give this version a try:

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated... 23 APR 2012
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400


' -----[ Variables ]-------------------------------------------------------

SYMBOL  timer           = B2
SYMBOL  ball            = B3
SYMBOL  addr            = B4
SYMBOL  idx             = B5
SYMBOL  last            = B6
SYMBOL  cycles          = B7

SYMBOL  lottery         = W5


' -----[ Initialization ]--------------------------------------------------

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000000                              ' no local outputs

  PAUSE 100                                     ' let DC-16s power up
  GOSUB Clear_DC16s                             ' clear all

  ball = 99


' -----[ Program Code ]----------------------------------------------------

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery                                ' randomize
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input


Show_Ball:
  RANDOM lottery                                ' re-stir
  ball = lottery // 40                          ' ball = 0 to 39
  IF ball = last THEN Show_Ball                 ' prevent repeat
    last = ball                                 ' save for next time

  IF ball > 10 THEN Calc_Address                ' low prize any time
  IF cycles >= 20 THEN Calc_Address             ' if enough cycles, go
    GOTO Show_Ball                              '  else try again

Calc_Address:
  addr = ball / 16                              ' calc address (0 to 2)
  idx  = ball // 16 + 1                         ' calc channel (1 to 16)

  GOSUB Clear_DC16s
  SEROUT Sio, Baud, ("!DC16", addr, "P", idx, IsOn)
  PAUSE 3000

Update_Cycles:
  cycles = cycles + 1                           ' update for low prize
  IF ball > 10 THEN Main
    cycles = 0                                  ' reset for high prize
    GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

Clear_DC16s:
  SEROUT Sio, Baud, ("!DC16", $FF, "X")
  '
  ' alternate SEROUT code if above does not work with your DC16s (pre 1.5)
  '
  ' SEROUT Sio, Baud, ("!DC16", %00, "X")
  ' SEROUT Sio, Baud, ("!DC16", %01, "X")
  ' SEROUT Sio, Baud, ("!DC16", %10, "X")
  '
  RETURN

' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office