Picking a Random Value from 'Color' and 'Color Temperature'


#1

1) Give a description of the problem
I have some LED strips that I want to cycle through a random set of 'color’s AND ‘color temperature.’

2) What is the expected behaviour?
As above.

3) What is happening/not happening?
Nothing yet - looking for help with the logic/statements.

I’d like to turn the statements below into a single set that picks a random choice between Red, Gold, Green and 2700K. Is this possible?

**4) Post a Green Snapshot of the piston![image|45x37]
Piston

5) Attach logs after turning logging level to Full
n/a


#2

Two ways come to mind: Use a switch statement, or use the random function with an ‘if’ statement for the “color temperature”. Here’s both methods in the same piston:

image

You can put either it in a while loop with a random delay like you have in your example.

Does this make sense?


#3

Found another post talking about that random function: Random number between two values

It looks like you could set your switch expression to random(5) instead of my goofy formula I learned in BASIC class. You might have to start the case number at 0 (like 0,1,2 instead of 1,2,3).


#4

Thank you. It makes sense to me. I just couldn’t work the logic out myself to handle both color and color temp. I will give this a whirl and report back.


#5

I used the random function and it’s working like a dream.

Thanks again.


#6

You can also go to town and set a variable to the current value and then the next go round compare the random value to the previous value so you don’t get the same color back to back, that would be boring :slight_smile: