Fan Control Logic

Discussion in 'Pascal Logic Code Examples' started by chromus, Jan 7, 2020.

  1. chromus

    chromus

    Joined:
    Jan 27, 2014
    Messages:
    422
    Likes Received:
    50
    Location:
    Perth
    Hi All,

    Looking for sanity check of my code before I deploy to a client site.

    Basically they want to have the ability to run a sweep fan automatically based on an enabler and have a temp sensor feed the logic to decide the fan speed based on temp.

    The code does compile OK, but that doesnt mean it will respond as desired.

    Here is my draft code, the required variable is of course defined in the proper spot but I am concerned that in its current form it may hunt from slow to medium each time the code runs if the temp is >= 27

    Code:
    {Sets Fan Speed based on room temp}
    
    //set fan to Off  <= 22C
    //set fan to Slow >= 22C
    //set fan to Med  >= 27C
    
    once (Second = 59) then // IMPORTANT - don't run this code every cycle - once a minute is ample
        begin
      
        r_b2fantemp := GetRealIBSystemIO("Measurement App Real Value", 254, 1, 4);  
        if(GetLightingState("Bed2 Fan Enabler") = On) then
      
           if r_b2fantemp >= 22.0 then
           SetLightingLevel("Bed2 Fan", 30%, "0s")
    
           else
           if r_b2fantemp >= 27.0 then
           SetLightingLevel("Bed2 Fan", 60%, "0s")
          
           else
           SetLightingLevel("EDLTTextColour", 0%, "0s");
     
      end;
    
    
     
    chromus, Jan 7, 2020
    #1
  2. chromus

    chromus

    Joined:
    Jan 27, 2014
    Messages:
    422
    Likes Received:
    50
    Location:
    Perth
    I worked out why I had that bad feeling and ive included the right way below for future ref

    Code:
    {Sets Fan Speed based on room temp}
    
    //set fan to Off  <= 22C
    //set fan to Slow >= 22C
    //set fan to Med  >= 27C
    
    once (Second = 59) then // IMPORTANT - don't run this code every cycle - once a minute is ample
       begin
     
       r_b2fantemp := GetRealIBSystemIO("Measurement App Real Value", 254, 1, 4); 
       if(GetLightingState("Bed2 Fan Enabler") = On) then
     
          if r_b2fantemp >= 27.0 then
          SetLightingLevel("Bed2 Fan", 60%, "0s")
    
          else
          if r_b2fantemp >= 22.0 then
          SetLightingLevel("Bed2 Fan", 30%, "0s")
         
          else
          SetLightingLevel("EDLTTextColour", 0%, "0s");
    
      end;
    
     
    chromus, Jan 7, 2020
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.