Corridor Linking

Discussion in 'Pascal Logic Code Examples' started by Darren, Jul 11, 2005.

  1. Darren

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    Another common requirement for logic is "corridor linking". In this case, there are a series of offices or rooms sharing a corridor. The corridor light needs to be on while any of the office lights are on, and switch off soon after the last light goes off.

    For a simple case of only two offices, the code is :

    Code:
    { constants }
    CorridorGroup = 5;
    Office1Group = 1;
    Office2Group = 2;
    
    { module code }
    { Switch Corridor on if ANY offices are on }
    once (GetLightingState(Office1Group) = ON) or (GetLightingState(Office2Group) = ON) then
      SetLightingState(CorridorGroup, ON);
    
    { Switch corridor off if ALL offices are off}
    once (GetLightingState(Office1Group) = OFF) and (GetLightingState(Office2Group) = OFF) then
    begin
      Delay(30);
      if (GetLightingState(Office1Group) = OFF) and (GetLightingState(Office2Group) = OFF) then
        SetLightingState(CorridorGroup, OFF);
    end;
    
    The important factor in the code above is to check that the office lights are still off at the end of the delay, in case someone switched a light back on again during the delay period.

    If you need more offices, you can just add them to the condition statements. If you have a lot of offices (more than 3 or 4), this can start to get messy. A simpler way to handle this is to create a Scene which contains all of the Office groups. The groups in this Scene can be manipulated as a set using various logic functions.

    For example, if you have a Scene called "Offices" containing the Group Addresses for all of the offices along a corridor (the levels in the Scene do not matter), you could use the function :
    Code:
    GetSceneMaxLevel("Offices")
    
    to determine the maximum level of the Groups in the Scene. If this level is 0, then all Groups are off. If this level is greater than 0, then at least one group is on.

    This can be applied to the corridor linking example as follows :
    Code:
    { constants }
    CorridorGroup = 5;
    
    { module code }
    { Switch Corridor on if ANY offices are on }
    once GetSceneMaxLevel("Offices") > 0 then
      SetLightingState(CorridorGroup, ON);
    
    { Switch corridor off if ALL offices are off}
    once GetSceneMaxLevel("Offices") = 0 then
    begin
      Delay(30);
      if GetSceneMaxLevel("Offices") = 0 then
        SetLightingState(CorridorGroup, OFF);
    end; 
    
    See the Corridor Linking example provided with the software to see an example of this operating.
     
    Darren, Jul 11, 2005
    #1
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.