November 23, 2024, 01:36:40 AM

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.


adding random

Started by lazerlite, October 04, 2008, 03:35:29 PM

Previous topic - Next topic

lazerlite

October 04, 2008, 03:35:29 PM Last Edit: October 04, 2008, 03:39:02 PM by lazerlite
Hey John..I have done a little research on adding a random in my program, but I dont quite understand it yet . What I am wanting to do, is, where my program has a pause, I want it to have a different pause, causing it to have a random pause, basically meaning the next four times, it will be different, then start over . The pause starts at 4500, and I can find tweak at 6sec to 1 min., I can fine tune that..I am just trying to find out the actual language on how to do that.  The way I have it set up now,  the AP8 comes on, programs pauses at 4500 and then the red light comes on, and the following plays out.  I just need the pause to pause at a random rate. Pause 5500 the fist time, pause 6500 the second time , pause 7500 the third time and pause 8500 the last and then start over to pause 5500 at the start after the fourth time the push button is pushed. each time then the red light comes on and the programs runs out....Just with a different pause before the the red light comes on  each time  the push button is pushed  and then starts over. Thank you for all of your help.

' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Connections:
' -- replace ULN2803 with ULN2003
' -- connect P7 to RC-4 (serial), RC-4 to AP-8
'    * RC-4 must be first in chain
' -- remove B/R jumper on RC-4 and AP-8
' -- remove A0 & A1 jumpers from RC-4 and AP-8
' -- remove Prop-1 P7 SETUP jumper
' -- move Prop-1 P6 SETUP jumper to UP
' -- connect N.O. switch between P6.R (+5v) and P6.W (input)


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


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

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


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

SYMBOL  Baud            = OT2400

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


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

SYMBOL  relays          = B0
SYMBOL   redLight       =  BIT0                 ' connect to RC-4, K1
SYMBOL   grnLight       =  BIT1
SYMBOL   cylinder       =  BIT2


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

Reset:
  ' reset AP-8 and RC-4 on power-up or reset button
  '
  SEROUT Sio, Baud, ("!!!!!!AP8", 0, "X", "!RC4", 0, "X")
  PAUSE 25

  relays = IsOff                                ' all are off now


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

Main:
  IF Trigger = IsOff THEN Main                  ' wait for trigger

Start_Audio:
  SEROUT Sio, Baud, ("!AP8", 0, "P", 0)         ' play sound 0
  PAUSE 4500

Activate_Lights:
  redLight = IsOn
  GOSUB Refresh_RC4
  PAUSE 250

  redLight = IsOff
  grnLight = IsOn
  cylinder = IsOn
  GOSUB Refresh_RC4
  PAUSE 500

  relays = IsOff
  GOSUB Refresh_RC4                             ' clear relays
  SEROUT Sio, Baud, ("!AP8", 0, "X")            ' stop audio
  PAUSE 25                                      ' let AP-8 reset

  GOTO Main



JonnyMac

I'm a little confused... you use the term "random" which, to me, means different each time and unknown, but then you go on to specify that the first time through the delay is 5500, the second time 6500, etc. -- this is not random.  I have implemented your second suggestion, where is uses delays of 5500, 6500, 7500, and 8500 (then goes back).  You can change the values in the list as you desire.

' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Connections:
' -- replace ULN2803 with ULN2003
' -- connect P7 to RC-4 (serial), RC-4 to AP-8
'    * RC-4 must be first in chain
' -- remove B/R jumper on RC-4 and AP-8
' -- remove A0 & A1 jumpers from RC-4 and AP-8
' -- remove Prop-1 P7 SETUP jumper
' -- move Prop-1 P6 SETUP jumper to UP
' -- connect N.O. switch between P6.R (+5v) and P6.W (input)


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


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

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


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

SYMBOL  Baud            = OT2400

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


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

SYMBOL  relays          = B0
SYMBOL   redLight       =  BIT0                 ' connect to RC-4, K1
SYMBOL   grnLight       =  BIT1
SYMBOL   cylinder       =  BIT2

SYMBOL  timer           = B2
SYMBOL  idx             = B3
SYMBOL  delay           = W5


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

Reset:
  ' reset AP-8 and RC-4 on power-up or reset button
  '
  SEROUT Sio, Baud, ("!!!!!!AP8", %00, "X", "!RC4", %00, "X")
  relays = IsOff                                ' all are off now
  idx = 0


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

