Hello everyone,
I am relative new to PICBasic.
How do I change the output state of a pin after a 2 minute delay? I believe the pause command is only a maximum of 65 seconds.
Any help to set me on my way would be greatly appreciated.
Thanks
Carl
Hello everyone,
I am relative new to PICBasic.
How do I change the output state of a pin after a 2 minute delay? I believe the pause command is only a maximum of 65 seconds.
Any help to set me on my way would be greatly appreciated.
Thanks
Carl
Welcome to the forums
You could use a counter to count 60 seconds and then another counter to count the 2 minutes. A second can be achieved by Pause 1000
something like this would work
There may be other ways to achieve the same result.Code:Turn on the output for minutes = 1 to 2 for seconds = 1 to 60 pause 1000 next next Turn off the output
Good luck
start:
let x = (x+1)
if x >= 120 then (high or low your port)
pause 1000
goto start
Just a couple of thoughts...
Jerson's example is nicely presented, but be aware that the PAUSE statement stalls program execution and the Pic will do nothing during the two minutes. This may suit your need and there's no harm in it, but you may also consider the SLEEP statement in place of the PAUSE if you are running on batteries - SLEEP puts the Pic in low power mode and, while not as accurate, is much more efficient (if you're running on batteries this may be important). If program execution needs to continue during the two minutes, consider using an INTERRUPT. A short subroutine that increments a counter once per second and toggles your output at 120 seconds - while execution continues.
If you chose to use peterdeco1's routine, reset X to zero in the IF/ THEN construct, else it will continue to fire each second as X=121, X=122, ... - and don't forget to add an exit condition, unless you want to loop until long after "the cows come home".
Often the best help can be had by posting your code, explaining what it does and what you want it to do... there are geniuses here and they routinely offer many ideas that can make learning much easier - giving insight into best practice and "gotchas" not always evident, even if the code works as written.
Last edited by Amoque; - 21st February 2014 at 05:36. Reason: typo
Bookmarks