May 17, 2024, 09:34:36 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.


Serial Command Play Random - Not So Random?

Started by JesusFreak1959, August 10, 2011, 09:24:24 PM

Previous topic - Next topic

JesusFreak1959

August 10, 2011, 09:24:24 PM Last Edit: August 10, 2011, 09:45:57 PM by JesusFreak1959
Quite possibly a stupid mistake - trying to make things work while working in unventilated steel buildings on a 97 degree day tends to scramble the brains.

I was optimistic when I read this in the AP-16 dox: "...the AP-16+ maintains an internal play list so that – if using the same limit # in the "P?" command – no file will be repeated until all within the range have played."

I have 3 files SFX00 - SFX02 that "randomize" in manual mode.  But when this code is executed thru my Prop 1, periodically, I hear the same file played back to back, even up to 3 times in a row.  I am running the latest firmware revision:

SEROUT Sio, OT2400, ("!AP16", %00, "P?", 2, 1)

I could see where I might hear SFX00, SFX02, then SFX00 again, but I should never hear the same file back to back with this statement.  Does the "X" (reset) command reset the randomization queue?  This may be where the code is at fault.

JonnyMac

QuoteDoes the "X" (reset) command reset the randomization queue? 

Yes, it resets everything, including the playlist that saves which files in a range have played.
Jon McPhalen
EFX-TEK Hollywood Office

JesusFreak1959

If it is highly unlikely to impossible that the AP-16 would be retriggered while a sound is still playing, is there any reason to have the reset command in there at all?  Code is below:

' =========================================================================
'   File...... Academy Teacher Jumper.BS1
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
' Triggered, table-drive sequencer capable of driving six control outputs.
' P6 is used as the trigger input.
'
' Note: Replace ULN2803 with ULN2003 to allow serial comms with AP-8
' (on P7).
'
' -----[ Revision History ]------------------------------------------------
' 2010-Sep - Freezer Jumper  mod by Jeff Hamilton
' 2011-Aug - ML: Academy Teacher Jumper, modified to use AP-16 instead AP8

' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN

' -----[ Constants ]-------------------------------------------------------
SYMBOL  IsOn            = 1                     ' for active-high input
SYMBOL  IsOff           = 0
SYMBOL  TicTiming       = 100                   ' 0.1 sec per step

' -----[ Variables ]-------------------------------------------------------
SYMBOL  showBits        = B0
SYMBOL  playAudio       = BIT6
SYMBOL  endOfShow       = BIT7
SYMBOL  pntr            = B2                    ' step pointer
SYMBOL  tix             = B3

' -----[ Initialization ]--------------------------------------------------
Reset:
  PINS = %00000000                              ' clear pins
  DIRS = %00111111                              ' P0..P5 are outputs
  SEROUT Sio, OT2400, ("!AP16", %00, "X")       ' ML: do not reset? random play
  pntr = 0                                      ' point to start of show

' -----[ Program Code ]----------------------------------------------------
Main:
  IF Trigger = IsOff THEN Main                  ' wait for trigger

Play_Show:
  READ pntr, showBits                           ' get step

Check_Sound:
  IF playAudio = IsOff THEN Engine
     SEROUT Sio, OT2400, ("!AP16", %00, "P?", 2, 1)  ' randomize 3 files & no loop

Engine:
  PINS = showBits & %00111111                   '   update outputs
  pntr = pntr + 1                               '   point to timing
  READ pntr, tix                                '   read it
  GOSUB Timer                                   '   run the timer
  pntr = pntr + 1                               '   point to next step

  IF endofShow = IsOn THEN Reset                '   done?
    GOTO Play_Show

' -----[ Subroutines ]-----------------------------------------------------
Timer:
  IF tix = 0 THEN Timer_Done                    ' timer expired?
    PAUSE TicTiming                             ' no, time on "tic"
    tix = tix - 1                               ' decrement timer
    GOTO Timer                                  ' check again

Timer_Done:
  RETURN

' -----[ EEPROM Data ]-----------------------------------------------------
Show_Data:
'OUTPUT Ch:76543210
'          +------------ end of show bit
'          |+----------- start audio player
'          ||+---------- not used
'          |||+--------- not used
'          ||||+-------- eyes/LED
'          |||||+------- not used
'          ||||||+------ extend jumper
'          |||||||+----- jumper
'          ||||||||
'          ||||||||  +-- timing (1 to 255)

  EEPROM (%01001000, 2)                             
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)

  EEPROM (%00000000, 2)
  EEPROM (%00000000, 2)
  EEPROM (%00000000, 2)
  EEPROM (%00000000, 2)
  EEPROM (%00000000, 2)
  EEPROM (%00000000, 2)
  EEPROM (%00000000, 2)

  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)

  EEPROM (%00000000, 2)
  EEPROM (%00000000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00000000, 2)
  EEPROM (%00000000, 2)
  EEPROM (%00000000, 2)

  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00001000, 2)

  EEPROM (%00000000, 120)                       ' inter-show delay

  EEPROM (%10000000, 0)                         ' show done

JonnyMac

August 22, 2011, 12:31:54 PM #3 Last Edit: August 22, 2011, 12:36:16 PM by JonnyMac
I put it at the beginning of my programs because the Prop-1 could be reset separately from the AP-16+; having the Prop-1 send the X command at the beginning of its program gets them in sync.

I would change the Initialization section to this for the AP-16+ -- the AP-16+ will only get the X command at the start of its program.

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

Power_Up:
  PAUSE 2500                                    ' let AP-16+ power up
  SEROUT Sio, OT2400, ("!AP16", %00, "X")       ' reset AP-16+

Reset:
  PINS = %00000000                              ' clear pins
  DIRS = %00111111                              ' P0..P5 are outputs
  pntr = 0                                      ' point to start of show


Please remove my name from any listings you modify -- I have enough of my own creations to support!  ;)
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Another note: your trigger sensing is kind of old school and can be fouled by spurious inputs.  Better to debounce -- like this:

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  PAUSE 5                                       ' scan delay
  IF Trigger = IsOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer
Jon McPhalen
EFX-TEK Hollywood Office

JesusFreak1959


JesusFreak1959

...and it worked swimmingly.  Thanks for help and the hot tip on the old school trigger code.  Apparently we've got some of that code still lingering in our vault.

bsnut

Once, you learn new ways to code your you will be able to combine both newer ways with the old school ways. That way you can write yourself good code.
William Stefan
The Basic Stamp Nut