November 21, 2024, 06:20:01 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


????clueless with programing????

Started by goober, May 11, 2008, 09:53:25 PM

Previous topic - Next topic

goober

I've got a Prop-2 starter kit and have no idea how to program it. Is there a chart out there with a list of codes. And where can I find a programing guide for idiots?
All the props I've done so far run on valves, relays, lazer sensors, and preprogramed timers.
Thanks, John 801-792-3672

JonnyMac

The definitive guide to PBASIC keywords is the Parallax "manual" which is available online in the BASIC Stamp Editor Help file.  Don't start there, though, start with this document to start to get familiar with what you'll actually use in your prop projects:

-- http://www.efx-tek.com/downloads/prop-2_programming_basics.pdf

The key to writing a program is defining what you need the program to do... until you know the destination, you can't get there.
Jon McPhalen
EFX-TEK Hollywood Office

livinlowe

Programming is not all that hard (thanks to Jon). I would say, if you glance at some of the post on this board, you will very quickly learn what you want to do. Were all here to learn and help, just ask!  ;D
Shawn
Scaring someone with a prop you built -- priceless!

goober

I'm using a prop-2 controller and this is what I would like my prop to do:

pin 15, sensor input activated
out 0, spot light relay on 62sec
out 1, motor relays on 60sec
out 2, fog machine relay on 60sec while cycling 10 times (4sec on & 2 sec off)
program off for 60sec before resetting

This is my attempt so far:

'_____(program code)______________________________

main:
  DO WHILE (trigger = ison) ' run when button pressed
        HIGH thepin out 0 ' spot light relay on
        PAUSE 62000  ' hold
        LOW  thepin out 0 ' spot light relay off
         
      HIGH thepin out 1 ' motor relays on
      PAUSE 60000 ' hold
      LOW thepin out 1 ' motor relays off

        FOR reps = 1 TO 10 'fog cycles
          HIGH thepin out 2  ' fog relay  on
          PAUSE 4000 ' hold
          LOW 2000 ' fog relay off
      NEXT 
     Low thepin out 0 to out 2 ' program off
     PAUSE 60000
        LOOP
    GOTO main

JonnyMac

The listing below shows how I would approach this program -- study it and expand on it as you need.  Note that while PBASIC is very free-form and allows virtually any style (so long as the syntax is correct), the style I use makes the program easy to read, follow, and maintain.

I use P14 for the trigger input so that I have P15 available for serial devices (AP-8, etc.) should I choose to add them later.

' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              see: http://creativecommons.org/licenses/by/3.0/us/
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Trigger         PIN     14                      ' SETUP = DN
Fogger          PIN      2
Motor           PIN      1
Spotlight       PIN      0


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

IsOn            CON     1
IsOff           CON     0


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

timer           VAR     Byte                    ' for trigger debouncing
cycles          VAR     Byte


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

Reset:
  OUTL = %00000000                              ' clear P0..P7
  DIRL = %00000111                              ' make P0..P2 outputs


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

Main:
  timer = 0                                     ' reset timer
  DO WHILE (timer < 100)                        ' wait for valid trigger
    PAUSE 5                                     ' loop pad
    timer = timer + 5 * Trigger                 ' update timer value
  LOOP

  Spotlight = IsOn
  Motor = IsOn

  ' fogger cycling creates 60-second delay

  FOR cycles = 1 TO 10
    Fogger = IsOn
    PAUSE 4000
    Fogger = IsOff
    PAUSE 2000
  NEXT

  Motor = IsOff
  SpotLight = IsOff

  PAUSE 60000

  GOTO Main


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


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


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

goober

How would I change the program to run a RC-4 relay board instead of block relays?
Also how do I attach a Scary Terry audio board/player?

JonnyMac

Here you go.  If you use V+ and GND to power the Scary Terry audio board then all you have to do is connect OUT0 to the trigger input of the ST board.

' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              see: http://creativecommons.org/licenses/by/3.0/us/
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Sio             PIN     15                      ' No ULN, SETUP = Out
Trigger         PIN     14                      ' SETUP = DN
Audio           PIN      0                      ' use OUT0 to ST audio bd


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

IsOn            CON     1
IsOff           CON     0


