need to loop through random group addresses

Discussion in 'Pascal Logic Code Examples' started by Trevor, Oct 11, 2024.

  1. Trevor

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,554
    Likes Received:
    180
    Location:
    Adelaide, Australia
    I assume you want to turn them all on, wait a bit, turn them off, wait a bit more, then repeat.

    Code:
    If ShowingPage("Random Selection") Then
       Once getlightingstate(250) = ON Then
       For L_Count := 1 To getIntSystemIO("Loop_Count") Do 
       Begin
            For i := 1 To 10 Do SetLightingLevel(ga[i], 100%, getIntSystemIO("Ramp_Rate")); // Lights on
            Delay(10.0); // Or however long you want
            For i := 1 To 10 Do SetLightingLevel(ga[i], 100%, "0s"); // Trun off
           Delay(10.0); // Or however long you want      
       End;
     setlightingstate(250, OFF);
    
    The problem here is once the sequence has started you can't stop it until it's finished. The way around this is to check the 250 ga before each delay and break the loop if off:

    Code:
    If ShowingPage("Random Selection") Then
       Once getlightingstate(250) = ON Then
       For L_Count := 1 To getIntSystemIO("Loop_Count") Do 
       Begin
            For i := 1 To 10 Do SetLightingLevel(ga[i], 100%, getIntSystemIO("Ramp_Rate")); // Lights on
           if getlightingstate(250) = OFF Then break; // break will exit a for loop
            Delay(10.0); // Or however long you want
            For i := 1 To 10 Do SetLightingLevel(ga[i], 100%, "0s"); // Trun off
           if getlightingstate(250) = OFF Then break;
           Delay(10.0); // Or however long you want     
       End;
     setlightingstate(250, OFF);
    
    
    If you want to break faster you can put the break command inside a loop of shorter delays.
     
    Ashley, Oct 30, 2024
    #21
  2. Trevor

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    377
    Likes Received:
    29
    Location:
    Melbourne Victoria
    Cheers for the reply,
    I thought i did try the delay like that, but ill have to recheck. I assume i can duplicate most of that so if Lighting state 5 is on do it all with no ramp and if off use the ramp like the break idea. I must say its very hard uding this cut down version of pascal, i programmed in pascal back in the 80s, dos and machine code before that, then visual basic for excel, access and outlook sure it wasn't this hard. Thanks for the assistance.
     
    Trevor, Oct 30, 2024
    #22
  3. Trevor

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,554
    Likes Received:
    180
    Location:
    Adelaide, Australia
    Actually the logic engine implements the complete Pascal language, It's bascallly equivalent to Borlands original Turbo Pascal.. Not sure what you think is missing. I've written extremely complex logic over the years and still vastly prefer it to the Lua language in the SHAC in terms of robustness.
     
    Ashley, Oct 30, 2024
    #23
    Conformist likes this.
  4. Trevor

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    377
    Likes Received:
    29
    Location:
    Melbourne Victoria
    Sooo Close now, but i did have to edit out the break line, it doesn't recognize the command, i can see why it's there, is there any other way to do this, also missing the goto command.
    See code below...

    Code:
    If ShowingPage("Random Selection") Then
       Once getlightingstate(250) = ON Then
       For L_Count := 1 To getIntSystemIO("Loop_Count") Do
       Begin
            For i := 1 To 10 Do SetLightingLevel(ga[i], 100%, getIntSystemIO("Ramp_Rate")); // Lights on
        //   if getlightingstate(250) = OFF Then break; // break will exit a for loop
            Delay(getIntSystemIO("Delay_Count")); // Or however long you want
            For i := 1 To 10 Do SetLightingLevel(ga[i], 0%, getIntSystemIO("Ramp_Rate")); // Trun off
        //   if getlightingstate(250) = OFF Then break;
           Delay(getIntSystemIO("Delay_Count")); // Or however long you want     
       End;
     setlightingstate(250, OFF);
     
    Trevor, Oct 31, 2024
    #24
  5. Trevor

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,554
    Likes Received:
    180
    Location:
    Adelaide, Australia
    Oops. After telling you how complete the logic engine was I forgot it doesn't support the break or continue commands. :)

    Try

    Code:
     if getlightingstate(250) = ON Then // Only delay if group 250 still on
           Delay(getIntSystemIO("Delay_Count"));
    
    for both times;


    If "Delay_Count" is long and you want to exit sooner (within 1 second), you can go

    Code:
    for j := 1 to (getIntSystemIO("Delay_Count") do
      if getlightingstate(250) = ON Then
           Delay(1.0);
      
    Where you define j: integer in the globals section
     
    Ashley, Nov 1, 2024
    #25
  6. Trevor

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    377
    Likes Received:
    29
    Location:
    Melbourne Victoria
    No worries, the help you have given me is outstanding. I did fix the break problem with a line to increase the i variable to 10 if the button is pressed again. The only problem left is the time delay values, its all screwed up at the moment, 2 delays of separate times but because i accidentally changed the name of one of them they are now all up each other. But will fix this next week. If i use static times the whole thing works great. Prior to that the delays worked ok. My next project will be 2 fold... one for cgate and one for voice controll. Cheers for now. I'll post the completed project next week when it's all working.
     
    Trevor, Nov 1, 2024
    #26
  7. Trevor

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    377
    Likes Received:
    29
    Location:
    Melbourne Victoria
    Short update, decided on a defaukt delay of 3 seconds for all delays. Fixes it all and runs perfectly now.

    My new project is setting up a rasberry pi on s windows 10 pc with lots of extras included...
    I'll still post the project with the code running by end of the week.

    And agian, i appreciate all your help Ashley.
    Regards Trevor
     
    Trevor, Nov 6, 2024
    #27
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.