November 23, 2024, 02:08:00 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.


Advice for a newbie

Started by chuck, July 19, 2008, 05:42:19 AM

Previous topic - Next topic

chuck

Newbie (be gentle with me), just like to say hi to everyone,

Before I start I have to say that, having spoken Jon a couple of weeks ago, he is one of the nicest and most helpful guys I've ever come across. Its not every day you meet someone willing to speak to you on a Sunday morning when they are obviously very busy, can't speak highly enough of Jon. Still, would have been more impressed had he phoned me, cost me a small fortune calling from the UK  ;)  ;D

I was kindly allowed the use of an earlier program that Jon helped on and I have attempted to modify it to suite my purpose. I would be grateful if someone could tell me if I'm anywhere near right.

The program is to run an automated BMX start gate. On pressing the start button the sequence is: a pause to allow the rider to ready themselves, start the first audio segment, and pause for a random delay of between 1/100th to 2.5 seconds [I think the random code I have included may not be the best way to do it as it is a pseudo-random?] start the second audio segment and synchronise a 4 light sequence [the pauses between the lights is not 100% accurate but I can adjust when I get the thing up and running] on the green light it also needs to trigger switch to release the gate, then wait for the reset button to be pressed.

Hope that makes sense, thanks in advance.

' =================================================================
' File......... Bike_Starter.BS1
' Purpose...... Automate BMX starting gate
' Author....... Jon/Randy
' E-mail.......
' Started......3-12-06
' Updated......4-10-06

' {$STAMP BS1}
' {$PBASIC 1.0}

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

' Move P6 AND P7 setup jumpers to the down position

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

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

SYMBOL Start = PIN7
SYMBOL Reset = PIN6
SYMBOL Amberlight2 = PIN5
SYMBOL Amberlight1 = PIN4
SYMBOL SFX = 3
SYMBOL Gate = PIN2
SYMBOL Greenlight = PIN1
SYMBOL Redlight = PIN0
SYMBOL timer = W1
SYMBOL delay = W2

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

SYMBOL YES = 1
SYMBOL No = 0

SYMBOL IsOn = 1
SYMBOL IsOff = 0

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

' --------[ EEPROM Data ]-----------------------------------------------------------------

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

Setup:
PINS = %00000000 ' all outputs off
DIRS = %00000111 ' setup outputs
IF Reset = Yes THEN Setup

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

Main:
IF Start = No THEN Main ' wait for start input
PAUSE 3000 ' 3 second delay
SEROUT SFX, OT2400, ("!AP8", %11, "P", 0) ' Start audio
RANDOM timer
delay = timer // 2500 + 10 ' psuedo-random timer between 1/100th to 2.5 seconds
PAUSE delay
SEROUT SFX, OT2400, ("!AP8", %11, "P", 1) ' Start beeps
PINS = %00000001 ' red light on
PAUSE 150 ' adjust for space between light sequence
PINS = %00001000 ' first amber light on
PAUSE 150 ' adjust for space between light sequence
PINS = %00010000 ' first amber light on
PAUSE 150 ' adjust for space between light sequence
PINS = %00000100  ' gate down
PAUSE 100 ' pause 1/100 second
PINS = %00000001 ' green light on
PAUSE 3000 ' pause for 3 seconds
PINS = %00000000 ' lights off
Wait_For_Reset:
IF Reset = No THEN Wait_For_Reset ' stop until reset pressed
GOTO Setup

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

livinlowe

Welcome!
Yep, Jon is great, he is very good about helping new guys get up to speed and all he asks in return is for people to experiment and have fun. (And buy a couple Prop-1, 2 or SX's  ;), buy hey why not? )

Looking at your program I can't see any reason why it wont work! Have fun with your new "addiction"
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

July 19, 2008, 09:23:37 AM #2 Last Edit: July 19, 2008, 02:56:35 PM by JonnyMac
Well, now that we've established that I'm the coolest guy in the world....  ;D  (cheekiest, more like)  ... let's have a look at the program.

Some guidelines that will help:
-- Debounce trigger inputs to prevent false starts
-- Active-high buttons can be on ANY pin; the ULN acts as a pull-down
-- Always put your serial control on P7; see: http://www.efx-tek.com/php/smf/index.php?topic=130.0
-- For truly random data you need to stir the random value and then select it at random (button press)
-- To squeeze a value into a specific range, see: http://www.efx-tek.com/php/smf/index.php?topic=49.0 (modulus section)
-- I prefer to write code than comments; the style below is virtually self-commenting

Give this listing a look-over and compare it to your original; the programs behave in the same manner but this version is probably a little easier to read/update, does give you a truly random start delay, and debouces the Start button so that you don't get a false start.

Have fun!

' =========================================================================
'
'   File...... Bike_Starter.BS1
'   Purpose... Automate BMX starting gate
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Start           = PIN6                  ' SETUP = DN
SYMBOL  Reset           = PIN5
SYMBOL  Gate            = PIN4
SYMBOL  GreenLight      = PIN3
SYMBOL  AmberLight2     = PIN2
SYMBOL  AmberLight1     = PIN1
SYMBOL  RedLight        = PIN0


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

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

SYMBOL  IsDown          = 1
SYMBOL  IsUp            = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  status          = B0
SYMBOL   playing        = BIT7

SYMBOL  sfx             = B2

SYMBOL  timer           = W4
SYMBOL  lottery         = W5


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

Setup:
  PINS = %00000000                              ' clear all pins
  DIRS = %00011111                              ' make P0-P4 outputs

  IF Reset = Yes THEN Setup                     ' force reset release


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

Main:
  timer = 0                                     ' reset timer

Check_Start:
  RANDOM lottery                                ' stir random #
  PAUSE 2                                       ' loop pad
  timer = timer + 2 * Start                     ' update timer
  IF timer < 50 THEN Check_Start                ' wait for 50 ms input

  PAUSE 3000

  sfx = 0
  GOSUB Play_Audio
  GOSUB Audio_Hold

  timer = lottery // 2491 + 10                  ' 10 to 2500 ms
  PAUSE timer

  sfx = 1
  GOSUB Play_Audio

  RedLight = IsOn
  PAUSE 150

  RedLight = IsOff
  AmberLight1 = IsOn
  PAUSE 150

  AmberLight1 = IsOff
  AmberLight2 = IsOn
  PAUSE 150

  AmberLight2 = IsOff
  GreenLight =  IsOn
  Gate = IsDown
  PAUSE 3000

  GreenLight = IsOff


Wait_For_Reset:
  IF Reset = No THEN Wait_For_Reset
    GOTO Setup


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

Play_Audio:
  SEROUT Sio, Baud, ("!AP8", %11, "P", sfx)
  RETURN

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

Audio_Hold:
  SEROUT Sio, Baud, ("!AP8", %11, "G")          ' get status
  SERIN  Sio, Baud, status
  IF playing = Yes THEN Audio_Hold
    RETURN


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

Jon McPhalen
EFX-TEK Hollywood Office

chuck

Morning Jon, thanks for the help. Not too sure about comparing the two, mine looks a bit scruffy  :( Placing the audio in a subroutine makes it easier for me to understand, also using IsOn/IsOff rather than binary indicators. While I can fumble my way through most of your code I'm not sure what 'SETUP = out; no ULN &  SETUP = DN' so I guess I have a lot of reading to do. The guys from Holland have shipped the Prop1 & AP-8 and I should recieve them on Monday, so looking forward to getting going.

chuck

JonnyMac

July 19, 2008, 11:56:23 AM #4 Last Edit: July 19, 2008, 11:59:31 AM by JonnyMac
When you get a chance to read the Prop-1 docs you'll see references to the SETUP jumpers for P6 and P7.  These jumpers are used to preset the input state.  We don't need one on P7 as this is being used as a serial IO line and the AP-8 takes care of the pull-up on that side.

http://www.efx-tek.com/downloads/prop-1_docs.pdf

I just noticed something: You should insert a PAUSE after playing slot 0 in the AP-8 so that it can finish.  If your randomized delay between playing slots 0 and 1 is very short slot 0 could get cut off (if you send a play command while the AP-8 is playing it will kill the present audio and start the new).
Jon McPhalen
EFX-TEK Hollywood Office

chuck

Cheers Jon. Ok its making a little more sense to me now, another 20 years should see me right  :-[

  sfx = 0
  GOSUB Play_Audio

  PAUSE 10                                          ' would that do it?

  timer = lottery // 2491 + 10                  ' 10 to 2500 ms
  PAUSE timer

Does this line indicate that it is listening for a reset command all the time   IF Reset = Yes THEN Setup i.e. could activate the reset switch to act as an interupt?

JonnyMac

July 19, 2008, 02:56:00 PM #6 Last Edit: July 19, 2008, 03:04:01 PM by JonnyMac
No, I don't think that will work -- you see, once the command is sent by SEROUT the Prop-1 moves on to the next instruction, it doesn't know to wait on the now-playing audio unless you specifically tell it to.  I've added a new subroutine called Audio_Hold that lets you do this when you want (see updated listing above).

The Prop-1 doesn't have interrupts.  The line you cite simply holds the program in the Setup section until the reset input goes low.  When in other parts of the program that input is ignored.
Jon McPhalen
EFX-TEK Hollywood Office

chuck


chuck

Just a quick one, to give you all something to think about on a lazy Sunday afternoon and whilst I await the arrival of my Prop1 starter kit tomorrow  ;D. After speaking to Jon the other week I mentioned that I would like to add a timer to this gate i.e. as the gate drops timer starts and when a switch is cycled over (gas station bell kind of thing) it stops the timer, the time would be display on an LCD, and was advised that the Prop-SX would be the way to go. Now the thing is, I would like to build a 4 person gate to take into schools and youth projects, do our bit to introduce kids to a healthy sport. I assume I could use the same control for the gates or just have one large gate. If I wanted each lane to have a separate timer, connected to the greenlight I/O in the above program that would trigger 4 NO switches (one to each LCD) and 4 floor switches on a 'Y' joint to the NO switches (first signal starts the timer second one stops the timer) would this work? And would it mean having a Prop1 for each LCD.

I hope the way I've written this makes some kind of sense.


JonnyMac

I think that could be done on the Prop-SX without much trouble -- especially with version 2.0 of the compiler (which will be released soon).  We should put that discussion into the Prop-SX section, though.
Jon McPhalen
EFX-TEK Hollywood Office

chuck

Ok, will do Jon.

With the BMX racing start gates there are three versions, ABA, NBL and UCI random - so as a practice exercise I have had a go at the ABA and NBL (not much of an effort realy, just moving code round). If you think they are ok maybe they could go in the library section.



' ===========================================================================================
' File.............. ABA_Bike_Starter.BS1
' Purpose...... Automate ABA BMX starting gate
' Author......... Jon/Randy/Damien
' E-mail.......
' Started........3-12-06
' Updated......4-10-06

' {$STAMP BS1}
' {$PBASIC 1.0}

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

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

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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Start           = PIN6                  ' SETUP = DN
SYMBOL  Reset           = PIN5
SYMBOL  Gate            = PIN4
SYMBOL  GreenLight      = PIN3
SYMBOL  RedLight        = PIN0

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

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

SYMBOL  IsDown          = 1
SYMBOL  IsUp            = 0

SYMBOL  Baud            = OT2400

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

SYMBOL  status          = B0
SYMBOL  playing         = BIT7

SYMBOL  sfx             = B2

' --------[ EEPROM Data ]-----------------------------------------------------------------

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

Setup:
  PINS = %00000000                              ' clear all pins
  DIRS = %00011111                              ' make P0-P4 outputs

  IF Reset = Yes THEN Setup                     ' force reset release

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

Main:
IF Start = No THEN Main                         ' wait for start input

  PAUSE 6000                                    ' 6 second delay

  sfx = 0
  GOSUB Play_Audio                              ' Start audio
  GOSUB Audio_Hold

  PAUSE 12365                                   ' adjust for cadence

  RedLight = IsOn                               ' red light on
  PAUSE 400                                     ' adjust for space between red and gate

  RedLight = IsOff                              ' red off, gate down
  Gate = IsDown

  PAUSE 100                                     ' pause 1/100 second

  GreenLight =  IsOn                            ' green light on

  PAUSE 3000                                    ' pause 5 seconds

  GreenLight = IsOff                            ' green off
  PAUSE 5000

  Wait_For_Reset:

Wait_For_Reset:
  IF Reset = No THEN Wait_For_Reset
    GOTO Setup

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


Play_Audio:
  SEROUT Sio, Baud, ("!AP8", %11, "P", sfx)
  RETURN

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

Audio_Hold:
  SEROUT Sio, Baud, ("!AP8", %11, "G")          ' get status
  SERIN  Sio, Baud, status
  IF playing = Yes THEN Audio_Hold
    RETURN


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


' =========================================================================
'
'   File...... Bike_Starter.BS1
'   Purpose... Automate NBL BMX starting gate
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Start           = PIN6                  ' SETUP = DN
SYMBOL  Reset           = PIN5
SYMBOL  Gate            = PIN4
SYMBOL  GreenLight      = PIN3
SYMBOL  AmberLight2     = PIN2
SYMBOL  AmberLight1     = PIN1
SYMBOL  RedLight        = PIN0


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

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

SYMBOL  IsDown          = 1
SYMBOL  IsUp            = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  status          = B0
SYMBOL  playing         = BIT7

SYMBOL  sfx             = B2

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

Setup:
  PINS = %00000000                              ' clear all pins
  DIRS = %00011111                              ' make P0-P4 outputs

  IF Reset = Yes THEN Setup                     ' force reset release


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

Main:

  PAUSE 3000

  sfx = 0
  GOSUB Play_Audio
  GOSUB Audio_Hold

  PAUSE 200

  sfx = 1
  GOSUB Play_Audio

  RedLight = IsOn
  PAUSE 150

  RedLight = IsOff
  AmberLight1 = IsOn
  PAUSE 150

  AmberLight1 = IsOff
  AmberLight2 = IsOn
  PAUSE 150

  AmberLight2 = IsOff
  GreenLight =  IsOn
  Gate = IsDown
  PAUSE 3000

  GreenLight = IsOff


Wait_For_Reset:
  IF Reset = No THEN Wait_For_Reset
    GOTO Setup


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

Play_Audio:
  SEROUT Sio, Baud, ("!AP8", %11, "P", sfx)
  RETURN

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

Audio_Hold:
  SEROUT Sio, Baud, ("!AP8", %11, "G")          ' get status
  SERIN  Sio, Baud, status
  IF playing = Yes THEN Audio_Hold
    RETURN


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


chuck

Everything is going fine and I should be able to post a video of the project fairly soon. However, I'm stuck on a problem and not sure what to do. In the code below is a subroutine for interupting the audio but it doesn't seem to work, what I would realy like it to do is anytime during the main routine when I press the 'red' (reset) button jump to an AP8 segment to play a warning tone and reset the program. Would I need to encase the whole routine in an IF ELSE statement.

Hope this makes sense


' =========================================================================
'
'   File...... Bike_Starter.BS1
'   Purpose... Automate BMX starting gate
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Start           = PIN6                  ' SETUP = DN
SYMBOL  Reset           = PIN5
SYMBOL  Gate            = PIN4
SYMBOL  GreenLight      = PIN3
SYMBOL  AmberLight2     = PIN2
SYMBOL  AmberLight1     = PIN1
SYMBOL  RedLight        = PIN0


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

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

SYMBOL  IsDown          = 1
SYMBOL  IsUp            = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  status          = B0
SYMBOL  playing        = BIT7

SYMBOL  sfx             = B2

SYMBOL  timer           = W4
SYMBOL  lottery         = W5


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

Setup:
  PINS = %00000000                              ' clear all pins
  DIRS = %00011111                              ' make P0-P4 outputs

  IF Reset = Yes THEN Setup                     ' force reset release


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

Main:
  timer = 0                                     ' reset timer

Check_Start:
  RANDOM lottery                                ' stir random #
  PAUSE 2                                       ' loop pad
  timer = timer + 2 * Start                     ' update timer
  IF timer < 50 THEN Check_Start                ' wait for 50 ms input

  PAUSE 3000

  sfx = 0
  GOSUB Play_Audio
  GOSUB Audio_Hold

  timer = lottery // 2700 + 100                  ' 100 to 2700 ms
  PAUSE timer

  sfx = 1
  GOSUB Play_Audio

  PAUSE 730

  RedLight = IsOn
  PAUSE 60

  RedLight = IsOff
  AmberLight1 = IsOn
  PAUSE 60

  AmberLight1 = IsOff
  AmberLight2 = IsOn
  PAUSE 60

  AmberLight2 = IsOff
  GreenLight =  IsOn
  Gate = IsDown
  PAUSE 2500

  GreenLight = IsOff


Wait_For_Reset:
  IF Reset = No THEN Wait_For_Reset
    sfx = 3
    GOSUB Play_Audio
    GOTO Setup


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

Play_Audio:
  SEROUT Sio, Baud, ("!AP8", %11, "P", sfx)
  RETURN

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

Audio_Hold:
  SEROUT Sio, Baud, ("!AP8", %11, "G")          ' get status
  SERIN  Sio, Baud, status
  IF playing = Yes THEN Audio_Hold
    RETURN


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

JonnyMac

I'm not sure you're going to be able to do this.  The reason is that if you want to be able to monitor a button any time during the program is running you need to reconstruct the program from a linear design (what you have) to a finite state machine that is constantly monitoring the buttons.  I did that and promptly ran out of EEPROM space (remember, the Prop-1 has a very small program space).

Here's the code that won't fit -- it will show you what a finite state-machine looks like in the Prop-1.  I'm going to look for another way to skin this cat, but... please don't hold your breath, this is tricky business with a Prop-1.

' =========================================================================
'
'   File...... Bike_Starter.BS1
'   Purpose... Automate BMX starting gate
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Start           = PIN6                  ' SETUP = DN
SYMBOL  Reset           = PIN5
SYMBOL  Gate            = PIN4
SYMBOL  GreenLight      = PIN3
SYMBOL  AmberLight2     = PIN2
SYMBOL  AmberLight1     = PIN1
SYMBOL  RedLight        = PIN0


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

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

SYMBOL  IsDown          = 1
SYMBOL  IsUp            = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  btns            = B0
SYMBOL   startBtn       =  BIT0
SYMBOL   resetBtn       =  BIT1

SYMBOL  status          = B1
SYMBOL   playing        = BIT15

SYMBOL  state           = B2
SYMBOL  idx             = B3
SYMBOL  sfx             = B4

SYMBOL  timer           = W4
SYMBOL  lottery         = W5


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

Setup:
  PINS = %00000000                              ' clear all pins
  DIRS = %00011111                              ' make P0-P4 outputs

  IF Reset = Yes THEN Setup                     ' force reset release

  state = 0                                     ' wait for start


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

Main:
  RANDOM lottery                                ' stir random value
  GOSUB Scan_Buttons

  IF resetBtn = Yes THEN Reset_Warning          ' check for Reset button


Update_Timer:
  IF timer = 0 THEN Handle_State
    timer = timer - 1


Handle_State:
  BRANCH state, (Wait_Start,Seg1,Seg2,Seg3,Seg4,Seg5,Seg6,Seg7,Seg8,Seg9)
  GOTO Main


Wait_Start:
  IF startBtn = No THEN Main
    timer = 3000 / 60                           ' set to pgm loops
    state = 1                                   ' update state
    GOTO Main


Seg1:                                           ' 3 sec delay
  IF timer > 0 THEN Main
    sfx = 0
    GOSUB Play_Audio
    state = 2
    GOTO Main


Seg2:                                           ' hold for sfx 0
  GOSUB Check_Audio
  IF playing = Yes THEN Main
    timer = lottery // 2700 + 100 / 60          ' 100 to 2700 ms
    state = 3


Seg3:
  IF timer > 0 THEN Main
    sfx = 1
    GOSUB Play_Audio
    timer = 730 / 60
    state = 4


Seg4:
  IF timer > 0 THEN Main
    RedLight = IsOn
    timer = 1
    state = 5
    GOTO Main


Seg5:
  IF timer > 0 THEN Main
    RedLight = IsOff
    AmberLight1 = IsOn
    timer = 1
    state = 6
    GOTO Main


Seg6:
  IF timer > 0 THEN Main
    AmberLight1 = IsOff
    AmberLight2 = IsOn
    timer = 1
    state = 7
    GOTO Main


Seg7:
  IF timer > 0 THEN Main
    AmberLight2 = IsOff
    GreenLight =  IsOn
    Gate = IsDown
    timer = 2500 / 60
    state = 8
    GOTO Main


Seg8:
  IF timer > 0 THEN Main
    GreenLight = IsOff
    state = 9
    GOTO Main


Seg9:
  IF resetBtn = No THEN Main                    ' wait for Reset button


Reset_Warning:
  sfx = 3
  GOSUB Play_Audio
  GOTO Setup


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

' Scans and debounces start and reset buttons
' -- creates ~60 ms delay

Scan_Buttons:
  btns = %11                                    ' assume pressed
  FOR idx = 1 TO 10
    btns = PINS / 32 & btns
    PAUSE 6
  NEXT
  RETURN

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

Play_Audio:
  SEROUT Sio, Baud, ("!AP8", %11, "P", sfx)
  RETURN

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

Check_Audio:
  SEROUT Sio, Baud, ("!AP8", %11, "G")          ' get status
  SERIN  Sio, Baud, status
  RETURN


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

chuck

Hi Jon,

You may need plenty of Star Bucks :) Am I right in assuming that the Seg1 etc is similar to a CASE SELECT? What about, after each iteration of the linear program, we insert a line of code like IF reset = yes THEN abort ELSE next line of code and the final reset as per normal.


JonnyMac

In a way, yes; BRANCH can be used with an index to jump to (select) a bit of code to run.

I tried what you has suggest -- you still run out of program space.  I've got another idea that I will present when I finish with a piece SX code that needs immediate attention.
Jon McPhalen
EFX-TEK Hollywood Office