#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T38K4       CON     45
  #CASE BS2PX
    T2400       CON     1646
    T38K4       CON     84
#ENDSELECT

SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000
Baud            CON     Open + T38K4            ' B/R jumper is installed


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

relays          VAR     Byte
spotLight      VAR     relays.BIT0             ' K1
motor          VAR     relays.BIT1             ' K2
fogger         VAR     relays.BIT2             ' K3

timer           VAR     Byte                    ' for trigger debouncing
cycles          VAR     Byte


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

Reset:
  OUTS = %00000000                              ' clear pins
  DIRS = %00000001                              ' make P0 an output

  relays = %0000
  SEROUT Sio, Baud, ["!!!!!!RC4", %00, "X"]     ' clear RC-4

  PAUSE 60000


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

Main:
  timer = 0                                     ' reset timer
  DO WHILE (timer < 100)                        ' wait for valid trigger
    PAUSE 5                                     ' loop pad
    timer = timer + 5 * Trigger                 ' update timer value
  LOOP

  Audio = IsOn
  PAUSE 25
  Audio = IsOff

  spotlight = IsOn
  motor = IsOn
  GOSUB Update_RC4

  ' fogger cycling creates 60-second delay

  FOR cycles = 1 TO 10
    fogger = IsOn
    PAUSE 4000
    GOSUB Update_RC4
    fogger = IsOff
    PAUSE 2000
    GOSUB Update_RC4
  NEXT

  GOTO Reset                                    ' reset everything


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

' Assumes RC-4 A0 and A1 jumpers are removed

Update_RC4:
  SEROUT Sio, Baud, ["!RC4", %00, "S", relays]
  RETURN

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


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

goober

I need to make an adjustment to the program code. How do I do it?
The foger (K3 on RC-4) cycles for the 60sec but the rest of the program does not stop.

JonnyMac

Okay, I'm confused....  please help me by describing what you want the prop to do again.  Describe in very layman's terms, as if I was looking at it and had no idea how it operated.  Tell me exactly when things go on, how long they run, and when they go off.  And if things are happening at the same time, I need to know that as well.
Jon McPhalen
EFX-TEK Hollywood Office

goober

I think I have a bug somewhere. It took awhile to get the program to run.
The prop starts and after 60sec the fogger relay turns off but the other two relays keep going until I unplug the prop.
The foggers time is also backwards. It runs for 2sec and off for 4sec. Which is strange because the program is wrighten right.
I tweeked the program with "IsOff" for the two relays and added a fourth relay command for skull eyes.
I hope I did it right. It downloaded fine but nothing is running yet. The LEDs are lit on the Prop-2 board but the RC-4 isn't responding.

I have a cable running from P15 to the RC-4 ser pins
Baud pin has a jumper
No jumper on A1 or A0
Prop-2 setup pin P15 & P14 have jumpers

Am I over looking somthing?

' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              see: http://creativecommons.org/licenses/by/3.0/us/
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Sio             PIN     15                      ' No ULN, SETUP = Out
Trigger         PIN     14                      ' SETUP = DN
Audio           PIN      0                      ' use OUT0 to ST audio bd


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

IsOn            CON     1
IsOff           CON     0


#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T38K4       CON     45
  #CASE BS2PX
    T2400       CON     1646
    T38K4       CON     84
#ENDSELECT

SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000
Baud            CON     Open + T38K4            ' B/R jumper is installed


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

relays          VAR     Byte
spotLight      VAR     relays.BIT0             ' K1
motor          VAR     relays.BIT1             ' K2
fogger         VAR     relays.BIT2             ' K3
eyes           VAR     relays.BIT3             ' K4

timer           VAR     Byte                    ' for trigger debouncing
cycles          VAR     Byte


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

Reset:
  OUTS = %00000000                              ' clear pins
  DIRS = %00000001                              ' make P0 an output

  relays = %0000
  SEROUT Sio, Baud, ["!!!!!!RC4", %00, "X"]     ' clear RC-4

  PAUSE 60000


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

