November 22, 2024, 04:22:31 AM

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.


Abuse Avoidance

Started by clinefx1, September 29, 2013, 05:01:49 PM

Previous topic - Next topic

clinefx1

Hi all!

So its been awhile and I'm a bit rusty but I wrote this code from scratch and it works for the most part.
The problem I'm trying to work out is letting a few triggers happen on my "IRBEAM" contact maybe 2-3 but then locking it out for a settable amount of time without crashing the program.  What am I missing? 

Thanks
Chris


' =========================================================================
'
'   File.......CLINEFX1_DRIVEWAY_ALERT-1
'   Purpose....
'   Author.....
'   E-mail.....CLINEFX1@GMAIL.COM
'   Started....
'   Updated....
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL AMBER            = PIN0
SYMBOL BEEP             = PIN1
SYMBOL CHIME            = PIN2

SYMBOL Doorbell         = PIN7       ' SETUP = DN
SYMBOL IRBEAM           = PIN6       ' SETUP = DN



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

SYMBOL  IsOn            = 1                     ' button pressed
SYMBOL  IsOff           = 0                     ' button released

SYMBOL  LedTime         = 75                    ' light-on delay time
SYMBOL CHIME_TIME       = 500
SYMBOL BEEP_TIME        = 60
SYMBOL FULL             = 2000
SYMBOL DELAY_VALUE      = 500
' -----[ Variables ]-------------------------------------------------------

SYMBOL  timer           = W5
SYMBOL COUNT            = W6


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

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00001111                              ' P3..P0 are outputs

TIMER = 2000

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

Main:

IF DOORBELL = IsOff THEN DRIVEWAY_CHECK
  GOTO DOORBELL_ACTIVE


DRIVEWAY_CHECK:
IF COUNT > 0 THEN UPDATE_COUNT
GOTO CHECK_BEAM


CHECK_BEAM:
IF IRBEAM = IsOff THEN TIMER_UPDATE
GOTO DRIVEWAY_ACTIVE

UPDATE_COUNT:
COUNT = COUNT - 1
GOTO TIMER_UPDATE

TIMER_UPDATE:
IF TIMER = 0 THEN CLEAR_ACTIVE
TIMER = TIMER - 1

GOTO MAIN

CLEAR_ACTIVE:
AMBER = ISOFF

GOTO Main


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

DOORBELL_ACTIVE:
CHIME = ISON
PAUSE 100
CHIME = ISOFF
AMBER = ISON
PAUSE CHIME_TIME
AMBER = ISOFF
PAUSE CHIME_TIME
AMBER = ISON
PAUSE CHIME_TIME
AMBER = ISOFF
PAUSE CHIME_TIME
AMBER = ISON
PAUSE CHIME_TIME
AMBER = ISOFF
PAUSE CHIME_TIME
AMBER = ISON
PAUSE CHIME_TIME
AMBER = ISOFF
PAUSE CHIME_TIME
AMBER = ISON
TIMER = FULL
GOTO MAIN

DRIVEWAY_ACTIVE:
BEEP = ISON
AMBER = ISON
PAUSE  BEEP_TIME
BEEP = ISOFF
AMBER = ISOFF
PAUSE  BEEP_TIME
BEEP = ISON
AMBER = ISON
PAUSE BEEP_TIME
BEEP = ISOFF
AMBER = ISOFF
PAUSE BEEP_TIME
BEEP = ISON
AMBER = ISON
PAUSE BEEP_TIME
BEEP = ISOFF
AMBER = ISOFF
PAUSE 500

BEEP = ISON
AMBER = ISON
PAUSE  BEEP_TIME
BEEP = ISOFF
AMBER = ISOFF
PAUSE  BEEP_TIME
BEEP = ISON
AMBER = ISON
PAUSE BEEP_TIME
BEEP = ISOFF
AMBER = ISOFF
PAUSE BEEP_TIME
BEEP = ISON
AMBER = ISON
PAUSE BEEP_TIME
BEEP = ISOFF
AMBER = ISOFF
PAUSE BEEP_TIME
PAUSE 500
AMBER = ISON

TIMER = FULL
COUNT = DELAY_VALUE * 2
GOTO MAIN
' -----[ DATA Data ]-------------------------------------------------------

JonnyMac

September 30, 2013, 06:55:52 AM #1 Last Edit: September 30, 2013, 07:11:59 AM by JonnyMac
I'm having a hard time understanding what you want from the program -- can you describe it in full, as if you didn't have code yet?

Let me show you a trick to shorten redundant code. In the Doorbell Active section you're toggling an output manually. You can't use the TOGGLE command with a PINx definition, but you can still toggle the pin easily. Note the FOR-NEXT loop that shortens that section of code.

Doorbell_Active:
  Chime = IS_ON
  PAUSE 100
  Chime = IS_OFF

  FOR idx = 1 TO 8                              ' must be even #
    Amber = 1 - Amber                           ' toggle Amber
    PAUSE CHIME_TIME
  NEXT

  Amber = IS_ON
  timer = FULL
  GOTO Main


You can use the same trick in the driveway section.

Driveway_Active:
  FOR idx = 1 TO 5
    Beep = 1 - Beep
    Amber = 1 - Amber
    PAUSE BEEP_TIME
  NEXT

  Beep = IS_OFF
  Amber = IS_OFF
  PAUSE 500

  FOR idx = 1 TO 6
    Beep = 1 - Beep
    Amber = 1 - Amber
    PAUSE BEEP_TIME
  NEXT

  PAUSE 500
  Amber = IS_ON

  timer = FULL
  counter = DELAY_VALUE * 2
  GOTO Main


Any time you see redundant code, look for the opportunity to put it into a loop as that will save valuable program space. By using these techniques I was able to shrink your program from using 82% of the memory down to 53% -- that means more room for control logic features (which you many need).
Jon McPhalen
EFX-TEK Hollywood Office

clinefx1

Jon thanks for the advice, I forgot about doing the for next loops.
Here is my synopsis of my project. 
Thanks
Chris.


Striped down this is a program that monitors two inputs and activates 3 outputs.
What I have set up is an IR beam across a drive way and a doorbell button as inputs.  On the output side is an amber light, a electronic beeper and an electronic chime unit. 
When the doorbell is pressed the chime rings and the amber light flashes.
When the IRBeam is broken the beeper beeps and amber light flashes at a different rate.
What I want to do is limit the amount of times the IR beam can trigger an output for a given amount of time after the first hit.
IE let's say a kid finds the beam and starts triggering it over and over again. I would only want to let him do it say 3 times before it locks out for 60 sec.

JonnyMac

So the IR beam is what you're monitoring for "abuse"? Doing time-window programming with a Prop-1 can be really tricky (this would be a breeze on the HC-8+. Let me mull over it for a while and come up with a state-driven program that will let you keep track of times, etc.

Jon McPhalen
EFX-TEK Hollywood Office

clinefx1

Yes the IRBeam is the one I want to be able to tame. I was trying to solve it by doing a value that was being multiplied when that event happened, becoming large enuf to lock it. Then cycling that value back down with main program cycles.