Main:
  timer = 0                                     ' reset timer

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

  DEBUG "Triggered"


Start_Audio:
  SEROUT Sio, Baud, ("!AP8", %00, "P", 0)       ' play segment 0

Set_Delay:
  LOOKUP idx, (5500, 6500, 7500, 8500), delay
  PAUSE delay
  idx = idx + 1 // 4                            ' keep 0 to 3

Activate_Lights:
  redLight = IsOn
  GOSUB Set_RC4
  PAUSE 250

  redLight = IsOff
  grnLight = IsOn
  cylinder = IsOn
  GOSUB Set_RC4
  PAUSE 500

  relays = IsOff
  GOSUB Set_RC4                                 ' clear relays
  SEROUT Sio, Baud, ("!AP8", 0, "X")            ' stop audio
  PAUSE 25                                      ' let AP-8 reset

  GOTO Main

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

Set_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN
Jon McPhalen
EFX-TEK Hollywood Office

lazerlite

Sorry..that was confusing how I put it..IS there a way so that it will randomly select the pauses from maybe 5500 one time, then on the next start 6500, and next start 8500 and so on?...I am wanting it to start from a choice of  5500, 6500, 7500 or 8500 in any order...with each new start..Like one time it may come on  6500..and the next start it may come on at 5500..and such..so that one may not know each time when it will start. Hope this helps clarify some of what I am thinking..Thanks for all your help..My ap-8 is running at 4.5 seconds..

JonnyMac

Now I get it: you want to randomly select from that list of times, not index through it sequentially.  Here you go:

' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Connections:
' -- replace ULN2803 with ULN2003
' -- connect P7 to RC-4 (serial), RC-4 to AP-8
'    * RC-4 must be first in chain
' -- remove B/R jumper on RC-4 and AP-8
' -- remove A0 & A1 jumpers from RC-4 and AP-8
' -- remove Prop-1 P7 SETUP jumper
' -- move Prop-1 P6 SETUP jumper to UP
' -- connect N.O. switch between P6.R (+5v) and P6.W (input)


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


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

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


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

SYMBOL  Baud            = OT2400

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


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

SYMBOL  relays          = B0
SYMBOL   redLight       =  BIT0                 ' connect to RC-4, K1
SYMBOL   grnLight       =  BIT1
SYMBOL   cylinder       =  BIT2

SYMBOL  timer           = B2
SYMBOL  idx             = B3
SYMBOL  delay           = W4
SYMBOL  lottery         = W5


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

Reset:
  ' reset AP-8 and RC-4 on power-up or reset button
  '
  SEROUT Sio, Baud, ("!!!!!!AP8", %00, "X", "!RC4", %00, "X")
  relays = IsOff                                ' all are off now
  idx = 0


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

Main:
  timer = 0                                     ' reset timer

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

Start_Audio:
  SEROUT Sio, Baud, ("!AP8", %00, "P", 0)       ' play segment 0

Set_Delay:
  idx = lottery // 4                            ' random, 0 to 3
  LOOKUP idx, (5500, 6500, 7500, 8500), delay
  PAUSE delay

Activate_Lights:
  redLight = IsOn
  GOSUB Set_RC4
  PAUSE 250

  redLight = IsOff
  grnLight = IsOn
  cylinder = IsOn
  GOSUB Set_RC4
  PAUSE 500

  relays = IsOff
  GOSUB Set_RC4                                 ' clear relays
  SEROUT Sio, Baud, ("!AP8", 0, "X")            ' stop audio
  PAUSE 25                                      ' let AP-8 reset

  GOTO Main

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

Set_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN
Jon McPhalen
EFX-TEK Hollywood Office

lazerlite

October 15, 2008, 03:37:42 PM #4 Last Edit: October 15, 2008, 04:25:33 PM by lazerlite
THANKS JON . That is perfect. I Am wondering if I can add another push button so I can run a second program code all written into the same main, using the same prop-1? I have two codes that I want to use in the same project. They both do about the same thing but the second code has the random code you just  helped me with and I added two new ap-8 addresses and it uses two extra lights on the RC-4 card. I have re-modified the first program so the wiring in my project will run both  codes. I have also rewritten the codes so they both work in my project.  I am wanting to combine the two codes and add a second push button to run the second code on the same prop-1.  Is this possible?   P7 IS connected  to RC-4 and my push button is on P6

