Shop OBEX P1 Docs P2 Docs Learn Events
PIR project — Parallax Forums

PIR project

marcuzmarcuz Posts: 5
edited 2008-04-22 19:50 in BASIC Stamp
· Help, I'm trying to write a program utilizing PIR motion sensors and servos to simulate a gated parking lot. I'm having a difficult time with the
· programming. I am able to count the cars entering the lot, but having trouble controlling the counting and subtracting and stopping the program
· when the lot is full. I'm having a lot of trouble with the PBASIC language any help would be appreciated.·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-21 16:22
    The best way to get help on these forums is to ask specific questions, provide adequate information about what you've tried already and what you understand and what's happening when you try something. You'll need to provide the source of your existing program as an attachment to your message and it's very helpful if there are meaningful comments in the source about what you're trying to do in that part of the program. If you're still in the process of writing your program and have PBasic questions, just ask the specific question with examples of what you mean. I strongly suggest that you build your programs step-wise. Start with one piece, get it working, then add the next bit of functionality and test that, etc. If you try to do the whole thing at once when you're still learning, you get bogged down in the complexity of your program when you're debugging.
  • stamptrolstamptrol Posts: 1,731
    edited 2008-04-21 16:29
    PBASIC is one of the easiest to use variants of BASIC. You may just be trying to absorb too many concepts at one time.

    Have a look at a few chapters of "What's a Microcontroller?" on the Parallax website. It will lead you through the early steps and help you build a foundation of experience to build on.

    Or, give us something to work with. For instance, instead of saying you're having "a lot of trouble with PBASIC", show us some examples of your unsuccessful code. Then, we can help you one problem at a time.

    I think you'll find the forum-ites very helpful, but specific questions are better than vague questions.

    BTW, if you've gotten your program to do as much as you say, the final solution is not too far away!

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • marcuzmarcuz Posts: 5
    edited 2008-04-21 18:15
    here is what I have so far. The idea was to have the counter advance once every time switch A is hit and the gate would raise the opposite should happen for switch B the counter should subtract 1 and raise and lower the gate (pulse servo left and right). This dandy bit of code only pulses the servo and then ends.




    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    switcha PIN 2
    switchb PIN 6
    gate VAR Word
    counter VAR Nib
    counter = 0


    DO
    GOSUB Main
    GOSUB Gate_up

    LOOP

    Main:
    IF switcha = 1 THEN counter = counter + 1
    DEBUG CRSRXY,1, 2, "counter =", DEC2 counter
    PAUSE 250

    IF switchb = 1 THEN counter = counter - 1
    IF switcha = 1 THEN
    ENDIF
    RETURN
    Gate_up:

    FOR gate = 1 TO 150
    PULSOUT 15,1000
    PAUSE 20
    NEXT

    FOR gate = 1 TO 150
    PULSOUT 15, 500
    PAUSE 20
    NEXT
    END
    RETURN


    I also have this working counter but am unable as of yet to get both to work together:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    switcha PIN 2
    switchb PIN 6
    gate VAR Word
    counter VAR Nib
    counter = 0


    DO
    GOSUB Main



    LOOP

    Main:
    IF switcha = 1 THEN counter = counter + 1
    DEBUG CRSRXY,1, 2, "counter =", DEC2 counter
    PAUSE 250

    IF switchb = 1 THEN counter = counter - 1
    IF switcha = 1 THEN
    ENDIF
    RETURN
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-21 18:51
    The END statement stops the program. You probably should just delete it.

    If your program stops or "twitches" just as the servo is first moved, you may have a power problem. The servo will draw a lot of current initially (up to 1 Amp), then this will drop to about 250mA while it's moving, then it will idle with a current draw of tens of mA. If your power source isn't up to this, the Stamp's supply will drop below the "brownout threshold" and the Stamp will be reset starting the program over again.
  • Shawn LoweShawn Lowe Posts: 635
    edited 2008-04-22 19:50
    Try this:

    {$STAMP BS2}
    ' {$PBASIC 2.5}

    switcha PIN 2
    switchb PIN 6
    gate VAR Word
    counter VAR Nib
    counter = 0




    Main:

    IF switcha = 1 THEN counter = counter + 1
    DEBUG CRSRXY,1, 2, "counter =", DEC2 counter
    Gosub Gate_up
    PAUSE 250
    else goto main

    IF switchb = 1 THEN counter = counter - 1
    DEBUG CRSRXY,1, 2, "counter =", DEC2 counter
    Gosub Gate_up
    PAUSE 250
    goto main


    Gate_up:

    FOR gate = 1 TO 150
    PULSOUT 15,1000
    PAUSE 20
    NEXT

    Pause 5000

    FOR gate = 1 TO 150
    PULSOUT 15, 500
    PAUSE 20
    NEXT

    RETURN


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    Maybe I should have waited to do that......
Sign In or Register to comment.