Simple Room Join

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

  1. Darren

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    A common logic requirement is where you have a conference/meeting room with a removable divider. When the divider is separating the room into two small rooms, the room lights operate independently. When the divider is open, the lights need to be linked together.

    The example code below assumes a switch is activated by the divider (ON = open) and there is one group address in each room. If you have more complex requirements, the relevant sections of code can just be duplicated.

    Code:
    { constants }
    ControlGroup = 1; { this controls whether the loads are linked }
    Room1Group = 2;   { group address for room 1 }
    Room2Group = 3;   { group address for room 2 }
    
    { variables }
    Room1Level : integer;  { last known level in room 1 }
    Room2Level : integer;  { last known level in room 2 }
    
    { initialisation }
    Room1Level := GetLightingLevel(Room1Group);
    Room2Level := GetLightingLevel(Room2Group);
    
    { module code }
    { if the rooms are linked ... }
    if GetLightingState(ControlGroup) = ON then
    begin
      { if Room 1 has changed, make Room 2 the same }
      if Room1Level <> GetLightingLevel(Room1Group) then
      begin
        Room1Level := GetLightingLevel(Room1Group);
        SetLightingLevel(Room2Group, Room1Level, "0s");
        Room2Level := Room1Level;  { this prevents the other bit of logic sending an extra command }
      end;
      { if Room 2 has changed, make Room 1 the same }
      if Room2Level <> GetLightingLevel(Room2Group) then
      begin
        Room2Level := GetLightingLevel(Room2Group);
        SetLightingLevel(Room1Group, Room2Level, "0s");
        Room1Level := Room2Level;  { this prevents the other bit of logic sending an extra command }
      end;
    end;
    
     
    Darren, Jul 5, 2005
    #1
  2. Darren

    nickrusanov

    Joined:
    Aug 5, 2004
    Messages:
    308
    Likes Received:
    0
    Location:
    russia
    Thank you, Darren! =)
     
    nickrusanov, Jul 6, 2005
    #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.