This is the fist code
   ' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Connections:
' -- replace ULN2803 with ULN2003
' -- connect P7 to RC-4 (serial), RC-4 to AP-8
'    * RC-4 must be first in chain
' -- remove B/R jumper on RC-4 and AP-8
' -- remove A0 & A1 jumpers from RC-4 and AP-8
' -- remove Prop-1 P7 SETUP jumper
' -- move Prop-1 P6 SETUP jumper to UP
' -- connect N.O. switch between P6.R (+5v) and P6.W (input)


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


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

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


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

SYMBOL  Baud            = OT2400

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


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

SYMBOL  relays          = B0
SYMBOL   redLight       =  BIT0                 ' connect to RC-4, K1
SYMBOL   yellowlight1   =  BIT1                 ' connect to RC-4, K2
SYMBOL   yellowlight2   =  BIT2                 ' connect to RC-4, K3
SYMBOL  grnlightncyl    =  BIT3                 ' connect to RC-4, K4

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

Reset:
  ' reset AP-8 and RC-4 on power-up or reset button
  '
  SEROUT Sio, Baud, ("!!!!!!AP8", 0, "X", "!RC4", 0, "X")
  PAUSE 25

  relays = IsOff                                ' all are off now


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

Main:
  IF Trigger = IsOff THEN Main                  ' wait for trigger

Start_Audio:
  SEROUT Sio, Baud, ("!AP8", 0, "P", 0)         ' play sound 0
  PAUSE 4500

Activate_Lights:
  redLight = IsOn
  GOSUB Refresh_RC4
  PAUSE 250

  redLight = IsOff
  yellowlight1 = IsOff
  yellowlight2 = IsOff
  grnlightncyl = IsOn
  GOSUB Refresh_RC4
  PAUSE 500

  relays = IsOff
  GOSUB Refresh_RC4                             ' clear relays
  SEROUT Sio, Baud, ("!AP8", 0, "X")            ' stop audio
  PAUSE 25                                      ' let AP-8 reset

  GOTO Main



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

Refresh_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN

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


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


' -----[ User Data ]-------------------------------------------------------

lazerlite

This is the second code

         ' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Connections:
' -- replace ULN2803 with ULN2003
' -- connect P7 to RC-4 (serial), RC-4 to AP-8
'    * RC-4 must be first in chain
' -- remove B/R jumper on RC-4 and AP-8
' -- remove A0 & A1 jumpers from RC-4 and AP-8
' -- remove Prop-1 P7 SETUP jumper
' -- move Prop-1 P6 SETUP jumper to UP
' -- connect N.O. switch between P6.R (+5v) and P6.W (input)


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


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

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


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

SYMBOL  Baud            = OT2400

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


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

SYMBOL  relays          = B0
SYMBOL   redLight       =  BIT0                 ' connect to RC-4, K1
SYMBOL  yellow1         =  BIT1                 ' connect to RC-4, K2
SYMBOL  yellow2         =  BIT2                 ' connect to RC-4, K3
SYMBOL  greencyl       =  BIT3                  ' connect to RC-4, K4

SYMBOL  timer           = B2
SYMBOL  idx             = B3
SYMBOL  delay           = W4
SYMBOL  lottery         = W5


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

Reset:
  ' reset AP-8 and RC-4 on power-up or reset button
  '
  SEROUT Sio, Baud, ("!!!!!!AP8", %00, "X", "!RC4", %00, "X")
  relays = IsOff                                ' all are off now
  idx = 0


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

Main:
  timer = 0                                     ' reset timer

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

Start_Audio:
  SEROUT Sio, Baud, ("!AP8", %00, "P", 1)       ' play segment 1

Set_Delay:
  idx = lottery // 4                            ' random, 0 to 3
  LOOKUP idx, (8500, 9500, 10000, 11000), delay
  PAUSE delay
  SEROUT sio, Baud, ("!AP8", %00, "P", 2)       ' play segment
  PAUSE 400
