Change button function.

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by filpee, May 31, 2006.

  1. filpee

    filpee

    Joined:
    May 31, 2006
    Messages:
    204
    Likes Received:
    0
    Location:
    Western Australia
    I'm not sure how to go about this but what I am trying to do is this..

    Button 1 operates as on/off during office hours
    Button 1 operates as timer (20min after office hours)

    but I cannot figure out how to change the button function using schedules etc.

    Cheers for you help
    Phil Pearson
     
    filpee, May 31, 2006
    #1
  2. filpee

    PSC

    Joined:
    Aug 3, 2004
    Messages:
    626
    Likes Received:
    0
    Location:
    Brisbane, Australia
    Do you have some sort of 'Logic engine'? i.e. PAC, Colour C-Touch even a Minder?

    If so you need to write some code along these lines. (this is more Minder orientated)

    1. Create a flag.
    Code for flag -
    If current time = 8am set office hours flag to ON
    If current time = 5pm set office hours flag to OFF

    2. Create a GA for that button i.e. Office
    Code for GA -
    If "Office" is ON and "Office hours Flag" is ON, set "Office Lights" to ON.
    If "Office" is OFF and "Office hours Flag" is ON, set "Office Lights" to OFF.

    If "Office" is ON and "Office hours Flag" is OFF, pulse "Office Lights" to ON for 00:20.00.
    If "Office Lights" are OFF, set "Office" to OFF

    Don't copy and paste this logic as it will not work. It was only written to give you an idea of the kind of coding needed to perform this operation.

    I hope this helps.
     
    PSC, May 31, 2006
    #2
  3. filpee

    filpee

    Joined:
    May 31, 2006
    Messages:
    204
    Likes Received:
    0
    Location:
    Western Australia
    Yeah i have a PAC but was hoping I could do without it.

    I understand what your code is doing but this would mean that I would need to repeat this code 30 times for the 30 groups that exist.

    Oh well I had better get coding.
     
    filpee, May 31, 2006
    #3
  4. filpee

    filpee

    Joined:
    May 31, 2006
    Messages:
    204
    Likes Received:
    0
    Location:
    Western Australia
    Ah ha.. PAC supports functions/procedures.
    the code below seems to work well.
    As I'm new at this (today my first day looking at PICED) can someone have a quick look at my code and let me know if you can see any issues with it.

    Code:
    {Enter Constant definitions here}
    lightsOutDelay = 300; {time in seconds for lights to turn off in after hours mode}
    AfterHours = 1;     {setup a schedule to turn on/off a group. add that groups id here}
    offsetVal = 16;     {the offset value between your inputs to your outputs}
    minInputVal = 17;   {the id of the first group mapped to a button press}
    maxInputVal = 20;   {the id of the last group mapped to a button press}
    
    {Enter Variable definitions here}
    i : integer;  {counter}
    
    procedure ProcessInput(Input, Output : integer);
    begin
      {if after hours then operate as a timer}
      if (GetLightingState(AfterHours) = ON) then
      begin
        {if button is turned on then turn on the lights and start the timer}
        if (GetLightingState(Input) = ON) then
        begin
          SetLightingState(Output, ON);
          TimerStart(Input);
        end;
        {if button is turned off then turn off the lights}
        if (GetLightingState(Input) = OFF) then
        begin
          SetLightingState(Output, OFF);
        end;
      end;
    
      {if not after hours then operate as normal on/off switch}
      if (GetLightingState(AfterHours) = OFF) then
      begin
        {if button is on the turn the lights on}
        if (GetLightingState(Input) = ON) then
        begin
          SetLightingState(Output, ON);
        end;
        {if button is off then turn the lights off}
        if (GetLightingState(Input) = OFF) then
        begin
          SetLightingState(Output, OFF);
        end;
      end;
    end;
    
    {--button inputs--}
    {scan all the inputs to check if a button has been turned off}
    for i := minInputVal to maxInputVal do
      if (GetLightingState(i) = OFF) then
      begin
        {if the button is off and the lights are on then something has changed.. time to process}
        if (GetLightingState(i+offsetVal) = ON) then
        ProcessInput(i,i+offsetVal);
      end;
    
    {scan all the inputs again but this time to check if a button has been turned on}
    for i := minInputVal to maxInputVal do
      if (GetLightingState(i) = ON) then
      begin
        {if the button is on and the lights are off then something has changed.. time to process}
        if (GetLightingState(i+offsetVal) = OFF) then
        ProcessInput(i,i+offsetVal);
      end;
    
    {--timer--}
    {scan through all the possible timers}
    for i := minInputVal to maxInputVal do
      if TimerRunning(i) then
      begin
        if (TimerTime(i) = lightsOutDelay) then
        {wait for x seconds to expire then turn off the lights, the button and the timer itself}
        begin
          SetLightingState(i+offsetVal, OFF);
          SetLightingState(i, OFF);
          TimerStop(i);
        end
      end;
    
    Thanks
    Phil Pearson
     
    filpee, May 31, 2006
    #4
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.