November 23, 2024, 12:31:43 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.


Another Monster in a box Pir, ap8, 2 solenoids

Started by widiver, September 18, 2009, 02:02:29 PM

Previous topic - Next topic

widiver

Hi,
I am just finishing up my MIB and need to get a program to run it and have extremely limited programming skills
I will use a PIR to activate
2 double acting cylinders - 1 for the lid, 1 for the bottom
I have 2 12v 5 port 4 way solenoids
AP-8 for sound. I would like to use 2 different sounds

This is how I see this running
PIR is activated

cylinder 1 (lid) opens for 1 sec, close for 1 sec, open, play sound 1, when sound is done close lid
wait 3 sec
Repeat above 1 time

Cylinder 2 (bottom) open 1 sec, close 1 sec, open 1 sec, close
wait 2 sec
Cylinder 1 open, play sound 1, when sound 1 done close lid (cylinder 1)
wait 3 sec
repeat 1 time

play sound 2 and as sound 2 plays I would like random opening and closing of the cylinder 1 and 2 until sound done
wait 1 min before starting over

thanks for your help
John

JonnyMac

Here you go, give this a try:

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started... 18 SEP 2009
'   Updated... 18 SEP 2009
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Sio     :: Serial IO to EFX-TEK accessories (RC-4, FC-4, etc.)
'            -- clip pin 1 of ULN2803 or replace with ULN2003
'
' Trigger :: Parallax-compatible PIR or N.O. button (mat switch, etc.)
'            -- connect N.O. button between P6.W and P6.R


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Bottom          = PIN1
SYMBOL  Lid             = PIN0


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

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  IsOpen          = 1
SYMBOL  IsClosed        = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' B/R jumper removed


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

SYMBOL  status          = B0
SYMBOL   playing        =  BIT7

SYMBOL  sfx             = B2
SYMBOL  valves          = B3
SYMBOL  last            = B4

SYMBOL  timer           = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' preset IOs
  DIRS = %00000011                              ' set output pins (1s)

  SEROUT Sio, Baud, ("!AP8", %00, "X")
  PAUSE 30000                                   ' let PIR warm-up


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input


  Lid = IsOpen
  PAUSE 1000
  Lid = IsClosed
  PAUSE 1000

  GOSUB Box_Talk

  Bottom = IsOn
  PAUSE 1000
  Bottom = IsOff
  PAUSE 1000

  Bottom = IsOn
  PAUSE 1000
  Bottom = IsOff
  PAUSE 2000

  GOSUB Box_Talk

  sfx = 1
  GOSUB Play_Audio


Bounce:
  RANDOM lottery
  valves = lottery & %11
  IF valves = last THEN Bounce
    last = valves
    PINS = valves

  RANDOM lottery
  timer = lottery // 151 + 100
  PAUSE timer
  GOSUB Check_Audio
  IF playing = Yes THEN Bounce

  PAUSE 30000                                   ' 30s + 30s = 1min
  GOTO Reset


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

Box_Talk:
  sfx = 0
  GOSUB Play_Audio

  Lid = IsOpen

Hold_Lid:
  GOSUB Check_Audio
  IF playing = Yes THEN Hold_Lid

  Lid = IsClosed
  PAUSE 3000
  RETURN

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

Play_Audio:
  SEROUT Sio, Baud, ("!AP8", %00, "P", sfx)
  RETURN

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

Check_Audio:
  PAUSE 15                                      ' create 50ms timing
  SEROUT Sio, Baud, ("!AP8", %00, "G")
  SERIN  Sio, Baud, status
  RETURN


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

widiver

Great, thanks a lot.
I will give it a try this week.

John