Activate_Lights:
  redLight = IsOn
  GOSUB Set_RC4
  PAUSE 250

  redLight = IsOff
  yellow1  =IsOn
  GOSUB Set_RC4
  PAUSE 150
  yellow1  =IsOff
  yellow2  =IsOn
  GOSUB Set_RC4
  PAUSE 150
  yellow2  =IsOff
  greencyl = IsOn
  GOSUB Set_RC4
  PAUSE 500

  relays = IsOff
  GOSUB Set_RC4                                 ' clear relays
  SEROUT Sio, Baud, ("!AP8", 0, "X")            ' stop audio
  PAUSE 25                                      ' let AP-8 reset

  GOTO Main

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

Set_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN

JonnyMac

My preference is that you do not stack different programs into the same thread.  Please, from this point forward a new program means a new thread.

Here's a dual-trigger shell that will let you run two different "shows" within your Prop-1; note that trigger #1 gets checked first and therefore has priority.  Drop in your "show" code and you should be good to go.

' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger2        = PIN6                  ' SETUP = DN
SYMBOL  Trigger1        = PIN5


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


SYMBOL  Baud            = OT2400                ' B/R jumper removed


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

SYMBOL  timer1          = B2
SYMBOL  timer2          = B3


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00011111                              ' set outputs


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

Main:
  timer1 = 0                                    ' reset timers
  timer2 = 0

Check_Triggers:
  PAUSE 5                                       ' loop pad

Check_T1:
  timer1 = timer1 + 5 * Trigger1
  IF timer1 = 100 THEN Show_1

Check_T2:
  timer2 = timer2 + 5 * Trigger2
  IF timer2 = 100 THEN Show_2
    GOTO Check_Triggers


Show_1:

  GOTO Main


Show_2:

  GOTO Main


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


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


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


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


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


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


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

lazerlite

Jon, I think I am missing something. It is saying that my "EEPROM" is full. I will paste what I have managed to throw together, but I am sure it is out of whack.

' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Connections:
' -- replace ULN2803 with ULN2003
' -- connect P7 to RC-4 (serial), RC-4 to AP-8
'    * RC-4 must be first in chain
' -- remove B/R jumper on RC-4 and AP-8
' -- remove A0 & A1 jumpers from RC-4 and AP-8
' -- remove Prop-1 P7 SETUP jumper
' -- move Prop-1 P6 SETUP jumper to UP
' -- connect N.O. switch between P6.R (+5v) and P6.W (input)


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger2        = PIN6                  ' SETUP = DN
SYMBOL  Trigger1        = PIN5

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

SYMBOL  Baud            = OT2400                ' B/R jumper removed

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0
' -----[ Variables ]-------------------------------------------------------

SYMBOL  relays          = B0
SYMBOL   redLight       =  BIT0                 ' connect to RC-4, K1
SYMBOL   yellowlight1   =  BIT1                 ' connect to RC-4, K2
SYMBOL   yellowlight2   =  BIT2                 ' connect to RC-4, K3
SYMBOL  grnlightncyl    =  BIT3                 ' connect to RC-4, K4
SYMBOL idx              =  B3
SYMBOL timer1           =  B2
SYMBOL timer2           =  B3
SYMBOL delay            =  W4
SYMBOL lottery          =  W5
'----[ Initialization ]-------------------------------------------------

Reset:
  ' reset AP-8 and RC-4 on power-up or reset button
  '
  SEROUT Sio, Baud, ("!!!!!!AP8", 0, "X", "!RC4", 0, "X")

  PAUSE 25

  relays = IsOff                                ' all are off now
  idx = 0
  PINS   = %00000000                            ' clear all
  DIRS   = %00011111                            ' set outputs
' -----[ Program Code ]----------------------------------------------------

Main:
  timer1 =0                                     ' reset timers
  timer2 =0

  check_Triggers:
    PAUSE 5                                     ' loop pad

    check_Tl:
      timer1 = timer1 + 5 * Trigger1
      IF timer1 = 100 THEN Show_1

      Check_T2:
        timer2 = timer2 + 5 * Trigger2
        IF timer2 = 100 THEN Show_2
          GOTO check_Triggers
          Show_1:

  IF Trigger1 = IsOff THEN Main                  ' wait for trigger

Start_Audio:
  SEROUT Sio, Baud, ("!AP8", 0, "P", 0)         ' play sound 0
  PAUSE 4500

