May 20, 2024, 09:59:54 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.


Timing and symbol questions

Started by aquawilly54, October 22, 2015, 07:11:31 PM

Previous topic - Next topic

aquawilly54

Hi all,
  I thought I knew the answer to this, but have proved myself wrong, so here it is;  Using last nights program as the example here, I want to have the cylinder and AP-16+ come on at the same time, and end at the same time.  The audio is 7 seconds long.

  I believe there are two ways of doing this
1.  Time them both somehow where they each end at 7 seconds
or
2.  Time it so the P0 output drops out when the audio finishes, thereby not having to worry about "perfect" timing.

I've been playing with it, but can't seem to figure it out.  Any help is as always greatly appreciated.

2nd question:  Notice in the I/O Definitions I have "PIN0" for the cylinder.  I tried (SYMBOL  Cylinder        =0      ' activate air cylinder) but it isn't recognized in the program code, so I put "PIN" back in and it works.  Can somebody fill me in on why?

Steve

' =========================================================================
'
'   File......      Witch jumper
'   Purpose...      Jump up with sound (witch's cackle)
'   Author....      Steve
'   E-mail....
'   Started...      10/20/2015
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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



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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Cylinder        = PIN0                  ' activate air cylinder


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  timer           = B2                    ' for debounce loop


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

Power_Up:
  PAUSE 3000                                    ' let AP-16+ initialize

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00111111                              ' P0..P5 are outputs

  PAUSE 30000                                   ' PIR warm-up/delay


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

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  PAUSE 5                                       ' scan delay
  IF Trigger = TrOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer

   Cylinder = IsOn                              ' activate cylinder

   PAUSE 4000                                   ' pause 4 seconds

  ' play audio file

  SEROUT Sio, Baud, ("!AP16", %00, "PS", 1, 1)

  GOTO Reset


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


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


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


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


' -----[ User Data ]-------------------------------------------------------

aquawilly54

I found an older program that had a similar set up, so I did some cutting and pasting again.  It seems to work, but please take a look and tell me if there might be something wrong.
Thanks again folks. 

Steve


' =========================================================================
'
'   File......      Witch jumper
'   Purpose...      Jump up with sound (witch's cackle)
'   Author....      Steve
'   E-mail....
'   Started...      10/20/2015
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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



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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Cylinder        = PIN0                  ' activate air cylinder


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400


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



SYMBOL  status         = B0                    ' AP-16+ status byte
SYMBOL   playing       =  BIT7                 ' 1 when playing

SYMBOL  timer          = B2                    ' for debounce loop


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

Power_Up:
  PAUSE 3000                                    ' let AP-16+ initialize

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00111111                              ' P0..P5 are outputs

  PAUSE 30000                                   ' PIR warm-up/delay


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

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  PAUSE 5                                       ' scan delay
  IF Trigger = TrOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer


    SEROUT Sio, Baud, ("!AP16", %00, "PS", 1, 1)



   Cylinder = IsOn                              ' activate cylinder

           Audio_Wait:
  PAUSE 100
  SEROUT Sio, Baud, ("!AP16", %00, "G")
  SERIN  Sio, Baud, status
  IF playing = Yes THEN Audio_Wait



  GOTO Reset


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


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


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


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


' -----[ User Data ]-------------------------------------------------------

JonnyMac

October 22, 2015, 07:28:47 PM #2 Last Edit: October 22, 2015, 07:34:09 PM by JonnyMac
Easy-peasy: You just have to ask the AP-16+ what's happening. It returns a status byte that will indicate if it's playing.  Here's the adjusted code.

' =========================================================================
'
'   File......      Witch jumper
'   Purpose...      Jump up with sound (witch's cackle)
'   Author....      Steve
'   E-mail....
'   Started...      10/20/2015
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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



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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Cylinder        = PIN0                  ' activate air cylinder


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  status          = B0                    ' status (B0 for bit access)
SYMBOL   playing        = BIT7                  ' 0 = idle, 1 = playing

SYMBOL  timer           = B2                    ' for debounce loop


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

Power_Up:
  PAUSE 3000                                    ' let AP-16+ initialize

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00111111                              ' P5..P0 are outputs

  PAUSE 30000                                   ' PIR warm-up/delay


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

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  PAUSE 5                                       ' scan delay
  IF Trigger = TrOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer

  SEROUT Sio, Baud, ("!AP16", %00, "PS", 1, 1)  ' start audio

  Cylinder = IsOn                               ' activate cylinder

Audio_Wait:
  PAUSE 50
  SEROUT Sio, Baud, ("!AP16", %00, "G")         ' request status
  SERIN  Sio, Baud, status                      ' get it from AP-16+
  IF playing = Yes THEN Audio_Wait              ' check playing bit
    GOTO Reset


If you're going to use:

  Cylinder = IsOn

...then Cylinder must be defined as a bit variable, e.g., PIN0.

If you want to use:

  HIGH Cylinder

Then Cylinder must be a constant value for the pin number, e.g., 0.

Both styles have merit; I always try to write code that reads like English so I prefer the Cylinder = IsOn style, but some commands (like SEROUT) require a pin constant (0) versus a pin variable (PIN0).
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Looks like we posted at the same time! -- and have the same (ish) code.
Jon McPhalen
EFX-TEK Hollywood Office

aquawilly54

Something must be clicking because this actually makes sense to me now.   :)
Thank you.




If you're going to use:

  Cylinder = IsOn

...then Cylinder must be defined as a bit variable, e.g., PIN0.

If you want to use:

  HIGH Cylinder

Then Cylinder must be a constant value for the pin number, e.g., 0.

Both styles have merit; I always try to write code that reads like English so I prefer the Cylinder = IsOn style, but some commands (like SEROUT) require a pin constant (0) versus a pin variable (PIN0).

JonnyMac

Jon McPhalen
EFX-TEK Hollywood Office

aquawilly54

Yup.  Read that last night.  7 or 8 more times and I'll have it.  :)

I didn't get my learning in this past year, so now I'm committed.  This stuff is just too cool to let it sit for 11 months at a time.
Thank you.

Steve

JonnyMac

In fact, you're right: it takes most people 5 to 7 exposures to new information before it sinks in.
Jon McPhalen
EFX-TEK Hollywood Office