November 27, 2024, 05:14:03 AM

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.


Prop 1 RC4, FC4 and PIR

Started by chuckb0004, September 21, 2009, 10:03:04 AM

Previous topic - Next topic

chuckb0004

Wondering if there is a more compact way to write a program that will do the following utilizing a Prop 1.

1. Control an FC4 board to fade in and out three lighting circuits.
2. Control an RC4 board to turn on a fan and a FCG.
3. Control two 12vdc solenoids for a pnuematic prop and 1 12VDC relay that triggers a VSA program that controls a 3 axis skull, this is done by energizing a 12VDC relay with n/o contacts.
5. Numbers 1 and 2 will be timed with the VSA routine along with the two pnuematic solenoids.
6. A PIR will trigger the prop1 that will energize the 12VDC relay and this in turn will trigger the VSA routine via hellsman.

I started to write the program by simply serout comands with different lenth pause comands for timing and it was working flawlessly that is unitl I got the EEMPROM FULL MESSAGE halfway through the program. I was wondering if there is a different approach at writing this program.

JonnyMac

Subroutines are your friend.  If you post your code (the one that runs out of EEPROM) I can show you how to optimize it.
Jon McPhalen
EFX-TEK Hollywood Office

chuckb0004

Here is the program at the point when I got the eeprom full message.

JonnyMac

As it turns out, you're trying to stuff a lot of code into a little tiny controller.  My first version, using subroutines, actually used a little more memory than yours.  What I did then is removed unnecessary variable assignments.  Since the fade channel, start level, stop level, and step timing are stored by the program now, you don't have to re-assign a variable if it's already holding the correct value.  I didn't erase anything, I just removed the assignments via commenting.

This recovers a little memory, but not a whole lot.  You may need a Prop-2 for the memory if you show is much longer.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$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  VSA             = PIN3
SYMBOL  Skeleton        = PIN2
SYMBOL  Lid             = PIN1


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' B/R jumper removed


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

SYMBOL  relays          = B0
SYMBOL   Ghost          =  BIT0
SYMBOL   Fans           =  BIT1
SYMBOL   K3             =  BIT2
SYMBOL   K4             =  BIT3

SYMBOL  timer           = B2

SYMBOL  ch              = B4                    ' channel to fade
SYMBOL  lvlStart        = B5                    ' start level
SYMBOL  lvlStop         = B6                    ' stop level
SYMBOL  stpDelay        = B7                    ' ms per step

SYMBOL  delay           = W5


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

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

  SEROUT Sio, Baud, ("!FC4", %00, "X")
  PAUSE 2000
  relays = %0000
  GOSUB Set_RC4
  PAUSE 10000


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  PAUSE 10                                      ' loop pad
  timer = timer + 10 * Trigger                  ' update timer
  IF timer < 200 THEN Check_Trigger             ' wait for 0.2 sec input


Run_Show:
  VSA = IsOn
  PAUSE 25

  ch = 1
  lvlStart = 0
  lvlStop = 255
  stpDelay = 20
  GOSUB Fade_FC4

  VSA = IsOff
  PAUSE 8000

  ch = 2
' lvlStart = 0
' lvlStop = 255
' stpDelay = 20
  GOSUB Fade_FC4
  PAUSE 11000

' ch = 2
  lvlStart = 255
  lvlStop = 0
  stpDelay = 10
  GOSUB Fade_FC4
  PAUSE 5000

  ch = 3
  lvlStart = 0
  lvlStop = 255
  stpDelay = 8
  GOSUB Fade_FC4
  PAUSE 5000

  Ghost = IsOn
  GOSUB Set_RC4

  ch = 1
  lvlStart = 255
  lvlStop = 0
' stpDelay = 8
  GOSUB Fade_FC4
  PAUSE 2500

' ch = 1
  lvlStart = 0
  lvlStop = 255
  stpDelay = 5
  GOSUB Fade_FC4
  PAUSE 2500

  Ghost = IsOff
  GOSUB Set_RC4

  ch = 3
  lvlStart = 255
  lvlStop = 0
  stpDelay = 8
  GOSUB Fade_FC4
  PAUSE 4000

  Fans = IsOn
  GOSUB Set_RC4
  PAUSE 4000

  ch = 1
' lvlStart = 255
' lvlStop = 0
  stpDelay = 20
  GOSUB Fade_FC4
  PAUSE 2500

  GOTO Reset


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

Fade_FC4:
  SEROUT Sio, Baud, ("!FC4", %00, "F", ch, lvlStart, lvlStop, stpDelay)
  RETURN

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

Set_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN

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


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

chuckb0004

Thanks Jon I was just at your online store looking at the prop 2. Since what I sent you was only half the show I will be ordering a prop2. One question is the prop 2 programming much different than the prop 1?

JonnyMac

PBASIC 2 is actually a little easier, most people think, as it looks and feels more like PC-oriend flavors of BASIC.
Jon McPhalen
EFX-TEK Hollywood Office