November 21, 2024, 04:33:00 PM

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.


Electric Chair revised

Started by norm, October 26, 2010, 08:08:31 PM

Previous topic - Next topic

norm

Hi Jon,

Here is the electric chair program you wrote for me in 2007, and it works great. However I should have mentioned that the flashing light is a real flashing light. The output only has to be a "on" signal to a relay.

'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


' Electric Chair:
' PIR sensor trips, flashing light on 5 sec., after 2 second delay
' body in electric chair moves back and forth very rapidly via
' pneumatics, I have double acting cylinders connect between the
' shoulder's and arms operated by a 5-way valve. I only need to signal
' the SPDT relay on and off in 1 second intervals. ( I would like to
' be able to change the rate of the intervals during the total cycle)
' after initial 5 sec. everything shuts off. wait 30 sec. to repeat cycle.


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


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

SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  Body            = PIN1                  ' valve to V+/OUT1
SYMBOL  Light           = PIN0                  ' relay to V+/OUT0


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

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

SYMBOL  IsOpen          = 1
SYMBOL  IsClosed        = 0

SYMBOL  IsUp            = 1
SYMBOL  IsDown          = 0

SYMBOL  LightDelay      = 500                   ' change every 500 ms


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

SYMBOL  idx             = B2                    ' loop control
SYMBOL  flashTm         = W3                    ' light flash timer
SYMBOL  timer           = W4                    ' for PIR debounce/timing
SYMBOL  lottery         = W5                    ' random number


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

Reset:
  PINS = %00000000                              ' clear outputs
  DIRS = %00000011                              ' set output pins (P0..P1)

  PAUSE 20000                                   ' warm-up/inter-show delay
  timer = 0                                     ' clear for PIR debounce


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

Main:
  RANDOM lottery                                ' stir random number
  PAUSE 10
  timer = timer + 10 * PIR                      ' advance/clear timer
  IF timer < 250 THEN Main                      ' wait for valid signal


  timer = 0
  flashTm = 0

Flasher:
  Light = Light ^ 1                             ' flip light output

Flash_Hold:
  PAUSE 50
  timer = timer + 50
  IF timer >= 2000 THEN Shock_Me
  flashTm = flashTm + 50
  IF flashTm < LightDelay THEN Flash_Hold
    flashTm = 0
    GOTO Flasher


Shock_Me:
  timer = 0
  flashTm = 0

Dr_Shocker:                                     ' aka Dan Roebuck!
  RANDOM lottery
  Body = lottery
  PAUSE 50

Check_Light_Timer:
  flashTm = flashTm + 50
  IF flashTm < LightDelay THEN Check_Shock_Timer
    Light = Light ^ 1
    flashTm = 0

Check_Shock_Timer:
  timer = timer + 50
  IF timer < 5000 THEN Dr_Shocker
    PINS = %00000000                            ' clear outputs


Long_Delay:
  PAUSE 10000                                   ' 10 seconds

  GOTO Reset


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


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


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


Thanking you

JonnyMac

October 26, 2010, 09:33:35 PM #1 Last Edit: October 26, 2010, 09:35:28 PM by JonnyMac
Not sure I understand you.  This update turns on the light relay (for the entire 5s cycle) while pulsing the body output after the 2s point through the end.

BTW, Dan Roebuck is a friend of mine.

'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


' Electric Chair:
' PIR sensor trips, flashing light on 5 sec., after 2 second delay
' body in electric chair moves back and forth very rapidly via
' pneumatics, I have double acting cylinders connect between the
' shoulder's and arms operated by a 5-way valve. I only need to signal
' the SPDT relay on and off in 1 second intervals. ( I would like to
' be able to change the rate of the intervals during the total cycle)
' after initial 5 sec. everything shuts off. wait 30 sec. to repeat cycle.


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


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

SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  Body            = PIN1                  ' valve to V+/OUT1
SYMBOL  Light           = PIN0                  ' relay to V+/OUT0


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

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

SYMBOL  IsOpen          = 1
SYMBOL  IsClosed        = 0

SYMBOL  IsUp            = 1
SYMBOL  IsDown          = 0

SYMBOL  LightDelay      = 500                   ' change every 500 ms


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

SYMBOL  idx             = B2                    ' loop control

SYMBOL  flashTm         = W3                    ' light flash timer
SYMBOL  timer           = W4                    ' for PIR debounce/timing
SYMBOL  lottery         = W5                    ' random number


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

Reset:
 PINS = %00000000                              ' clear outputs
 DIRS = %00000011                              ' set output pins (P0..P1)

 PAUSE 20000                                   ' warm-up/inter-show delay



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

Main:
 timer = 0                                     ' reset timer

Check_Trigger:
 RANDOM lottery
 PAUSE 5                                       ' loop pad
 timer = timer + 5 * PIR                       ' update timer
 IF timer < 250 THEN Check_Trigger             ' wait for 0.25 sec input

 timer = 0
 Light = IsOn

Dr_Shocker:                                     ' aka Dan Roebuck!
 PAUSE 50
 timer = timer + 50
 IF timer < 2000 THEN Dr_Shocker

Shock_Me:
 RANDOM lottery
 Body = lottery
 IF timer < 5000 THEN Dr_Shocker
   PINS = %00000000

Long_Delay:
 PAUSE 10000                                   ' 10 seconds

 GOTO Reset


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


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


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