PIR project
· 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.·
· 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
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
·
' {$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
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.
{$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......