Toggle is flip flopping


#1

1) Give a description of the problem
When I press a button and one of the lights is on and one is off they both switch to the opposite state each time the button is pressed which is not desired.

2) What is the expected behavior?
I would like them to do the same state changing each time the toggle is pressed. Press a button to toggle two lights on and off. If one is on and the other is off I want them to both do the same thing (either on or off) on the first press and then both do the same on the second press. The ST button controller does not have this issue so I want to replicate what they are doing.

3) What is happening/not happening?
If both lights are in the same state it works fine but if one is on and one is off they both toggle to the opposite state but I want them to toggle to to the same state.

4) Post a Green Snapshot of the piston
55%20PM


#2

It is doing exactly what you programmed: toggle both regardless of their state. If you want them to ‘sync up’ you will need to leave one to the other. You can either toggle one and then set the other to the same state or toggle them both and then if they are not the same toggle one again. perhaps adding something like this right after your first toggle:

if [Adam's Lamp : switch] != [Meghan's Lamp : switch]
then
    with Meghan's Lamp
       toggle
    end with
end if

#3

I agree it’s doing what it says I just don’t know how to do what I want! I assume what I’m asking would be pretty common though.

I am attempting to add your statement but from what I can tell I must use the GUI programming not edit the text and therefore I’m unable to figure out how to get a != comparison. This is what I got but it does not work.

Lastly, once I figure out how to add your fix, will I see a light turn on and off if it’s out of sync or will it run through the entire logic before making any state changes (thus preventing it from toggle twice on one of the lamps) ?

Obviously not right :
38%20PM


#4

just curious,
would turning both of them ON before toggle solve your problem?

IF button gets pushed
with Lamp1, lamp2
turn ON
end with
with lamp 1 lamp2 
toggle

somehow never used toggle, so I am just shooting blind here…
note : I am assuming this is kind of signaling them… that is why I recommended the above…


#5

I would go with something like this:

IF Button gets pressed
Then
    IF all of Adam & Meghan's switch are on
    Then
        Turn off Adam & Meghan's switch
    ELSE
        Turn on Adam & Meghan's switch
    END IF
END IF

If the lights do not match, then one press turns them on.


If you want the opposite (turn off if not matching) you can use this instead:

IF Button gets pressed
Then
    IF all of Adam & Meghan's switch are off
    Then
        Turn on Adam & Meghan's switch
    ELSE
        Turn off Adam & Meghan's switch
    END IF
END IF

#6

Thanks everyone. I realize that toggle is not the option and used the advice to make the following which is doing just what I need!

Is it possible to manually edit the script or is everything done from the GUI?

32%20PM


#7

GUI only, which is kind of nice since it helps make sure the syntax is correct.


#8

And, for future reference, you would get to the != by using an expression for your condition on the if statement. Then you just type it like I had above.


#9

Ahh yes… Good point. The ‘Expression’ box is kind of like a mini-script-editor.