Changing output state after 2 minutes


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2014
    Posts
    1

    Default Changing output state after 2 minutes

    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

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default Re: Changing output state after 2 minutes

    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

    Code:
      Turn on the output
    
       for minutes = 1 to 2
            for seconds = 1 to 60
                pause 1000
            next
       next
    
      Turn off the output
    There may be other ways to achieve the same result.

    Good luck

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Changing output state after 2 minutes

    start:
    let x = (x+1)
    if x >= 120 then (high or low your port)
    pause 1000
    goto start

  4. #4
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: Changing output state after 2 minutes

    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

Similar Threads

  1. Changing output binary number sequence? is it possible?
    By wdmagic in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd January 2013, 00:47
  2. Changing GPS co-ordinates into Degrees-Minutes-Seconds
    By FromTheCockpit in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 3rd November 2009, 20:00
  3. Changing bits in a byte for multiple output
    By tazntex in forum Serial
    Replies: 3
    Last Post: - 11th August 2008, 19:10
  4. Help changing CCP3 output pin
    By ChrisHelvey in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th July 2008, 02:30

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts