November 24, 2024, 01:57:25 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.


some basic questions

Started by hippofeet, September 06, 2012, 11:32:21 AM

Previous topic - Next topic

hippofeet


' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Barrel          = PIN0                  ' use V+/OUT0 for valve


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  timer           = W5                    ' for debounce loop


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

Power_Up:
  ' put code here that only happens at power-up/hard reset

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00111111                              ' P5..P0 are outputs


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

Main:
  timer = 0                                     ' reset debounce timer
  PAUSE 100
Check_Trigger:
  PAUSE 5                                      ' scan delay
  IF Trigger = TrOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer

  timer = 1 * 10                                ' set run time (2 min)

Machine_Gun:
  Barrel = IsOn
  PAUSE 50                                     ' hold 1/2 second
  Barrel = IsOff
  PAUSE 50
  timer = timer - 1                             ' update timer
  IF timer = 0 THEN Reset                       ' done?
    GOTO Machine_Gun                            '  no, keep going


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


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


' -----[ User Data ]-------------------------------------------------------
This one sort of works. I inserted a pause at the beginning, and as long as you are jumped at the trigger, it pauses, runs through the firing cycle, starts over, and pauses, then runs through. So it sounds like a machine gun firing bursts. I would like to have it pause as part of the cycle, so that it only needs to be triggered once, not held.

JackMan

September 07, 2012, 03:29:36 PM #16 Last Edit: September 07, 2012, 03:32:51 PM by JackMan
Give this a try. It will give you 2 second bursts with a 2 second pause in between and run for a total of 2 minutes.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Barrel          = PIN0                  ' use V+/OUT0 for valve


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  timer           = W5                    ' for debounce loop
SYMBOL idx                = B2

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

Power_Up:
  ' put code here that only happens at power-up/hard reset

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00111111                              ' P5..P0 are outputs


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

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  PAUSE 5                                       ' scan delay
  IF Trigger = TrOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer

  timer = 2 * 60                                ' set run time (2 min)

Machine_Gun:
FOR idx = 1 TO 20
  Barrel = IsOn
  PAUSE 50                                     ' hold 1/20 second
  Barrel = IsOff
  PAUSE 50
NEXT
  PAUSE 2000
  timer = timer - 4                             ' update timer
  IF timer = 0 THEN Reset                       ' done?
    GOTO Machine_Gun                            '  no, keep going


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


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


' -----[ User Data ]-------------------------------------------------------
[/color]

JackMan

Here's another variation that will give you a random PAUSE between bursts. It's set for 1~2 seconds which is easily adjustable in the code.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Barrel          = PIN0                  ' use V+/OUT0 for valve


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400

SYMBOL  PAUSE_MIN       =  1000                  ' min pause between bursts
SYMBOL  PAUSE_MAX       =  2000                  ' max pause between bursts
SYMBOL  RUN_TIME        =  60000                 ' 1 minute x counter value

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

SYMBOL  idx             = B2                    ' for # of blasts per burst
SYMBOL  counter         = B3                    ' for # of run times
SYMBOL  delay           = W3                    ' for random delay between bursts
SYMBOL  lottery         = W4                    ' for random delay between bursts
SYMBOL  timer           = W5                    ' for debounce loop and event time

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

Power_Up:
  ' put code here that only happens at power-up/hard reset

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00111111                              ' P5..P0 are outputs
  PAUSE 30000                                   ' 30s warm up for PIR and post delay


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

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  PAUSE 5                                       ' scan delay
  IF Trigger = TrOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer

FOR counter = 1 TO 2                           ' 2 x 60s run time (2m)
  GOSUB Machine_Gun
NEXT
   GOTO Reset

Machine_Gun:
  timer = 0                                     'reset event timer

Blast_It:
FOR idx = 1 TO 20                              ' 20 blasts per burst
  Barrel = IsOn
  PAUSE 50                                      ' hold 1/20 second (2s burst)
  Barrel = IsOff
  PAUSE 50
NEXT
  RANDOM lottery
  delay = PAUSE_MAX - PAUSE_MIN + 1
  delay = lottery // delay + PAUSE_MIN          ' caculate random delay between bursts
  PAUSE delay                                   ' pause 1 ~ 2s til next burst
  timer = timer + delay
  timer = timer + 2000                          ' update timer
  IF timer < RUN_TIME THEN Blast_It             ' no, keep going
  RETURN



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


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


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

hippofeet

Thanks to all who replied. It works great.