November 22, 2024, 06:49:24 PM

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.


Can you check my program....

Started by john@thedevils-den, September 22, 2007, 08:05:59 PM

Previous topic - Next topic

john@thedevils-den

 I think its very simple for what you guys are used to, just can't seem to get it past the Syntax error check. Here is what I am trying to accomplish.
1. Patrons walk into room with a lamp on and a sofa with a body laying on it. I need to wait until everybody is in the room ( about 30 Seconds) and then the lamp goes out for 2 seconds, while the lamp is out, the fogger comes on and the sofa flips over hiding the body on it, then the fogger goes off and the lamp comes back on,but the sofa needs to remain on for the remaining 2-5 minutes until everybody is out of the room and then everything resets. If you have a second, check this and let me know where I am going wrong.....thanks.


' {$STAMP BS1}
           ' =========================================================================
'
'   File...... SofaScare.bs1
'   Purpose...
'   Author.... john.sbandi@thedevils-den.com
'   E-mail.... same
'   Started...9/22/07
'   Updated...
'
'   { BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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

' Notes:
' -- move P6 SETUP jumper to DN position


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


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

SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  Flip1           = PIN5                  ' for sofa flip
SYMBOL  Lamp            = PIN2                  ' room lighting
SYMBOL  Fogger          = PIN1                  ' fog machine
SYMBOL  Bookcase        = PIN0


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

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


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



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

Reset:
  PINS = %00000000                              ' clear everything
  DIRS = %00000100                              ' configure output pins



  PAUSE 20000                                   ' let PIR stabilize
  timer = 0                                     ' clear timer for PIR

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

Main:
  PAUSE 10
  timer = timer + 10 * PIR                      ' update PIR timer
  IF timer < 250 THEN Main                      ' wait for valid signal

  PAUSE 5000
  Lamp = IsOff
  PAUSE 2000

  Fogger = IsOn
  PAUSE 5000

  Flip = IsOn
  PAUSE 20000

  Lamp = IsOn

  Fogger = IsOff

  Flip = IsOff

  GOTO Reset

john@thedevils-den

The syntax error is said to be in the Initialization, it is looking for a


: symbol by the "timer = 0" but when I plug it in, its looking for another command???
Not sure on this one...probably something simple..

john@thedevils-den

OK I kind of figured it out....... I didnt label the timer and I didnt label the flip commands properly. I need to read some more as I dont understand using variables in the programming. Do you have any advice on the variables in prop1 programming? What is the purpose of having the variables......

JonnyMac

Many programs can be written without variables, but even simple programs benefit from having them.  Let's say that you wanted to flash an LED 10 times.  You could write out the flash code and then copy it nine more times, or you could use a loop construct; FOR-NEXT is the most appropriate for this.  Like this:

Flasher:
  FOR idx = 1 TO 10
    HIGH Led
    PAUSE 100
    LOW Led
    PAUSE 100
  NEXT


FOR-NEXT requires a control value that can change -- a variable.  At the beginning of the process the variable called idx is set to one.  Then the loop code (the stuff that does the flashing).  When the code hits next the value of idx will be compared to 10; if it's 10 then the line after NEXT runs, otherwise one is added to idx and the program jumps back to the first line of the flash code.

In programs we have two kinds of values: contants: values that are fixed, and variables: values that change.

The BASIC Stamp Editor help file has a good write-up on memory usage and variables.

Jon McPhalen
EFX-TEK Hollywood Office

john@thedevils-den

Thanks for the help.......

I have fixed the program, but once I download it onto my prop1, nothing happens........I put the trainer on there to see the LEDs flash, but nothing happens. I plugged in the PIR sensor onto the trainer and nothing...Is it the program, or did I goof somewhere.......
I figure that as soon as I turn on power I should have an LED on at PIN 2 showing that the room lighting is on.....do I need to use the ULN2003 also when using the PIR sensor?

JonnyMac

Study this version -- I think it does what you want.  Note the changes in PINS and DIRS in the reset section.  A "1" in a PINS bit makes it high (on) when there is also a "1" in the DIRS bit (that's where most of your problems were).  You might want to spend some time playing with short demo programs to ensure you really have a handle on PINS and DIRS.  Also, you could use much shorter timing (divide by 10) for testing, then -- when it's all working -- go back and set the actual times.

' =========================================================================
'
'   File...... SofaScare.bs1
'   Purpose...
'   Author.... john.sbandi@thedevils-den.com
'   E-mail.... same
'   Started... 9/22/07
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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

' Notes:
' -- move P6 SETUP jumper to DN position


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


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

SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  Flip            = PIN5                  ' for sofa flip
SYMBOL  Lamp            = PIN2                  ' room lighting
SYMBOL  Fogger          = PIN1                  ' fog machine
SYMBOL  Bookcase        = PIN0


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

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


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

SYMBOL  timer           = B2                    ' for PIR debouncing


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

Reset:
  PINS = %00000100                              ' lamp on, others off
  DIRS = %00100111                              ' configure output pins

  PAUSE 20000                                   ' let PIR stabilize
  timer = 0                                     ' clear timer for PIR

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

Main:
  PAUSE 10
  timer = timer + 10 * PIR                      ' update PIR timer
  IF timer < 250 THEN Main                      ' wait for valid signal

  PAUSE 5000
  Lamp = IsOff
  PAUSE 2000

  Fogger = IsOn
  PAUSE 5000

  Flip = IsOn
  PAUSE 20000

  Lamp = IsOn
  Fogger = IsOff
  Flip = IsOff

  GOTO Reset
Jon McPhalen
EFX-TEK Hollywood Office