November 26, 2024, 09:35:37 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.


I need a Basic Prop-1, AP-8, PIR program?

Started by mpgonline, October 23, 2007, 03:46:02 PM

Previous topic - Next topic

mpgonline

Hello,

I need a Basic Prop-1, AP-8, PIR program that will play one sound recording everytime the PIR is activated.  I am new to the BASIC Stamp programming and right now I am VERY CONFUSED.  I have tryed many of the demos but I can not get all 3 of the Prop-1, AP-8, PIR to work together.  Can anyone please help.

JonnyMac

How long is your audio?  I'll write you a program and give you notes on making connections.
Jon McPhalen
EFX-TEK Hollywood Office

mpgonline

The one I am playing with is 7 seconds.

Thanks, ya'll are awsome!!

JonnyMac

October 23, 2007, 04:12:41 PM #3 Last Edit: October 23, 2007, 04:16:28 PM by JonnyMac
Here you go:

' =========================================================================
'
'   File...... MPGOnline.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2007 EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

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


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

SYMBOL  Baud            = OT2400

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  status          = B0
SYMBOL   playing        =  BIT7                 ' 1 when AP-8 is playing

SYMBOL  timer           = B2


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

Reset:
  SEROUT Sio, Baud, ("!!!!!!!AP8", %00, "X")    ' stop audio if playing

  PAUSE 20000                                   ' PIR warm-up


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

Main:
  timer = 0                                     ' clear for PIR debounce

Scan_Pir:
  PAUSE 5
  timer = timer + 5 * PIR                       ' advance/clear timer
  IF timer < 250 THEN Scan_Pir                  ' wait for valid signal

Start_Audio:
  SEROUT Sio, Baud, ("!AP8", %00, "P", 0)

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

  GOTO Main


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


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


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


What you have to do:
  -- Record your audio into slot 0 of the AP-8
     * close the 2, 1, 0 switches when recording
     * return all switches to open for Prop-1 control

  -- Connect the AP-8 to P7 of the Prop-1
     * replace Prop-1 ULN2803 with ULN2003, or see this post for "surgical" instructions: http://www.efx-tek.com/php/smf/index.php?topic=130.0
     * remove the P7 SETUP jumper on the Prop-1
     * remove the AP-8 B/R, A1, and A0 jumpers
     * make sure you connect to the Ap-8 Serial header, and follow the wiring color codes

  -- Connect the PIR to P6 of the Prop-1
     * This doc will help: http://www.efx-tek.com/downloads/pir_docs.pdf
Jon McPhalen
EFX-TEK Hollywood Office

mpgonline

THANKS!!!  That worked and it helped me isolate what I was doing wrong.  Thanks for the great support.

JonnyMac

I rule!  ;D

{ this is a statement made by Kevin Spacey's character in the movie, American Beauty }
Jon McPhalen
EFX-TEK Hollywood Office

mpgonline

Question.  You asked me what the length of the sound file was.  Is that length placed in the stamp code?

JonnyMac

Nope; I used a feature in the AP-8 that let's me know if the audio is playing or not.  That way you can change the length of the audio (up to about 59 seconds) without changing the code.
Jon McPhalen
EFX-TEK Hollywood Office

Spooky Dad

What position should "L" be in, Open or Closed, for serial communication with the prop-1?  Attached is my code (modified from the Prop-1 Trainer code) that I have been trying to get tot work.  Can you see my problem?

' {$STAMP BS1}
' {$PBASIC 1.0}
'
' =========================================================================
' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL  Sio = 7
SYMBOL Leds = PINS ' on P0 - P5
SYMBOL Trigger = PIN6 ' active-high button
SYMBOL  Baud = OT2400                ' baud jumper out
SYMBOL  Addr = %00                   ' both address jumpers out

' -----[ Constants ]-------------------------------------------------------
SYMBOL Pressed = 1
SYMBOL NotPressed = 0

' -----[ Variables ]-------------------------------------------------------
SYMBOL stpIdx = B2 ' step index
SYMBOL delay = B4 ' fixed delay

' -----[ EEPROM Data ]-----------------------------------------------------
Pattern:
EEPROM (%000001, %000010, %000100, %001000, %010000)
EEPROM (%100000, %010000, %001000, %000100, %000010)
' -----[ Initialization ]--------------------------------------------------
Reset:
DIRS = %00111111 ' make P0 - P5 outputs
Leds = %00000000 ' clear outputs
stpIdx = 0 ' reset pointer
SEROUT Sio, Baud, ("!!!!!AP8", Addr, "X")     ' clear AP-8 outputs

' -----[ Program Code ]----------------------------------------------------
Main:
    IF Trigger = NotPressed THEN Reset ' wait for trigger button
    SEROUT Sio, Baud, ("!AP8", Addr, "P", 0)
    delay = 3000 'delay
    Cycle_Leds:
      READ stpIdx, Leds ' move step pattern to LEDs
      PAUSE delay ' hold
      stpIdx = stpIdx + 1//10 ' point to next step
      GOTO Main

JonnyMac

Spooky Dad,

We don't have a lot of rules but one of then is no thread hijacking.  Your question has nothing to do with the original topic of this thread -- please start your own thread.
Jon McPhalen
EFX-TEK Hollywood Office