November 18, 2024, 01:53:16 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.


I need a program

Started by tgkraus, February 04, 2008, 11:50:28 AM

Previous topic - Next topic

tgkraus

John,I am very new to this programming. I want a program like this one,Mourning (and screaming!) Bride by Chris Bartram, But I want the eyes on first then the scream. Iam building a version of this prop. Thanks Chris for a great prop

P.S. Can I use a photo electric Sensor on a prop 1 controller?

JonnyMac

Tihm,

We all start off as "new" -- the good news is that you're starting early and not waiting until October to learn to program.

Can you point me to Chris's prop?  Do you have a web link? (My favorite line from Jerry Maguire is: Help me help you.)

As to your sensor, you probably can use it be we'll need to know some details so we can tell you how to hook it up to the Prop-1.  What kind of output?  Open-collector?  Dry contact?  Do you have spec sheet you can point me to?
Jon McPhalen
EFX-TEK Hollywood Office

tgkraus

Chris's prop I found on your completed projects  page.Dec.3 2007

The sensor in question if you go to Graingers web site the part # is 5B168. www.grainger.com

JonnyMac

Please... don't make me go hunting -- I've got a lot of things happening and if you will provide direct links to the projects and products you want me to help you with, I can and will.
Jon McPhalen
EFX-TEK Hollywood Office


JonnyMac

You can use that sensor as it has dry contacts.

On the program... have you asked Chris for a copy of it?  That might be quicker than me trying to figure out what his program is doing.  Now, if you want to watch the video and then tell me what you need the program to do... something like this:

Play moaning audio while waiting for sensor
On sensor detection
  -- scream
  -- turn head
  -- flash eyes
Go back to beginning

Honestly, reverse-engineering is a very subjective thing and it would be better for you to tell me exaclty what you want your prop to do.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

February 04, 2008, 05:01:44 PM #6 Last Edit: February 04, 2008, 05:03:44 PM by JonnyMac
Okay, here's a starter program based on how I interpret that video.  If you see it differently, then you'll need to modify the code (yes, I'll help, but you'll have to specify any changes you want).

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


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


' -----[ Revision History ]------------------------------------------------
'
' Notes:
' -- AP-8 should have 15 second "moan" track in slot 7
'    * software assumes Rev D board with soft looping feature
'
' -- Trigger is normally-open, dry-contact
'    * connect between P6.R and P6.W


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Eyes            = 1
SYMBOL  Servo           = 0                     ' for head


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

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

SYMBOL  Baud            = OT2400


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

SYMBOL  pos             = B2                    ' servo position
SYMBOL  idx             = B3                    ' loop controller
SYMBOL  flash           = B4

SYMBOL  timer           = W4                    ' trigger and event timing
SYMBOL  lottery         = W5                    ' random value


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

Reset:
  PINS = %00000000                              ' clear outputs
  DIRS = %00000011

  pos = 200                                     ' idle position

  SEROUT Sio, Baud, ("!AP8", %00, "X")          ' kill audio
  FOR idx = 1 TO 5
    GOSUB Refresh_Servo
  NEXT

  ' Soft looping works only with Rev D of AP-8
  '
  SEROUT Sio, Baud, ("!AP8", %00, "L", 7, 0)    ' loop until trigger


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

Main:
  RANDOM lottery                                ' stir random value
  GOSUB Refresh_Servo                           ' refresh the servo
  timer = timer + 1 * Trigger                   ' update/debounce trigger
  IF timer < 10 THEN Main                       ' hold for 0.2 sec trigger

Scream:
  SEROUT Sio, Baud, ("!AP8", %00, "P", 0)       ' play scream track

Turn_Head:
  pos = 100                                     ' turn the head
  GOSUB Refresh_Servo

  timer = 0                                     ' clear timer for eyes

Flash_Eyes:
  RANDOM lottery                                ' re-randomize
  GOSUB Refresh_Servo
  TOGGLE eyes                                   ' toggle eye state
  flash = lottery // 21 + 5                     ' flash 0.1 to 0.5 secs
  FOR idx = 1 TO flash
    GOSUB Refresh_Servo
    timer = timer + 20
  NEXT
  IF timer < 20000 THEN Flash_Eyes              ' flash for ~20 secs
    GOTO Reset


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

' Update servo and create 20 ms delay in program

Refresh_Servo:
  PULSOUT Servo, pos
  PAUSE 20
  RETURN

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


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

tgkraus

Thanks John for the program. I also got Chris's' program. With the two I was able to tweak it through trial and error to achieve the action I wanted. Thanks again.

JonnyMac

Excellent.  Once you have things working you may want to save an archival version of the program so that you can get back to it if you need.  Now... experiment!  That's the best way to learn.  Just play, play, play!
Jon McPhalen
EFX-TEK Hollywood Office

tgkraus

John, I was wondering if you could help modify this program to use your ir sensor and the ap-8 ???

' {$STAMP BS1}
' {$PBASIC 1.0}
' Program:  head-turner
' Author:   Chris Bartram
' Modified: 09/22/2007
'
' -----[ I/O Definitions ]-------------------------------------------

SYMBOL PIR=7            ' P7   = Infrared sensor
SYMBOL EYES=3           ' Out1 = LED Eyes
SYMBOL SERVO=2          ' P2   = Head turning servo
SYMBOL SoundEffect=4    ' Out4 = Chipcorder
SYMBOL COUNTER=W2
SYMBOL HeadLeft=55      ' code for servo full left
SYMBOL HeadRight=230    ' code for servo full right
SYMBOL TriggerDelay=20000 ' delay between motion detected and start
SYMBOL IdleTime=5000     ' delay between reactivations

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


