Pin as variable?


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Jul 2010
    Posts
    19

    Cool Pin as variable?

    Is there a way to set a Pin as a variable?

    Something like:

    Code:
    ...
    myPin = PORTB.1
    
    High myPin
    Pause 1000
    Low myPin
    
    myPin = PORTA.0
    
    High myPin
    Pause 500
    Low myPin
    ...
    Using myPin VAR PORTB.1 is not good since I cannot define the variable several times. Am I missing something obvious?

  2. #2
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default

    Hi;

    Yes;

    like this;
    Code:
    LED   VAR PORTA.1
    
    High led
    pause 500
    low led
    Thanks and Regards;
    Gadelhas

  3. #3
    Join Date
    Jul 2010
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gadelhas View Post
    Hi;

    Yes;

    like this;
    Code:
    LED   VAR PORTA.1
    
    High led
    pause 500
    low led
    Thank you for your response, but as I mention in my original post, that is not what I am looking for, since you cannot define the variable repeatedly in the program. If you look at my example I am assigning two different Pins to the same variable. Thank you anyway

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Why do you want to use the same variable name for two different things?
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Jul 2010
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Why do you want to use the same variable name for two different things?
    I am not using the same variable for two different things.

    I have a subroutine that sends a special signal through a pin, and I need to be able to control which PIN the signal is sent through.

    So the easiest way would be to do something like:

    Code:
    myPin = PORTB.1
    gosub SendSignal
    ...
    myPin = PORTA.1
    Gosub SendSignal
    ...
    myPin = PORTA.0
    Gosub SendSignal
    ...
    SendSignal:
    ... 
    HIGH myPin
    (Do more stuff)
    LOW myPin
    Pause T
    HIGH myPin
    T = something
    Pause T
    Low myPin
    (more stuff)
    High myPin
    Tf = T*something
    Pause Tf
    Low myPin
    ...
    RETURN
    Since the SendSignal routine is quite complex, I would like to implement it this way. I can't use a CASE SELECT either because everytime the routine has to do something with the pin, I would have to have a separate CASE block.

    Any ideas?
    Last edited by dream-; - 15th September 2010 at 20:46.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    myPin = PORTB.1
    Read the state of the pin and stores the value to myPin.

    HIGH myPin
    Is for making a pin HIGH.

    So the way you want to do it will not work.

    The only way I see to do what you want is to use an IF/THEN/ELSE block with three condiitons or CASE SELECT with three conditions.
    Dave
    Always wear safety glasses while programming.

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