need to loop through random group addresses

Discussion in 'Pascal Logic Code Examples' started by Trevor, Oct 11, 2024 at 2:31 AM.

  1. Trevor

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    352
    Likes Received:
    26
    Location:
    Melbourne Victoria
    Hi all,
    I have updated this a bit since last post so best to start again.

    The code below when run gets the 10 values entered into system logic user io input fields and assigns those values to buttons and allocates a group address for each of them, and also to indicator lights on the screen.

    What i need to do now is loop through those group addresses and turn each of them on/off as selected later.
    I just can't seem to get them into any sort of place i can do this. I used to write a lot of visual basic for Excel, Access and Outlook and if it was in one of those i wouldn't have a problem, but the limited syntax is killing me is here.

    to simplify, i have 10 randomly selected group addresses that can be changed/selected as required, after the user has selected them, start a loop and turn on and off each one for amount of times selected in another system user io

    Hope you can help, or even point me in the right direction please.
    regards
    Trevor
    Code below works OK.

    Code:
    If ShowingPage("Random Selection") then
    once getlightingstate(250) = ON then
    //Initialise all 10 group addresses
    begin
    SetCompintegerProp("Random Selection", "Gate_Status_1", "C-Bus Group",  GetIntSystemIO(1));
    SetCompintegerProp("Random Selection", "Gate_Status_2", "C-Bus Group",  GetIntSystemIO(2));
    SetCompintegerProp("Random Selection", "Gate_Status_3", "C-Bus Group",  GetIntSystemIO(3));
    SetCompintegerProp("Random Selection", "Gate_Status_4", "C-Bus Group",  GetIntSystemIO(4));
    SetCompintegerProp("Random Selection", "Gate_Status_5", "C-Bus Group",  GetIntSystemIO(5));
    SetCompintegerProp("Random Selection", "Gate_Status_6", "C-Bus Group",  GetIntSystemIO(6));
    SetCompintegerProp("Random Selection", "Gate_Status_7", "C-Bus Group",  GetIntSystemIO(7));
    SetCompintegerProp("Random Selection", "Gate_Status_8", "C-Bus Group",  GetIntSystemIO(8));
    SetCompintegerProp("Random Selection", "Gate_Status_9", "C-Bus Group",  GetIntSystemIO(9));
    SetCompintegerProp("Random Selection", "Gate_Status_10","C-Bus Group",  GetIntSystemIO(10));
    
    SetCompintegerProp("Random Selection", "gate_indicator_1", "C-Bus Group",  GetIntSystemIO(1));
    SetCompintegerProp("Random Selection", "gate_indicator_2", "C-Bus Group",  GetIntSystemIO(2));
    SetCompintegerProp("Random Selection", "gate_indicator_3", "C-Bus Group",  GetIntSystemIO(3));
    SetCompintegerProp("Random Selection", "gate_indicator_4", "C-Bus Group",  GetIntSystemIO(4));
    SetCompintegerProp("Random Selection", "gate_indicator_5", "C-Bus Group",  GetIntSystemIO(5));
    SetCompintegerProp("Random Selection", "gate_indicator_6", "C-Bus Group",  GetIntSystemIO(6));
    SetCompintegerProp("Random Selection", "gate_indicator_7", "C-Bus Group",  GetIntSystemIO(7));
    SetCompintegerProp("Random Selection", "gate_indicator_8", "C-Bus Group",  GetIntSystemIO(8));
    SetCompintegerProp("Random Selection", "gate_indicator_9", "C-Bus Group",  GetIntSystemIO(9));
    SetCompintegerProp("Random Selection", "gate_indicator_10", "C-Bus Group",  GetIntSystemIO(10));
    
     end;
     
    Trevor, Oct 11, 2024 at 2:31 AM
    #1
  2. Trevor

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,540
    Likes Received:
    177
    Location:
    Adelaide, Australia
    Use an array and a for loop


    Code:
    // Global variables section
    ga: array[1..10] of integer;   // Array to hold ga's
    i: integer;
    
    // Your Module (compressed a bit)
    If ShowingPage("Random Selection") then
    once getlightingstate(250) = ON then
    //Initialise all 10 group addresses
      for i := 1 to 10 do ga[i] :=  GetIntSystemIO(1); // Save ga's in array
      SetCompintegerProp("Random Selection", "Gate_Status_1", "C-Bus Group",  ga[1]);
      SetCompintegerProp("Random Selection", "Gate_Status_2", "C-Bus Group",  ga[2]);
    ...etc
      SetCompintegerProp("Random Selection", "gate_indicator_1", "C-Bus Group",  ga[1]);
      SetCompintegerProp("Random Selection", "gate_indicator_2", "C-Bus Group",  ga[2]);
    ...etc
      end;
    
    // To loop through ga's
    for i := 1 to 10 do
    begin
       SetLightingLevel(ga[i], 0%, "0s"); // For example, turn off all groups
    end
    
    If you need different levels for each ga, just define another array and put the target values in it, and
    access them the same as above.

    You can also loop through setting each component property rather than individually setting them , but that's another story.
     
    Ashley, Oct 11, 2024 at 8:20 AM
    #2
  3. Trevor

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    352
    Likes Received:
    26
    Location:
    Melbourne Victoria
    Thanks Ash,
    Looks like you've fonebit again. Ill have all of that put in nect week...hetting very close now.
     
    Trevor, Oct 11, 2024 at 9:20 AM
    #3
  4. Trevor

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    352
    Likes Received:
    26
    Location:
    Melbourne Victoria
    Hi Ashley,
    I've been playing around with this new code...
    for i := 1 to 10 do ga := GetIntSystemIO(1); // Save ga's in array

    Should this "GetIntSystemIO(1)" have the i variable in place of the 1 so it increments as well to get all the different group addresses saved in the 10 system variables

    And then once i have all the group addresses in the array how do i loop through them.

    See the sample file, random tests are under group tests then Custom...
     

    Attached Files:

    Trevor, Oct 14, 2024 at 8:17 PM
    #4
  5. Trevor

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    352
    Likes Received:
    26
    Location:
    Melbourne Victoria
    Almost there now,
    I did need to change that 1 to an i so it followed the ga as it changed, then the last bit of code you supplied works to turn the selected group addresses on/off as required. Now im just going to add some more code to let the user select the number of loops or continuous, and what action to take eg... On,Off,Ramp,toggle.
    I will also limit to the group addresses that have been selected. ie they need to be greater than 0.
    I'll post the project again with these included.
    Thanks for your help Ashley, much appreciated.
     
    Trevor, Oct 14, 2024 at 10:02 PM
    #5
  6. Trevor

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,540
    Likes Received:
    177
    Location:
    Adelaide, Australia
    Yes, sorry, typo :)
     
    Ashley, Oct 14, 2024 at 11:46 PM
    #6
  7. Trevor

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    352
    Likes Received:
    26
    Location:
    Melbourne Victoria
    The code below sort of works ok now, it says messages are being sent on every scan. the error line is indicated as the last line before final end statement, i cant seem to get my if and once commands
    correct.

    Code:
    If ShowingPage("Random Selection") then
    once getlightingstate(250) = ON then
         setlightingstate(250, OFF);
    //Initialise all 10 group addresses
    begin
    SetCompintegerProp("Random Selection", "Gate_Status_1", "C-Bus Group",  GetIntSystemIO(1));
    SetCompintegerProp("Random Selection", "Gate_Status_2", "C-Bus Group",  GetIntSystemIO(2));
    //...up to 10
    SetCompintegerProp("Random Selection", "gate_indicator_1", "C-Bus Group",  GetIntSystemIO(1));
    SetCompintegerProp("Random Selection", "gate_indicator_2", "C-Bus Group",  GetIntSystemIO(2));
    //...up to 10
    end;
    // Set group addresses as per user selections
    for i := 1 to 10 do ga[i] :=  GetIntSystemIO(i); // Save ga's in array
    
    //loop through ga's
    for i := 1 to 10 do
    begin
       SetLightingLevel(ga[i], 100%, "0s"); // For example, turn off all groups
    end     
     
    Trevor, Oct 14, 2024 at 11:52 PM
    #7
  8. Trevor

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    352
    Likes Received:
    26
    Location:
    Melbourne Victoria
    After fixing my begin end statements it is all ok now.
    Just going to add some parameters for the user to select... run time/count group address actions...On/Off/ ramp.
    hope to be done by late in the week
     
    Trevor, Oct 14, 2024 at 11:54 PM
    #8
  9. Trevor

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    352
    Likes Received:
    26
    Location:
    Melbourne Victoria
    The code below sort of works ok now, it says messages are being sent on every scan. the error line is indicated as the last line before final end statement, i cant seem to get my if and once commands
    correct.

    Code:
    If ShowingPage("Random Selection") then
    once getlightingstate(250) = ON then
         setlightingstate(250, OFF);
    //Initialise all 10 group addresses
    begin
    SetCompintegerProp("Random Selection", "Gate_Status_1", "C-Bus Group",  GetIntSystemIO(1));
    SetCompintegerProp("Random Selection", "Gate_Status_2", "C-Bus Group",  GetIntSystemIO(2));
    //...up to 10
    SetCompintegerProp("Random Selection", "gate_indicator_1", "C-Bus Group",  GetIntSystemIO(1));
    SetCompintegerProp("Random Selection", "gate_indicator_2", "C-Bus Group",  GetIntSystemIO(2));
    //...up to 10
    end;
    // Set group addresses as per user selections
    for i := 1 to 10 do ga[i] :=  GetIntSystemIO(i); // Save ga's in array
    
    //loop through ga's
    for i := 1 to 10 do
    begin
       SetLightingLevel(ga[i], 100%, "0s"); // For example, turn off all groups
    end     
     
    Trevor, Oct 16, 2024 at 12:28 AM
    #9
  10. Trevor

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    352
    Likes Received:
    26
    Location:
    Melbourne Victoria
    OK, i had this all working yesterday. NOW it seems that it wants to use the system io numbers as if they are based on 0 starting number, yesterday it was all working when they were based on 1 as starting digit... WTF
     
    Trevor, Oct 16, 2024 at 12:29 AM
    #10
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.