DEBUG CLS                  ' Clear DEBUG Screen
FOR counter = 40 TO 0 STEP -1     ' Wait 40 Seconds For PIR Warm-Up
DEBUG "IR Ready in:", counter 'print how much time left
  PAUSE 1000               ' Display Counter Every Second
DEBUG CLS                  ' Clear DEBUG Screen
NEXT

Restart:
counter = 0                ' Clear Counter Variable

'   DEBUG "WAITING...   "      ' Display Waiting Message

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

WaitForMotion:
    PULSOUT servo,HeadLeft
    PAUSE 25
    counter = counter + 50 * PIR
    IF counter < 250 THEN WaitForMotion              ' Motion Detected?

'   DEBUG "TRIPPED..."

PropSequence:
' motion detected, start sobbing sound (which is 20 seconds long before scream)
    HIGH Soundeffect
' wait 'triggerdelay' seconds before turning head
    FOR counter=0 TO TriggerDelay STEP 20
      GOSUB TurnHeadLeft     ' hold head in left position
      PAUSE 20
    NEXT

'DEBUG "Head Right"
' turn head right and wait 3 seconds
    counter=0
    FOR counter=0 TO 3000 STEP 20
      GOSUB TurnHeadRight
      PAUSE 20
    NEXT

'   DEBUG "Light eyes" as scream finishes
    HIGH EYES  ' light up the eyes

'   DEBUG "15 second delay..."
    counter=0
    FOR counter=0 TO 15000 STEP 20
      GOSUB TurnHeadRight
      PAUSE 20
    NEXT

    LOW EYES      ' eyes back off
'   DEBUG "Head (back) Left"
    GOSUB TurnHeadLeft ' head back left

    counter=0
    FOR counter=0 TO IdleTime STEP 20
      GOSUB TurnHeadLeft
      PAUSE 20
    NEXT

'   DEBUG "Resetting"
GOTO Restart

TurnHeadLeft:
  PULSOUT servo,HeadLeft
  RETURN

TurnHeadRight:
  PULSOUT servo,HeadRight
  RETURN ???

JonnyMac

Here's how I would do it:

' =========================================================================
'
'   File...... Head_Turner_JW.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (based on code by Chris B.)
'   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  Trigger         = PIN6                  ' SETUP = DN (for PIR)
SYMBOL  Eyes            = PIN1
SYMBOL  Servo           = 0


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

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

SYMBOL  Baud            = OT2400

SYMBOL  HeadLeft        =  55
SYMBOL  HeadCenter      = 150
SYMBOL  HeadRight       = 230

SYMBOL  TriggerDelay    = 20000
SYMBOL  IdleTime        = 5000


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

SYMBOL  pos             = B2                    ' servo position
SYMBOL  timer           = B3                    ' debounce timer
SYMBOL  delay           = W5                    ' use for PAUSE replacement


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

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

  SEROUT Sio, Baud, ("!AP8", 0, "X")            ' reset player

PIR_Warmup:
  pos = HeadCenter
  delay = 20000
  GOSUB Servo_Delay

Restart:
  timer = 0                                     ' reset timer


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

Main:
  PULSOUT Servo, HeadLeft                       ' loop pad
  PAUSE 19
  timer = timer + 20 * Trigger                  ' update timer
  IF timer < 200 THEN Main                      ' wait for 0.2 sec input

  SEROUT Sio, Baud, ("!AP8", 0, "P", 0)         ' start audio

  ' delay after trigger

  pos = HeadLeft
  delay = TriggerDelay
  GOSUB Servo_Delay

  ' head right for three seconds

  pos = HeadRight
  delay = 3000
  GOSUB Servo_Delay

  Eyes = IsOn

  ' hold 15 seconds

  delay = 15000
  GOSUB Servo_Delay

  Eyes = IsOff

  ' idle

  pos = HeadLeft
  delay = IdleTime
  GOSUB Servo_Delay

  GOTO Restart


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

' Holds servo in position while creating a delay to replace PAUSE

Servo_Delay:
  IF delay = 0 THEN Delay_Exit
    PULSOUT Servo, pos
    PAUSE 18
    IF delay < 20 THEN Delay_Exit
      delay = delay - 20
      GOTO Servo_Delay

Delay_Exit:
  RETURN

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


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


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

tgkraus

John, That program looks good. Can you draw up a visual diagram how are these components will attach to the prop 1. What does SYMBOL Sio mean? What chip should I be using? 
Can you suggest a book to help me learn?
--------------------------------------------------------------------------------

livinlowe

Symbol Sio = 7 is just assigning the number 7 to the variable Sio. The reason it isn't =pin7 is because this command: SEROUT Sio, Baud, ("!AP8", 0, "X") wants a number, not pin7. I am not sure what you mean by what chip, so I can't help there. As far as a book, I just read through the various posts and did a little experimenting. It's not too bad picking up good ideas as jon is an excellent programmer!

Hope this helps         
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

All of the syntax is explained, with examples, in the BASIC Stamp manual and help file. 

Also, Scott Edwards wrote a book called "Programming and Customizing the BASIC Stamp Computer" that you may be able to find on Amazon.  Until you get it, you might want to read through Nuts & Volts articles written by Scott Edwards and myself.  I will list them in another thread.
Jon McPhalen
EFX-TEK Hollywood Office