Piston to cycle through colors


#1

1) Give a description of the problem
I am trying to write a piston that will toggle through hue lights colors each time the button is pressed. First time pressed light goes blue, next time pressed red, etc then have the cycle start all over

2) What is the expected behaviour?
(PUT YOUR INFO HERE)

3) What is happening/not happening?
Well I’m so new I can only get the first press to turn the light blue then I’m stumped

4) Post a Green Snapshot of the pistonimage
(UPLOAD YOUR IMAGE HERE)

5) Attach logs after turning logging level to Full
(PASTE YOUR LOGS HERE THEN HIGHLIGHT ALL OF THE LOGS AND CLICK ON THE </> ICON TO FORMAT THEM CORRECTLY)

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

If you’re only cycling between two choices, this method works well:


#3

what type of button?


#4

This is a scene enabled smart switch


#5

I would like to be able to cycle through as many colors as I set. So I would like it to be adaptable.


#6

Try something like this.


#7

Thanks. But don’t want it to be random. Want to be able to cycle thru a set of known colors. The part I do t understand is the variable setting. I found this but don’t understand the green text


#8

I’m in bed right now. But if no one has answered you by tomorrow I’ll pull something together for you.


#9

Thanks. I got the colors to cycle but the webcore piston looks like a mess. And I cant dim except for one color. Thx for the help


#10

I got the cycle to work. Now I just need dim and on and off


#11

pls share the latest piston so that who ever comes later can benefit from it.
And we might be able to help with dim and Off.


#12

I’ve not had a chance to write it for you but what you need is a string variable that contains all the colours that you want to cycle through and a global variable that will hold the count of times (And therefore index of colour array) that it’s been executed.

Once you’ve chose a colour (using the index) then increase that number by one.

You need to check and make sure your not setting it to a number that’s bigger than the amount of colours in your array. If it is reset it back to 1.

Hopefully that gives you enough food for thought.


#13

Hello,

So I am brand new to web CORE and was trying to do something similar using a RGB bulb and a Samsung smart button. I want a single push of the button to bring the light on to a standard lighting look and another to turn the lighting look off. Holding the button would result in entering the “color mode” and then each double press after that would cycle through a list of colors. I have gotten the on/off to work. I have also gotten the initial “enter color mode” to work. Where I am having trouble is getting the colors to scroll correctly. What I figured I would do is create an “if” statement saying that in order to go to the next color in the sequence when the button is pushed, the fixture must first be in the color it is sitting in currently. By doing this, it would always know where it is in the cycle. To exit the color mode, I thought I would create a restriction saying the lamp could be in any of the colors in the color mode, and then a long press would allow an exit. Again, I can’t seem to get any farther then getting the lamp in the initial color, so any help or advice might be appreciated. This is most likely just user error from the new guy. Attaching a picture.


#14

try creating them all as individual if statements instead of nested if’s, the other thing you could try is a case (switch) statement. Not only will one of these work it will make it more readable. I would recommend the case statement myself


#15

Thank you. I was looking up the case switch statements and it seems cool. What do you think would be the best way to keep the colors in order? Seems like i need each execution to reference the last in some way?


#16

I’d try using a global variable that you update each time the piston executes. Then do a check at then end to make sure you’ve not increased the variable to a number more than you have colours. If you have then reset the global variable back to 1.


#17

Unfortunately, @Rizlah, a global variable change cannot be detected until the next piston execution. (local variables do not have this restriction, and can be seen immediately)


#18

isn’t this what he is looking to achieve, each time the piston is executed the new number is picked up


#19

Sorry… I was referring to this:

A global checked at the end will always be the same as the global checked at the beginning. It only changes once the piston has completed in it’s entirety. If that is the goal, then cool, but normally it is avoided.


#20

Best doing the check at the beginning then before running the switch statement.