November 21, 2024, 10:08:40 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.


GroundBreaker Question

Started by Lotus, October 24, 2013, 08:51:32 PM

Previous topic - Next topic

Lotus

October 24, 2013, 08:51:32 PM Last Edit: October 24, 2013, 11:01:45 PM by Lotus
Hey Guys,

I took Jon's code "Hope he doesn't mind" for a thrashing loop, and edited it to just repeat after every 2 minutes, I tested it out but the only Pins 0 and 1 appear to work. My question is could this be because of DIRS = VALVES, if so what could I do to fix this? Still learning but I am starting to understand this  :)  Its setting off a Nerve Center just for the audio and to turn on a Spot light

Joe                           


' =========================================================================
'
'   File...... GroundBreaker
'   Purpose...
'   Author....
'   E-mail....
'   Started... October 15, 2013
'   Updated... October 24. 2013
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
'
' -----[ Revision History ]------------------------------------------------


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

SYMBOL  NerveCntr       = PIN3                  ' use OUT5 and GND
SYMBOL  LED             = PIN2                  ' Orange Lights
SYMBOL  LShoulder       = PIN1
SYMBOL  RShoulder       = PIN0


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

SYMBOL  VALVES          = %00000011             ' pins used for valves

SYMBOL  IS_ON           = 1                     ' for active-high in/out
SYMBOL  IS_OFF          = 0

SYMBOL  YES             = 1
SYMBOL  NO              = 0



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

SYMBOL  idx             = B2                    ' loop index
SYMBOL  newvalves       = B3                    ' new valve bits
SYMBOL  last            = B4                    ' last valve outputs

SYMBOL  delay           = W3                    ' cycle delay (ms)
SYMBOL  timer           = W4                    ' for debounce/run timing
SYMBOL  lottery         = W5                    ' random #


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

Power_Up:
  lottery = 1031                                ' seed random #

Reset:
  PINS = %00000000                              ' clear everything
  DIRS = VALVES                                 ' set outputs

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

Main:

  NerveCntr = IS_ON                             ' Start Nerve Center
  DEBUG "NervCntr Triggered", CR
  PAUSE 1000
  NerveCntr = IS_ON                             ' Nevre Center trigger off
  LED       = IS_ON



Jump:
  DEBUG "Ground Breaker", CR
  PINS = PINS | VALVES                          ' both on
  PAUSE 1000

  timer = 23000                                 ' thrash for 10 seconds

Thrasher:
  FOR idx = 1 TO 3
    RANDOM lottery
  NEXT
  newvalves = lottery & VALVES                  ' filter valve bits

  IF newvalves = last THEN Thrasher             ' force change
    last = newvalves                            ' save for next cycle

  PINS = PINS &/ VALVES | newvalves             ' clear old, set new
  RANDOM lottery
  delay = lottery // 251 + 100 MAX timer        ' 100 to 350ms
  PAUSE delay                                   ' hold
  timer = timer - delay                         ' update timer
  IF timer > 0 THEN Thrasher                    ' time left?
  LED = IS_OFF
         PAUSE 120000                                  ' Wait 2 minutes
         DEBUG "Times Up", CR
    GOTO Reset


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


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


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

JonnyMac

October 24, 2013, 09:30:55 PM #1 Last Edit: October 26, 2013, 03:35:15 PM by JonnyMac
I write code that you have something to start with. I do have one rule, however: If you modify one of my programs, you own,  so take my name off of it.

I only found couple "gotchas" -- the biggest being that you cannot do PAUSE 120000; the largest number that the BASIC Stamp understands is 65535, so we use PAUSE 60000 twice.

Edited: 26 OCT 2013


' =========================================================================
'
'   File...... GroundBreaker
'   Purpose...
'   Author....
'   E-mail....
'   Started... October 15, 2013
'   Updated... October 26, 2013
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
'
' -----[ Revision History ]------------------------------------------------


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

SYMBOL  NerveCntr       = PIN3                  ' use OUT3 and GND
SYMBOL  LED             = PIN2                  ' Orange Lights
SYMBOL  LShoulder       = PIN1
SYMBOL  RShoulder       = PIN0


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

SYMBOL  VALVES          = %00000011             ' pins used for valves

SYMBOL  IS_ON           = 1                     ' for active-high in/out
SYMBOL  IS_OFF          = 0

SYMBOL  YES             = 1
SYMBOL  NO              = 0



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

SYMBOL  idx             = B2                    ' loop index
SYMBOL  newvalves       = B3                    ' new valve bits
SYMBOL  last            = B4                    ' last valve outputs

SYMBOL  delay           = W3                    ' cycle delay (ms)
SYMBOL  timer           = W4                    ' for debounce/run timing
SYMBOL  lottery         = W5                    ' random #


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

Power_Up:
  lottery = 1031                                ' seed random #

Reset:
  PINS = %00000000                              ' clear everything
  DIRS = %00001111                              ' set outputs


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

Main:
  NerveCntr = IS_ON                             ' Start Nerve Center
  DEBUG "NervCntr Triggered", CR
  PAUSE 1000

  NerveCntr = IS_OFF                            ' Nevre Center trigger off
  LED       = IS_ON

Jump:
  DEBUG "Ground Breaker", CR
  PINS = PINS | VALVES                          ' both on
  PAUSE 1000

  timer = 23000                                 ' thrash for 23 seconds

Thrasher:
  FOR idx = 1 TO 3
    RANDOM lottery
  NEXT
  newvalves = lottery & VALVES                  ' filter valve bits

  IF newvalves = last THEN Thrasher             ' force change
    last = newvalves                            ' save for next cycle

  PINS = PINS &/ VALVES | newvalves             ' clear old, set new
  RANDOM lottery
  delay = lottery // 251 + 100 MAX timer        ' 100 to 350ms
  PAUSE delay                                   ' hold
  timer = timer - delay                         ' update timer
  IF timer > 0 THEN Thrasher                    ' time left?

    PINS = %00000000                            ' clear everything

Run_Delay:
  PAUSE 60000                                   ' wait 1 minute
  PAUSE 60000                                   ' wait 1 minute

  DEBUG "Times Up", CR

  GOTO Main


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


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


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

Lotus


Lotus

Hey Guys I got a question I noticed that once the program runs Pin 0 or Pin 1 stays active until it runs again then Pin 1 or 0 stays on until next time and so on, any idea?

JonnyMac

My mistake. I usually put the PIR delay in the Reset section so that everything gets cleared and then we hold -- you seemed to want the 2-minute delay at the end. I added changed two lines to fix the problem (see above).
Jon McPhalen
EFX-TEK Hollywood Office

Lotus