Issues with while/repeat loop


#1

I’ve created a “disco” piston to that slowly fades the hue of my Sylvania bulbs through the spectrum. I have this the fade working properly using a virutal switch to trigger it and the loop runs as expected - stopping when the virtual switch is “off”. I’ve added some additional code that should run after the final loop completes that should reset the color temperature back to normal, but it doesn’t ever seem to run.

Any idea what I might be doing wrong here? I’ve tried both a while and repeat and it never seems to run.

thanks!


#2

I would do:

if
    Disco's switch is on
then
    while
        ...
    end while;
else
    with
        ...
    do
        Set color temperature to 2703*K
    end with;
end if;

#3

Thanks, this is what I have now that seems to work. I did need to add a wait equal to the length of the entire loop as turning off the disco mid-loop caused unpredictable behavior.

I’m open to any suggestions as to whether there’s a better way to do this without the wait. Thanks for the help!


#4

Well, the default behavior is supposed to be to cancel the statements if the condition changes. This is the Task Cancellation Policy (TCP.) The default setting is on condition state change. But, I guess I don’t really know at what points it might be able to actually cancel the sequence of statements and tasks (in this case in the while loop.) My first guess would have been that it should be able to cancel at any wait statements, but maybe it can’t cancel a while loop in the middle. So, bottom line, whatever works! :slight_smile: