November 21, 2024, 02:15:50 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Using a DATA table to control outputs on the BS2

Started by GregH, August 01, 2007, 08:06:54 AM

Previous topic - Next topic

GregH

Hi All,

The following is a simple program I often use for the prop1 to animate some props at our local haunted house.  Basically I use the EEPROM table to set the state of the output pins for a duration of time (the number following the comma in each EEPROM row).

I would like to use this same technique on the BS2 for pin i/o 0 to 15 but I'm having a couple of problems.  I have most everything converted but I'm having trouble reading the data and updating the pins.  I'm thinking I may have to divide the table into two word length sections.  Currently I READ the data into a VAR WORD and am using OUTS = VAR.  I would also like to signal the end of the table by setting Bit13 to 1 like I do with BIT7 in the program below.

Anyone successfully using this technique on a BS2?  If so, I would really appreaciate some help with this.  Thanks! Greg





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


SYMBOL  AP8     = 7                             ' serial I/O for AP-8
SYMBOL  Trigger = PIN6                          ' trigger
SYMBOL  Valves  = PINS

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

SYMBOL  Yes     = 1                             ' for active high input
SYMBOL  No      = 0


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

SYMBOL  temp    = B0                            ' value for pins
SYMBOL  done    = BIT7                          ' table end bit
SYMBOL  pntr    = B2                            ' pointer
SYMBOL  delay   = B3                            ' delay in 1/10 seconds


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

Table:
'            543210

  EEPROM (%00011001,  40)
  EEPROM (%00011011,  10)
  EEPROM (%00111111,  20)
  EEPROM (%00100101,  15)
  EEPROM (%00110111,  20)
  EEPROM (%00011001,  15)

  EEPROM (%10000000, 100)                       ' 10 sec re-trigger delay


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

Setup:
  DIRS = %00111111                              ' set i/o


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

Main:
  IF Trigger = No THEN Main                     ' wait for trigger
  pntr = 0                                      ' reset pointer



Main2:
  READ pntr, temp                               ' read bits from table
  pntr = pntr + 1                               ' point to delay
  READ pntr, delay                              ' read delay from table
  pntr = pntr + 1                               ' point to next EEPROM row

  Valves = temp                                 ' update the outputs
  GOSUB Timer                                   ' hold for timing

  IF done = Yes THEN Main                       ' table end?
    GOTO Main2                                  ' no, continue


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

Timer:
  IF delay = 0 THEN Timer_Exit                  ' delay finished?
    PAUSE 100                                   ' 1/10 second
    delay = delay - 1                           ' update counter
    GOTO Timer                                  ' return to timer

Timer_Exit:
  RETURN                                        ' return to caller

JonnyMac

Sure, we do it all the time.  The key to using 16-bit values in a DATA table and with READ is the "Word" modifier.  The program below is an update of your program for the Prop-2; it's identical except that:

1) You can use 14 outputs (0 - 13)
2) You can selectively enable starting the AP-8 (change "UseAudio_Off" to "UseAudio" in the Conditional Compilation section)

Note that bit15 of the outputs data is used to signal the end-of-show.

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


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


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


' -----[ Conditional Compilation Symbols ]---------------------------------

#DEFINE UseAudio_Off


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

Sio             PIN     15                      ' SETUP = out; no ULN
Trigger         PIN     14                      ' SETUP = DN
Valves          VAR     OUTS


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

IsActive        CON     1
IsNotActive     CON     0

IsOn            CON     1
IsOff           CON     0

EventDelay      CON     100


T2400           CON     396
T38K4           CON     6

Open            CON     $8000
Baud            CON     Open | T38K4            ' fast baud for accessories


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

record          VAR     Word                    ' current sequence record
tix             VAR     Byte                    ' timing for record

showBits        VAR     Word                    ' output + control bits
endOfShow       VAR     showBits.BIT15          ' 1 = stop when timer done


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

Reset:
  OUTS = $0000
  DIRS = $3FFF


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

Main:
  record = 0                                    ' point to start of show
  IF (Trigger = IsNotActive) THEN Main          ' wait for trigger

Start_Audio:
  #IF UseAudio #THEN
    SEROUT Sio, Baud, ["!AP8", %00, "P", 0]
  #ENDIF

Play_Show:
  READ (record * 3), Word showBits, tix         ' get outputs & timing
  OUTS = showBits & $3FFF                       ' update outputs

Timer:
  IF (tix = 0) THEN Next_Step                   ' timer expired?
    PAUSE EventDelay                            ' no, time one "tic"
    tix = tix - 1                               ' decrement timer
    GOTO Timer                                  ' check again

Next_Step:
  IF (endofShow = IsOn) THEN Reset              ' done?
    record = record + 1                         ' no, point to next
    GOTO Play_Show                              ' and keep going


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


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


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

Show_Data:
'               1111
'             X 32109876543210

  DATA  Word %0000000000011001,  40
  DATA  Word %0000000000011011,  10
  DATA  Word %0000000000111111,  20
  DATA  Word %0000000000100101,  15
  DATA  Word %0000000000110111,  20
  DATA  Word %0000000000011001,  15
  DATA  Word %1000000000000000, 100             ' 10 sec re-trigger delay


Now... if you're a Windows user and want to speed up the process of sequencer-style coding, we've made it dirt easy with the help of our friend, KC Oaks, and his very cool program called Vixen.  Checkout this topic:

http://www.efx-tek.com/php/smf/index.php?topic=140.0
Jon McPhalen
EFX-TEK Hollywood Office

GregH

Jon, THANKS SO MUCH!! ;D 

Once again I am impressed with you and the EFX-TEK team!

Thanks again!

Greg

livinlowe

Yeah, I can't believe how easy it is to make changes with Vixen. It is soooo cool!  :D
Shawn
Scaring someone with a prop you built -- priceless!