Main:
  timer = 0                                     ' reset timer
  DO WHILE (timer < 100)                        ' wait for valid trigger
    PAUSE 5                                     ' loop pad
    timer = timer + 5 * Trigger                 ' update timer value
  LOOP

  Audio = IsOn
  PAUSE 25
  Audio = IsOff

  spotlight = IsOn
  PAUSE 60000
  spotlight = IsOff
  motor = IsOn
  PAUSE 60000
  motor = IsOff
  eyes = IsOn
  PAUSE 60000
  eyes = IsOff

  GOSUB Update_RC4

  ' fogger cycling creates 60-second delay

  FOR cycles = 1 TO 10
    fogger = IsOn
    PAUSE 4000
    GOSUB Update_RC4
    fogger = IsOff
    PAUSE 2000
    GOSUB Update_RC4
  NEXT

  GOTO Reset                                    ' reset everything


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

' Assumes RC-4 A0 and A1 jumpers are removed

Update_RC4:
  SEROUT Sio, Baud, ["!RC4", %00, "S", relays]
  RETURN

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


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

goober

My prop is a witch riding a broom.
I have a spot light that will come on and light her up. Under her dress is a fogger which puts fog out the end of the broom. Her head moves up & down, And back & forth. Her eyes are yellow LEDs that fade  off & on. Her arm goes up & down waving a wand which has an LED cluster on the end and they change colors. (Her head has A Scary Terry audio board that run the mouth and sound)

JonnyMac

You are encountering the most difficult aspect of programming: describing the program in terms that translate to code.  Please update your description to make everything step-by-step and include the amount of time each step takes.
Jon McPhalen
EFX-TEK Hollywood Office

goober

Ok, I'm getting closer. I rewrote the program and now I have one problem.
Everything works except I can't seem to get the fogger relay to cycle the 4sec On & 2sec Off for the 60sec that everything else is running. I've tried subroutines but couldn't quit get it to work right.
Here's my new attempt at this:

' =========================================================================
'   File...... Witch with prop-2 & RC-4 board
'   Purpose... Prop control
'   Author.... Goober
'   E-mail.... nfli_today@earthlink.net
'   Started...5-15-08
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
' =========================================================================

' -----[ Program Description ]---------------------------------------------
'
' Prop is a witch riding a broom.
'A spot light will shine on her.
'Under her dress is a fogger which puts fog out the end of her broom.
'Her head moves up & down, AND back & forth.
'Her eyes are yellow LEDs that fade off & ON.
'Her arm goes up & down waving a wand which has an LED cluster on the end that changes colors.
'Her head has A Scary Terry audio board that run the mouth AND sound.
'
'
' -----[ I/O Definitions ]-------------------------------------------------

TX              PIN     15                      ' serial I/O to RC-4
Trigger          PIN     14                      ' lazer sensor
Audio            PIN      0                        ' ST audio board & fading eyes

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

Baud            CON     $8000 | 6               ' OT38400

Yes             CON     1
No              CON     0

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

RELAYs          VAR     Byte             ' K1 relay (Motors)
    wand        VAR      relays.BIT1     ' K2 relay
    fogger       VAR     relays.BIT2     ' K3 relay
    spotlight    VAR     relays.BIT3     ' K4 relay

cycles         VAR     Byte

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

  Reset:

  DIRS = %00000001   ' make P0 an output



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

Main:

  SEROUT TX, Baud, ["!RC4", %00, "X"]  'resets RC4 board

  IF (Trigger = No) THEN Main        ' wait for "victim"

PAUSE 1000                    '1sec hesitation after triggers tripped
audio = yes                    'activates out0, ST board
relays = yes '(motors)         'K1 relay
    wand = yes                  'K2 relay
    fogger = yes                'K3 relay
    spotlight = yes             'K4 relay

SEROUT TX, Baud, ["!RC4", %00, "s", relays]
PAUSE 60000                      ' RC4 runs 60sec
audio = no                       'deactivates out0

  GOTO Main                        ' back to Main



livinlowe

TRY THIS


FOR CYCLES = 1 TO 10
SEROUT TX, Baud, ["!RC4", %00, "s", relays]
PAUSE 4000                      ' RC4 runs  4 sec
FOGGER = NO
SEROUT TX, Baud, ["!RC4", %00, "s", relays]
PAUSE 2000
FOGGER = YES
NEXT
audio = no                       'deactivates out0
Shawn
Scaring someone with a prop you built -- priceless!

goober

Thanks,
That worked great. It was the missing link to finishing my prop.