How to swap a variable?


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Hello,

    Not sure if this will help you. The receiving variable is always on the left side

    In this statement you are moving the contents of temp into Block_temp

    Block_temp = temp

    The way I read your question you wanted to store or move the contents of Block_temp into
    temp?

    temp = Block_temp

    Regards
    Mark

  2. #2
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mark_s View Post
    In this statement you are moving the contents of temp into Block_temp - Block_temp = temp
    Hi Mark,

    Yes that's correct, I want to move the contents of temp into Radiator_temp on the first pass in the mainloop so I can see the temperature on the first line of my Lcd then on the second pass I change the Sensor_Select to be the Block_Sensor and then want to load temp into Block_temp so I can see it on the second line of the Lcd. I've tried many different combinations and just can't seem to get that to work. It does work and display properly if I mix it up like my code shows above, but it's a puzzler for me and I can't figure why that works and if it'll be reliable.

    Thanks
    jessey

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hi Jessey,

    I noticed in your 1st subroutine "Select_A_Sensor_To_Read:" you are swapping your variables before the gosub to "Check_Temperature:" . What happens if you read the temperature first
    right before the swap statement. The last sensor reading will now be in the temp variable. It can now be stored in Radiator_Temp or Block_temp. The way you have it now it reads the temperature to temp and exits the subroutine.

    Try this
    Add a new variable Old_temp

    If I = 0 Then''''''''''''''''''''

    Sensor_Select = Radiator_Sensor' This is a little convoluted to say the
    GOSUB Check_Temperature ' it should work then the program switches
    SWAP Old_temp, Radiator_temp ' least but it works, how and why I have no
    Radiator_temp = temp ' idea. If I uncomment the commented out code


    Endif ' sensors around i.e. instead of reading the
    ' Radiator_Sensor on pin 15 it then reads
    If I = 1 Then ' the sensor on 33 even though it's declared
    Sensor_Select = Block_Sensor ' on pin 15 and vice versa for the
    GOSUB Check_Temperature ' it should work then the program switches
    SWAP Old_temp, Block_temp ' DS1820 Block_Sensor. So it switches the
    Block_temp = temp ' two sensors, very confusing! It must be in


    Endif
    Return''''''''''''''''''''''''''''''
    Last edited by mark_s; - 18th June 2010 at 19:11.

  4. #4
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mark_s View Post
    What happens if you read the temperature first right before the swap statement. The last sensor reading will now be in the temp variable. It can now be stored in Radiator_Temp or Block_temp. The way you have it now it reads the temperature to temp and exits the subroutine.
    Thanks Mark,

    That's all it took, I changed it like you suggested and it works perfectly now. Thanks for your help I really appreciate it.

    Thanks Again
    jessey

    Code:
       If I = 0 Then                 
        Sensor_Select = Radiator_Sensor   
        GOSUB Check_Temperature 
        Radiator_temp = temp  
       Endif    
     
       If I = 1 Then 
        Sensor_Select = Block_Sensor 
        GOSUB Check_Temperature
        Block_temp = temp 
       Endif
    Last edited by jessey; - 19th June 2010 at 03:48.

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Jessey,
    Glad to hear it's working!

    How are you attaching or making contact with the DS1820's to your engine? I have a
    generator that I would like to experiment with a temp read out and overheat cut off.

    Thanks Mark

Members who have read this thread : 0

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