Activate_Lights:
  redLight = IsOn
  GOSUB Refresh_RC4
  PAUSE 250

  redLight = IsOff
  yellowlight1 = IsOff
  yellowlight2 = IsOff
  grnlightncyl = IsOn
  GOSUB Refresh_RC4
  PAUSE 500

  relays = IsOff
  GOSUB Refresh_RC4                             ' clear relays
  SEROUT Sio, Baud, ("!AP8", 0, "X")            ' stop audio
  PAUSE 25                                      ' let AP-8 reset

  GOTO Main

        Show_2:

  timer2 = 0                                     ' reset timer2

Check_Trigger2:
  RANDOM lottery                                ' stir random #
  PAUSE 5                                       ' loop pad
  timer2 = timer2 + 5 * Trigger2                   ' update timer2
  IF timer2 < 100 THEN Check_Trigger2             ' wait for 0.1 sec input


  SEROUT Sio, Baud, ("!AP8", %00, "P", 1)       ' play segment 1

Set_Delay:
  idx = lottery // 4                            ' random, 0 to 3
  LOOKUP idx, (8500, 9500, 10000, 11000), delay
  PAUSE delay
  SEROUT sio, Baud, ("!AP8", %00, "P", 2)       ' play segment
  PAUSE 400
  redLight = IsOn
  GOSUB Set_RC4
  PAUSE 250

  redLight = IsOff
  yellowlight1  =IsOn
  GOSUB Set_RC4
  PAUSE 150
  yellowlight1  =IsOff
  yellowlight2  =IsOn
  GOSUB Set_RC4
  PAUSE 150
  yellowlight2  =IsOff
  grnlightncyl = IsOn
  GOSUB Set_RC4
  PAUSE 500

  relays = IsOff
  GOSUB Set_RC4                                 ' clear relays
  SEROUT Sio, Baud, ("!AP8", 0, "X")            ' stop audio
  PAUSE 25                                      ' let AP-8 reset

  GOTO Main

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

Refresh_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN

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


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


' -----[ User Data ]-------


Any help would be appreciated. I may not even be able to do what I am wanting without adding something else.
Thanks again...

JonnyMac

Give this a look-over; it fits.

' {$STAMP BS1}
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Connections:
' -- replace ULN2803 with ULN2003
' -- connect P7 to RC-4 (serial), RC-4 to AP-8
'    * RC-4 must be first in chain
' -- remove B/R jumper on RC-4 and AP-8
' -- remove A0 & A1 jumpers from RC-4 and AP-8
' -- remove Prop-1 P7 SETUP jumper
' -- move Prop-1 P6 SETUP jumper to UP
' -- connect N.O. switch between P6.R (+5v) and P6.W (input)


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger2        = PIN6                  ' SETUP = DN
SYMBOL  Trigger1        = PIN5


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

SYMBOL  Baud            = OT2400                ' B/R jumper removed

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  relays          = B0
SYMBOL   RedLight       =  BIT0                 ' connect to RC-4, K1
SYMBOL   YellowLt1      =  BIT1                 ' connect to RC-4, K2
SYMBOL   YellowLt2      =  BIT2                 ' connect to RC-4, K3
SYMBOL   GreenLtCyl     =  BIT3                 ' connect to RC-4, K4

SYMBOL timer1           = B2
SYMBOL timer2           = B3
SYMBOL sfx              = B4
SYMBOL idx              = B5
SYMBOL delay            = W4
SYMBOL lottery          = W5


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

Reset:
  ' reset AP-8 and RC-4 on power-up or reset button
  '
  SEROUT Sio, Baud, ("!!!!!!AP8", 0, "X", "!RC4", 0, "X")
  PAUSE 25

  relays = IsOff                                ' all are off now


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

Main:
  timer1 = 0                                    ' reset timers
  timer2 = 0

Check_Triggers:
  RANDOM lottery
  PAUSE 5                                       ' loop pad

Check_T1:
  timer1 = timer1 + 5 * Trigger1
  IF timer1 = 100 THEN Show_1

Check_T2:
  timer2 = timer2 + 5 * Trigger2
  IF timer2 = 100 THEN Show_2
    GOTO Main


Show_1:
  sfx = 0
  GOSUB Play_AP8
  PAUSE 4500

Activate_Lights:
  RedLight = IsOn
  GOSUB Set_RC4
  PAUSE 250

  relays = %1000
  GOSUB Set_RC4
  PAUSE 500

  relays = IsOff
  GOSUB Set_RC4
  GOSUB Kill_AP8
  PAUSE 25
  GOTO Main


