counting commands?

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by innovative, Jan 24, 2014.

  1. innovative

    innovative

    Joined:
    Jan 13, 2014
    Messages:
    26
    Likes Received:
    0
    Location:
    south australia
    Hey guys, question. I'm experimenting again and I'm wondering how can I set my system so on say every second or fifth time a c bus group is triggered a second c bus group is triggered? I take it logic would be the go? Could someone please show me?

    Thanks for your time and help guys, I appreciate the time taken.

    Aaron.
     
    innovative, Jan 24, 2014
    #1
    1. Advertisements

  2. innovative

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    974
    Likes Received:
    73
    Location:
    Adelaide, Australia
    In logic:

    in Advanced/Global Variables:

    Code:
    counter1: integer; // or whatever you want to call it
    
    in Initialisation:

    Code:
    counter1 := 0;
    
    in a module:

    Code:
    once GetLightingState("Group to count") = On then
    begin
      counter1 := counter1 + 1;
      if counter1 >= 5 then // Or whatever limit you want
      begin
        counter1 := 0;
        SetLightingState("Group to control", ON);
      end;
    end;
    Or shorter but not so obvious:

    Code:
    once GetLightingState("Group to count") = On then
    begin
      counter1 := counter1 + 1;
      if (counter1 mod 5) = 0 then  SetLightingState("Group to control", ON);
    end;
    if you need to do it every 2nd AND 5th time:

    Code:
    once GetLightingState("Group to count") = On then
    begin
      counter1 := counter1 + 1;
      if ((counter1 mod 5) = 0)  or ((counter1 mod 2) = 0) then  SetLightingState("Group to control", ON);
    end;
     
    Last edited by a moderator: Jan 24, 2014
    Ashley, Jan 24, 2014
    #2
    1. Advertisements

  3. innovative

    innovative

    Joined:
    Jan 13, 2014
    Messages:
    26
    Likes Received:
    0
    Location:
    south australia
    can you help me out with where I have gone wrong please??

    [​IMG]

    what I am after is to see when my alarm is armed, I arm my alarm via a bell press c bus command to a group called "SECURITY" and I want every odd number of bell presses (1st,3rd etc) to trigger a c bus group called "security indicator" which will turn on an indicator on my c-touch spectrum screen.

    rest assured I realise the pitfalls of this system, I am really only doing this as a learning curve..

    thanks very much for your time and help.

    and yes I realise this wont tell me if I use another non c bus panel to arm my alarm.. I plan to use an auxilery input sw to do this long term byt for now I just want to crack the challenge I have set myself:)

    sorry I am a long time installer of c bus but short time programmer!
     
    innovative, Jan 24, 2014
    #3
  4. innovative

    Roosta

    Joined:
    Nov 22, 2011
    Messages:
    560
    Likes Received:
    1
    Location:
    Australia
    You need to clarify your 'if' statement..

    Currently you have 'if counter1=>', you need to put something in after this to define the statement... Try it set to =2 and see if that works...

    You may need to set the counter in the initialisation to 1 rather than 0 to get it to be in the right sequence..

    You may also need to add another if statement to turn the indicator group off.. This should be set to when counter = 1...

    I could be way off though.. Too many beers..
     
    Last edited by a moderator: Jan 24, 2014
    Roosta, Jan 24, 2014
    #4
  5. innovative

    innovative

    Joined:
    Jan 13, 2014
    Messages:
    26
    Likes Received:
    0
    Location:
    south australia
    I tried that but no luck? Appreciate the help though mate. Good point on the off sequence as well.
     
    innovative, Jan 24, 2014
    #5
  6. innovative

    Roosta

    Joined:
    Nov 22, 2011
    Messages:
    560
    Likes Received:
    1
    Location:
    Australia
    Is it giving an error when u compile the logic?
    Are you starting the logic engine before testing?
    How are you testing it?
     
    Roosta, Jan 24, 2014
    #6
  7. innovative

    innovative

    Joined:
    Jan 13, 2014
    Messages:
    26
    Likes Received:
    0
    Location:
    south australia
    I know it's not right as I can't run the logic engine.. it won't stay running. Also if i close and re open the project it tells me there is a logic error.
     
    innovative, Jan 24, 2014
    #7
  8. innovative

    Roosta

    Joined:
    Nov 22, 2011
    Messages:
    560
    Likes Received:
    1
    Location:
    Australia
    If you go to compile in the logic engine menu it should tell you where your errors are..

    My guess is its in your group address tags..
     
    Roosta, Jan 24, 2014
    #8
  9. innovative

    innovative

    Joined:
    Jan 13, 2014
    Messages:
    26
    Likes Received:
    0
    Location:
    south australia
    [​IMG]
    does that mean anything to you?

    sorry like I said im waiting to do my logic training still so im self teaching currently.
     
    innovative, Jan 24, 2014
    #9
  10. innovative

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    974
    Likes Received:
    73
    Location:
    Adelaide, Australia
    You need to look at my example more carefully and copy it correctly.

    You are missing the THEN after the IF statement.

    Tag names must be enclosed in quotes.

    Also, you are never turning the group off. Basically you just want to toggle the group address every time the bell press group is activated.

    Code:
    Once GetLightingState("SECURITY") = ON then SetLightingState("Lighting Indicator", not GetLightingState("Lighting Indicator"));// Toggle Lighting Indicator
    
    Use the right click to insert statements and it will show you the correct syntax.

    Also, the use of BELL PRESS to trigger logic is unreliable. Logic only runs every 200mS so if you press and release the button within this time (which is easy to do) the ONCE statement will not be triggered.
    Set up the switch to just turn ON the group address, then turn if off in the logic
     
    Last edited by a moderator: Jan 25, 2014
    Ashley, Jan 24, 2014
    #10
  11. innovative

    innovative

    Joined:
    Jan 13, 2014
    Messages:
    26
    Likes Received:
    0
    Location:
    south australia
    all fantastic advice :)
    I am learning thankyou!

    latest issues are:

    [​IMG]
     
    innovative, Jan 25, 2014
    #11
  12. innovative

    Roosta

    Joined:
    Nov 22, 2011
    Messages:
    560
    Likes Received:
    1
    Location:
    Australia
    This is making my head hurt.. It should be relatively simple using ?dvice already given...

    Your use of the 'not' statement intrigues me, also you have not out in an statement to turn the group off yet..
     
    Roosta, Jan 25, 2014
    #12
  13. innovative

    innovative

    Joined:
    Jan 13, 2014
    Messages:
    26
    Likes Received:
    0
    Location:
    south australia
    Sorry I'm not trying to be a burden.. I'm just trying to find a code that works.. I'm yet to manage that:/

    Maybe I should just copy and paste a code from here?
     
    innovative, Jan 25, 2014
    #13
  14. innovative

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    974
    Likes Received:
    73
    Location:
    Adelaide, Australia
    Until you familiarize yourself with the basic syntax of the language you will not get very far.

    I suggest you get hold of a book on the Pascal programming language which the logic engine is based on. There are many on-line resources available, and free versions of pascal that run on PC's and Macs are available which will have lots of samples and allow you to come up to speed much quicker.

    To toggle the security indicator only the first line of code is required. It replaces the other example. The code you have can also potentially flood the Cbus network as it is executing the SetLightingState command every 400mS. I will leave you to work out why. Start by looking up BEGIN/END blocks.

    There is no syntax error in the code you have shown (just rather serious logic errors). The errors must be originating in another module.

    To Roosta. The NOT statement simply toggles the current state of the group. ON and OFF are synonyms for TRUE and FALSE. False (Off) has a value of zero and True (On) a byte value of 255.
     
    Last edited by a moderator: Jan 25, 2014
    Ashley, Jan 25, 2014
    #14
  15. innovative

    innovative

    Joined:
    Jan 13, 2014
    Messages:
    26
    Likes Received:
    0
    Location:
    south australia
    Thanks for advice, downloading now:)

    And oops I only needed one line!?

    Yup works great now:) Thankyou for your patience!
     
    innovative, Jan 25, 2014
    #15
    1. Advertisements

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.