November 05, 2024, 12:48:43 AM

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.


Thrashing Coffin

Started by Lotus, June 29, 2008, 05:48:29 PM

Previous topic - Next topic

Lotus

might of been i just ordered another sensor to see if thats the problem

Lotus

Sorry to bring this post back to the top but I have noticed that it seems that sometimes the coffin lids stays open for far to long and I was wondering how I could reduce that in the code

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


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


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


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

SYMBOL  Trigger         = PIN6                  ' P6; SETUP = DN
SYMBOL  Fogger          = PIN2                  ' V+/OUT2
SYMBOL  Coffin          = PIN1                  ' V+/OUT1



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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  IsUp            = 1
SYMBOL  IsDown          = 0


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

SYMBOL  delay           = W3
SYMBOL  timer           = W4
SYMBOL  lottery         = W5                    ' random value


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00000111                              ' make P0-P2 outputs


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery                                ' stir random number
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

  Fogger = IsOn                                 ' fog it up
  PAUSE 5000
  Fogger = IsOff
  timer = 0

Bounce_Lid:
  RANDOM lottery
  delay = lottery // 751 + 250
  Coffin = 1 - Coffin                           ' toggle coffin output
  PAUSE delay
  timer = timer + delay
  IF timer < 16500 THEN Bounce_Lid
    Coffin = IsDown

Long_Delay:
  PAUSE 60000
  PAUSE 60000

  GOTO Main


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


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


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


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

JonnyMac

This is the line that sets the random timing for the lid:

delay = lottery // 751 + 250

By design it will give you a time from 0.25 seconds to one full second.  What would you like those times to be?
Jon McPhalen
EFX-TEK Hollywood Office

Lotus

Quote from: JonnyMac on August 25, 2008, 01:59:42 PM
This is the line that sets the random timing for the lid:

delay = lottery // 751 + 250

By design it will give you a time from 0.25 seconds to one full second.  What would you like those times to be?

Question does 751 mean 1 second and 250 mean 0.25 seconds

JonnyMac

No; the 751 when used with modulus (//) will cause the first part of that equation to return a value between 0 and 750.  When this is added to 250 you get a final output range between 250 and 1000.

You can read about that and other math tricks in this thread:
-- http://www.efx-tek.com/php/smf/index.php?topic=49.0
Jon McPhalen
EFX-TEK Hollywood Office

Lotus

so if I wanted it to be 0.25 seconds to 0.75 secs what would i do

JonnyMac

August 25, 2008, 04:30:11 PM #21 Last Edit: August 25, 2008, 04:32:29 PM by JonnyMac
delay = lottery // 501 + 250

The first part of the equation gives you a random value of 0 to 500, by adding that to 250 you get a final range of 250 (0.25s) to 750 (0.75s).
Jon McPhalen
EFX-TEK Hollywood Office

Lotus

ooooo cool thank you Jonny