Show_2:
  sfx = 1
  GOSUB Play_AP8

Set_Delay:
  idx = lottery // 4                            ' random, 0 to 3
  LOOKUP idx, (8500, 9500, 10000, 11000), delay
  PAUSE delay
  sfx = 2
  GOSUB Play_AP8
  PAUSE 400
  RedLight = IsOn
  GOSUB Set_RC4
  PAUSE 250

  RedLight = IsOff
  YellowLt1 = IsOn
  GOSUB Set_RC4
  PAUSE 150
  YellowLt1 = IsOff
  YellowLt2 = IsOn
  GOSUB Set_RC4
  PAUSE 150
  YellowLt2 = IsOff
  GreenLtCyl = IsOn
  GOSUB Set_RC4
  PAUSE 500

  GOTO Reset


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

Set_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN

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

Play_AP8:
  SEROUT Sio, Baud, ("!AP8", %00, "P", sfx)
  RETURN

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

Kill_AP8:
  SEROUT Sio, Baud, ("!AP8", %00, "X")
  RETURN


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

lazerlite

December 06, 2008, 02:10:24 PM #9 Last Edit: December 06, 2008, 02:13:16 PM by lazerlite
THANK YOU JON. It is perfect. I just need it to do one more thing. I would like to include a timer/stopwatch. The timer starts when the green light comes on and stops with a  floor mat switch, the time would be displayed an a LED (OF SOME SORT?) . The time would need to show seconds/10Th's and 100Th's . AND do you make anything like  a LED display for this and or a floor mat switch or where I can get some that will  work? Can I and this with my PROP-1 ?  THANK YOU FOR EVERYTHING!

JonnyMac

The only way to add timer functionality with that kind of resolution is to move up the the Prop-SX; the Prop-1 just doesn't have the horsepower for that kind of coding.  I don't know where you'd get a display as you're suggesting -- if you can find one I may be able to help you get it connected.
Jon McPhalen
EFX-TEK Hollywood Office

lazerlite

Hi Jon..I was on the Parallax site and found a  7Seg-DB Daughterboard (Slave Unit)..or master unit..Do I need this BS2pe Prototyping Daughterboard  to make it work? And can it be simply attached by using a servo cable to the prop sx controller? Basically, I am trying to figure out how to make one so it will work after I get my prop sx controller. As far as a mat switch goes, I saw a flexiforce sensor..is this the same thing a floor mat switch to stop the counter? Thanks

JonnyMac

Can you give me a link to the display you're talking about.  The search engine at Parallax is awful (don't worry, I expressed that opinion when we worked there) and I couldn't find what you're talking about.  And... I really don't like hunting for things we don't sell.

The Flexiforce is not a good candidate for a mat switch.  It's about the size of a nickel, and is actually a resistive element.  To use it in an application when one steps on it you'd have to create a mechanism that focuses a normal pad onto the small element.  In the end, I would do this; you can buy an off-the-shelf mat switch fairly inexpensively and with no fuss.

BTW... this thread in the Parallax SX forum shows the code (not for beginners) for implementing an RTC/Timer in the SX:

http://forums.parallax.com/forums/default.aspx?f=7&m=311402

My code is posted toward the bottom of the thread.  The code I wrote uses a standard LCD display as that's what the poster needed and I'm doing an intervalometer (time lapse photography controller) that uses it for my Nuts & Volts column.
Jon McPhalen
EFX-TEK Hollywood Office

lazerlite

December 14, 2008, 07:23:04 AM #13 Last Edit: December 15, 2008, 11:37:35 AM by lazerlite
Here is the link: THANK YOU for the info on the RTC/TIMER. I will study it over. After looking at it again, do I need  to attach a 7 seg-DB to a MoBoStamp-pe and a servo cable from the MoBoStamp-pe to the Prop-SX controller? Is this how to make it?? Does the 7 segment display have to have the  MoBoStamp-pe to make it work?

http://www.parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/List/1/ProductID/454/Default.aspx?txtSearch=led+display&SortField=ProductName%2cProductName

JonnyMac

You *could* use that module but you'd have to come up with connections.  At this point you're nearly to custom designing something completely custom.  You might consider getting an SX proto board from Parallax and using SX/B (you'll have to post questions in their SX forum, but I'm a regular there).
Jon McPhalen
EFX-TEK Hollywood Office