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

    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.

  2. #2
    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.

  3. #3


    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