November 23, 2024, 09:29:30 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.


Prop2 Programming question

Started by davisgraveyard, September 18, 2009, 10:09:49 PM

Previous topic - Next topic

davisgraveyard

I want to randoming select OUT0-7 and then turn that output on/off and then its corresponding OUT8-15 output as well.   I seem to be having problems with my logic because on the 1st OUT is working and not the second.   Code below...any ideas?



' {$STAMP BS2}

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


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


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

Bush      VAR Byte                   ' solenoid to turn on
last      VAR Byte                    ' last solenoid adjusted
seconds   VAR Word
lottery   VAR Word                ' random value
i         VAR Byte


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

Reset:
  lottery = 1031                                ' seed random value


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

Main:
  RANDOM lottery                                ' tumble random value
  Bush = lottery & %11111111                        ' select a solenoid, 0 - 7
  IF Bush = last THEN Main                   ' no repeats
    last = Bush

  'rattle the solenoid
FOR i=1 TO 10
  HIGH Bush
    PAUSE 100
  LOW Bush
  PAUSE 100
  HIGH Bush + 8
    PAUSE 100
  LOW Bush + 8
  PAUSE 100
NEXT

  RANDOM lottery
  seconds =  1000 +  lottery // 5 * 1000        ' stay off for 3 to 8 seconds
  PAUSE seconds
  GOTO Main




JonnyMac

September 18, 2009, 11:18:57 PM #1 Last Edit: September 18, 2009, 11:20:48 PM by JonnyMac
I think this is what you're after:

' {$STAMP BS2}
' {$PBASIC 2.5}
'
' -----[ I/O Definitions ]-------------------------------------------------


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


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

lottery         VAR     Word                    ' random value
msecs           VAR     Word                    ' for random delay

idx             VAR     Byte                    ' loop counter
bush            VAR     Byte                    ' selected output
last            VAR     Byte                    ' last selection


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

Reset:
  lottery = 1031                                ' seed random value


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

Main:
  FOR idx = 1 TO 3
    RANDOM lottery                              ' stir it up
  NEXT

  bush = lottery // 8                           ' select 0 to 7
  IF (bush = last) THEN Main                    ' don't repeat
    last = bush

Rattle:
  FOR idx = 1 TO 10
    HIGH bush
    PAUSE 100
    LOW bush
    HIGH (bush + 8)
    PAUSE 100
    LOW (bush + 8)
  NEXT

  RANDOM lottery
  msecs = lottery // 5001 + 3000                ' 3 to 8 seconds
  PAUSE msecs
  GOTO Main
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

September 19, 2009, 01:03:01 PM #2 Last Edit: September 19, 2009, 01:08:19 PM by JonnyMac
... and if you wanted to randomize the number of rattles you could do something like this (replace the FOR-NEXT section with the code below):


  RANDOM lottery
 idx = lottery // 6 + 5                        ' 5 to 10 rattles

Rattle:
 HIGH bush
 PAUSE 100
 LOW bush
 HIGH (bush + 8)
 PAUSE 100
 LOW (bush + 8)
 idx = idx - 1
 IF idx > 0 THEN Rattle
Jon McPhalen
EFX-TEK Hollywood Office