Shop OBEX P1 Docs P2 Docs Learn Events
Need some help with the "count" command on BS2 — Parallax Forums

Need some help with the "count" command on BS2

Daniel BrockmanDaniel Brockman Posts: 6
edited 2011-08-28 19:24 in BASIC Stamp
My next project is a garage door minder,
It monitors my garage door and automatically shuts it after detecting NO motion in the garage after 1 hour.
Im trying to use the "count" command to count the number of times the IR beam has been broken. Im setting it up( the count command) on pin I/O 16.
If the count is "0" then shut the garage after 1 hour
if the count is > or = 1 then I run a sub routine to reset the count to 0 and start the 1 hour process over.
I've looked at the book and can't seem to make heads or tails of the example.
I've figured out how to make the BS2 shut the garage, check to see if indeed its closed, but if I'm working in the garage the IRBeam will be being triggered and I don't want it to close. After I'm in for the night, and "Darn" I forgot to close my garage, the BS2 will detect no motion from the IRBeam, and thus toggle pin 16 high and down goes the garage door.
If you give me the code for this please explain so I can learn. Im very new, and trying my best to grasp.
Thank you guys very much.
Daniel:lol:

Comments

  • FranklinFranklin Posts: 4,747
    edited 2011-08-28 08:59
    I'm not sure where your problem is. What is it your program is doing (or not) that you want fixed? It always helps if you attach your code so we don't have to reinvent your wheel but only fix the error or omission in your code. Thanks.
  • Daniel BrockmanDaniel Brockman Posts: 6
    edited 2011-08-28 09:10
    OK, Franklin.
    I'm sorry, I'll do that now.
    I have not done a "syntax" to see if all this is correct, so if you see any other errors, pls scolled me for them :)
    IRBeam Pin 16 'IR Beam from Garage is on Pin 16
    Capture CON 1
    Cycles VAR Word
    Process:
    OUTPUT 0
    LOW 0
    IF IN1 = 1 THEN Timer1
    IF IN2 = 1 THEN Timer2
    IF IN3 = 1 THEN Timer3
    IF IN4 = 1 THEN Timer4
    GOTO Process

    Timer1: 'Timer 1 is 30 minutes
    COUNT (Capture * 1), DEC cycles
    IF IRBeam > 1 OR = 1 THEN Reset1
    IF IN1 = 0 THEN Process
    LOW 0
    PAUSE (18000 * 100) ' I hope this sets pause for 30 min
    IF IN1 = 0 THEN Process
    HIGH 0
    PAUSE 1000
    LOW 0
    PAUSE 30000
    GOTO Process

    Timer2: ' Timer 2 is 1 hour
    IF IN2 = 0 THEN Process
    LOW 0
    PAUSE (36000 * 100) " 1 hour pause I hope
    IF IN2 = 0 THEN Process
    HIGH 0
    PAUSE 1000
    LOW 0
    PAUSE 30000
    GOTO Process

    Timer3: ' Timer 3 is 1.5 hours
    IF IN3 = 0 THEN Process
    LOW 0
    PAUSE (36000 * 100) 'Pause for 1 hour
    PAUSE (18000 * 100) 'pause for 1/2 hour
    IF IN3 = 0 THEN Process
    HIGH 0
    PAUSE 1000
    LOW 0
    PAUSE 30000
    GOTO Process

    Timer4: 'Timer 4 is set for 2 hours
    IF IN4 = 0 THEN Process
    LOW 0
    PAUSE (36000 * 100) 'pause for 1hour
    PAUSE (36000 * 100) 'pause for 1 hour
    IF IN4 = 0 THEN Process
    HIGH 0
    PAUSE 1000
    LOW 0
    PAUSE 30000
    GOTO Process

    Reset1: ' rests count on i/o 16 back to a "0" count
    COUNT = 0
    GOTO Timer1
  • Daniel BrockmanDaniel Brockman Posts: 6
    edited 2011-08-28 09:15
    JUst another note, This is not 100 percent complete, as you can see. I'm just trying to get over this "count" hump
  • FranklinFranklin Posts: 4,747
    edited 2011-08-28 09:24
    Your count syntax is not right should be COUNT Pin, Duration, variable. The best way to work on a problem like this is to write a SMALL program that includes only the problem and whatever you need to test it. Also if you put your code in the editor and press F7 it will tell you what is not right and you can fix the problems one at a time. Once the code compiles you can test it for operation.
  • Daniel BrockmanDaniel Brockman Posts: 6
    edited 2011-08-28 09:35
    ok. so i'll start with trying to run a "count" program, since that is where im getting hooked up.
    I have been using the F7 before this on some other small programs I did and it work and the program worked fine. This is the first time using the count command for me. so, If I follow you , then i should go something like,
    1: count 16 ( this being the pin im using) duration, variable
    correct?
  • Mike GMike G Posts: 2,702
    edited 2011-08-28 09:46
    Daniel, open the Basic Stamp Help, read about the COUNT command and check out the sample code.

    Help -> Basic STamp Help... -> PBASIC Language Reference -> COUNT -> COUNT Example link in the upper right hand corner.

    If you are still having problems, post your syntax error free code.

    When posting a problem, we need to know what you expect to happen and the steps to reproduce the problem.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-08-28 14:33
    The maximum duration for the COUNT command is 65.535 seconds. You could do something like the following...
    '{PBASIC 2.5}
    increment VAR Word
    ticks VAR Byte
    
    Start:
    FOR ticks = 1 to 60    ' for 60 minutes
      COUNT IRpin, 60000, increment  ' Stamp holds here and counts for 60 seconds
      IF increment THEN start     ' somebody broke the beam, start over
    NEXT
      ' closeDoor here
      END
    


    There are other ways to do this that are probably more flexible and do not involve the COUNT command per se.
  • ercoerco Posts: 20,256
    edited 2011-08-28 19:24
    Daniel: If you're really in Rocklin, CA, you're the luckiest son of a gun here. Just stroll into Parallax in Rocklin and ask for help!
Sign In or Register to comment.