November 21, 2024, 01:36:39 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.


Code conversion from Prop1 to Prop2

Started by davisgraveyard, July 29, 2024, 09:06:49 AM

Previous topic - Next topic

davisgraveyard

Its been a while since I've done this.  I code for a living but I haven't touched pBasic in a LONG time. 

I am converting this old Prop1 code to a Prop2  and I am switching from using a AP8 for audio to a smaller cheaper DY-XXXX audio board.  I am also using the pins on the Prop2 for the LED lights instead of using a DC-16.   Otherwise the code is the same

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

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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Solenoid        = 1


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

SYMBOL  IS_ON           = 1                     ' for active-high in/out
SYMBOL  IS_OFF          = 0


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

SYMBOL  timer           = B2
SYMBOL  i               = B3


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00111111                              ' make P0-P5 outputs

  PAUSE 10                                      ' reset devices
  SEROUT Sio, OT2400, ("!AP8", %11,"X")
  PAUSE 10
  SEROUT Sio, OT2400, ("!DC16",%11,"X")


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

Main:
  timer = 0                                     ' reset timer

Get_Trigger_1:
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 50 THEN Get_Trigger_1              ' 50ms for valid input

Force_Release:
  timer = 100                                   ' set 100ms release timer

Get_Trigger_0:
  PAUSE 5
  IF Trigger = IS_ON THEN Force_Release
    timer = timer - 5
    IF timer > 0 THEN Get_Trigger_0

Make_Sounds:
  FOR i = 1 TO 7
    SEROUT Sio, OT2400, ("!AP8", %11, "P", 0)
    PAUSE 1000
  NEXT

Light_Steps:
  FOR i = 0 TO 6
    PAUSE 5
    SEROUT Sio, OT2400, ("!AP8",  %11, "P", 0)
    PAUSE 5
    SEROUT Sio, OT2400, ("!DC16", %11, "P", i, 1)
    PAUSE 1000
    SEROUT Sio, OT2400, ("!DC16", %11, "P", i, 0)
  NEXT

  PAUSE 1000

Rattle_Solenoid:
  HIGH Solenoid
  PAUSE 7000
  LOW Solenoid
  PAUSE 100

  GOTO Main


'   {$STAMP BS2}
'   {$PBASIC 2.5}

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

Sio     PIN  7                ' SETUP = out; no ULN
Trigger PIN  8                ' SETUP = DN

Solenoid PIN 9


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


IS_ON           CON     1                     ' for active-high in/out
IS_OFF          CON     0

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

timer             VAR           Byte
i                 VAR           Byte


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

Reset:
  OUTH = %00000000
  DIRH = %10000111

  PAUSE 10                                      ' reset devices

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

Main:
  timer = 0                                     ' reset timer

Get_Trigger_1:
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 50 THEN Get_Trigger_1              ' 50ms for valid input

Force_Release:
  timer = 100                                   ' set 100ms release timer

Get_Trigger_0:
  PAUSE 5
  IF Trigger = IS_ON THEN Force_Release
    timer = timer - 5
    IF timer > 0 THEN Get_Trigger_0

Make_Sounds:
  FOR i = 1 TO 7
    SEROUT Sio,84,[$AA,$07,$02,$00,$01,$B4]' Play file #1
    PAUSE 1000
  NEXT

Light_Steps:
  FOR i = 0 TO 6
    PAUSE 5
    SEROUT Sio,84,[$AA,$07,$02,$00,$01,$B4]' Play file #1
    PAUSE 5
    HIGH i
    PAUSE 1000
    LOW i
  NEXT

  PAUSE 1000

Rattle_Solenoid:
  HIGH Solenoid
  PAUSE 7000
  LOW Solenoid
  PAUSE 100

  GOTO Main

Jeff Haas

A couple of notes:

- The Prop-2 (BS2) has more pins than the Prop-1 (BS1) so your init sequence should cover them all.  Like this:

OUTH = %10000000 : OUTL = %00000000          ' clear all
DIRH = %10000000 : DIRL = %11111111          ' set outputs.

Note the H and L sets of pins.  Of course you don't have to do this but it helps keep track of all the pins.

- In Make_Sounds, is the intent to play the same file several times in a row?  And then play it again as each of the LEDs light up?

davisgraveyard

The sound file is the sound of a boot taking a single step on concrete.

The program logic is like this...

Wait for a tigger from an audio relay board that makes contact when a sound is heard which is a loud footstep on a video file.

Play 7 steps as the ghost on the video advances

Play 7 more steps along with lighting up a LED footstep that glows

Activate a solenoid that rattles a gate for 7 seconds

Go back to waiting for the trigger


davisgraveyard


I always forget how OUTH and DIRH work

I am using pin 0-6 to turn on 12V LED"s
pin 7 for serial I/O
Pin 8 is for the trigger
Pin 9 is for a relay data trigger

so how should these be set?

OUTH = %10000000 : OUTL = %00000000          ' clear all
DIRH = %10000000 : DIRL = %11111111          ' set outputs.



Jeff Haas

Looking at the Prop-2, from the bottom you have P0 - P7 as one group of pins and P8 - P15 as the other.  These are the Low and High sets, OUTH and OUTL, DIRH and DIRL.

In the DIRH and DIRL sections, set pins to 1 to make them outputs, and 0 to make them inputs.

DIRL would be the same as you have, all 1's except for the pin for the MP3 player.  Run a test to see that you can trigger the MP3 and light up the LEDs. 
DIRH should be all 0's, since I think they're all inputs.

I think this is it:

OUTH = %00000000 : OUTL = %00000000          ' clear all
DIRH = %00000000 : DIRL = %01111111          ' set outputs. (1s) 

I've always seen JonnyMac set all the OUTH and OUTL to 0 in the Initialize section, and then label the section
Reset:so you can get to the end of the program, and then GOTO Reset if you need to have something complicated (pneumatics, etc.) to settle down.