November 23, 2024, 08:31:53 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.


Cycling outputs with trigger input

Started by gadget-evilusions, May 17, 2010, 07:58:13 PM

Previous topic - Next topic

gadget-evilusions

My goal with this program is to cycle thru 6 outputs. When Trigger is closed I want it to jump out of the first loop and to a loop with no delays on the on/off cycle (Emergency). I can not locate my mistake. It cycles thru the outputs fine but does not jump out of the main loop and into the emergency loop. I am testing this program with a prop-1 trainer.

' =========================================================================
'
'   File...... Evilusions_Cage_Maze_Strobes.bs1
'   Purpose...
'   Author.... Brian Warner
'   E-mail.... gadget@evilusions.com
'   Started... 5-17-2010
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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


SYMBOL Trigger           = PIN6

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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

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

SYMBOL  idx     = B2

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

Reset:
  PINS = %00000000
  DIRS = %011111111

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

Main:
  FOR idx = 0 TO 5
    HIGH idx
    PAUSE 50
    LOW idx
    PAUSE 50
    IF Trigger = IsOn THEN Emergency
  NEXT
GOTO Main

Emergency:
FOR idx = 0 TO 5
    HIGH idx
    LOW idx
  NEXT
IF Trigger = IsOff THEN Main
GOTO Emergency

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


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


' -----[ EEPROM Data ]-----------------------------------------------------
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

May 17, 2010, 08:54:36 PM #1 Last Edit: May 17, 2010, 08:56:27 PM by JonnyMac
I think part of the problem is that you have no delay time between HIGH and LOW in the Emergency section so you're getting there but not seeing it.  I changed things up visually, and this seems to work fine.

' =========================================================================
'
'   File...... Evilusions_Cage_Maze_Strobes.bs1
'   Purpose...
'   Author.... Brian Warner
'   E-mail.... gadget@evilusions.com
'   Started... 5-17-2010
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL Trigger          = PIN6


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

SYMBOL  idx             = B2


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

Reset:
 PINS = %00000000
 DIRS = %00111111


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

Main:
 FOR idx = 0 TO 5
   HIGH idx
   PAUSE 50
   IF Trigger = IsOn THEN Emergency
   LOW idx
   PAUSE 50
   IF Trigger = IsOn THEN Emergency
 NEXT
 GOTO Main

Emergency:
 PINS = %00111111
 FOR idx = 1 TO 8
   PAUSE 100
   PINS = PINS ^ %00111111
 NEXT
 IF Trigger = IsOff THEN Main
   GOTO Emergency

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


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


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

gadget-evilusions

Thanks Jon. I think you were correct. I needed at least a 10ms pause between high idx and low idx and now it works as I intended.

Now for a variation.

I would like to take the "Main" loop and have it randomize it's output, blinking between them (Out 0 - 5) without duplicating until all are hit. I have seen you do this with AP-8 outputs but I can not locate an example to look at. Your help would be appreciated. I will go back too looking for previous examples. The "Emergency" loop can stay the same.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

May 17, 2010, 09:39:13 PM #3 Last Edit: May 17, 2010, 10:14:18 PM by JonnyMac
Here's something to try.  Note that when you get away from the linear pattern your POV (persistence of vision) can make the device look like multiple outputs are active.

' =========================================================================
'
'   File...... Evilusions_Cage_Maze_Strobes.bs1
'   Purpose...
'   Author.... Brian Warner
'   E-mail.... gadget@evilusions.com
'   Started... 5-17-2010
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL Trigger          = PIN6


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

SYMBOL  idx             = B2
SYMBOL  last            = B3
SYMBOL  mask            = B4
SYMBOL  check           = B5
SYMBOL  hitList         = B6

SYMBOL  lottery         = B7


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

Reset:
 PINS = %00000000
 DIRS = %00111111

 lottery = 31


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

Main:
  hitList = %00000000                           ' clear "hit" pins

Blip:
  lottery = lottery * 5 + 123                   ' randomize
  idx = lottery // 6                            ' create index, 0 to 5
  IF idx = last THEN Main                       ' no repeats
    last = idx                                  ' mark for next cycle
  READ idx, mask                                ' get pin mask
  check = hitList & mask                        ' check this channel
  IF check = mask THEN Blip                     ' already played?
    hitList = hitList | mask                    ' else mark hit

  PINS = mask                                   ' output new channel
  PAUSE 100                                     ' delay
  IF Trigger = IsOn THEN Emergency              ' abort on trigger
  IF hitList = %00111111 THEN Main              ' if all hit, reset
    GOTO Blip                                   ' else keep going

Emergency:
 PINS = %00111111                              ' all on
 FOR idx = 1 TO 8
   PAUSE 100
   PINS = PINS ^ %00111111                     ' toggle all to flash
 NEXT
 IF Trigger = IsOff THEN Main
   GOTO Emergency


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


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


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

BitMask:
 EEPROM (%00000001)
 EEPROM (%00000010)
 EEPROM (%00000100)
 EEPROM (%00001000)
 EEPROM (%00010000)
 EEPROM (%00100000)
Jon McPhalen
EFX-TEK Hollywood Office