Jump to content
C4 Forums | Control4

leds on a keypad with lighting scenes


Recommended Posts

ok i need a different perspective on this.

i have a 3 button keypad and button 2 executes a "downstairs all on" scene and button 3 executes a "downstairs all off" scene.

simple enough.

heres where i need help

the downstairs has 5 lights (4 dimmers and 1 switch)

i want the leds on the 3 button keypad to change in real time when the any of the lights downstairs change. For example the most obvious is, if all the lights downstairs are off, then turn button3 red and button 2 black. And conversely, button 2 green and 3 black when its on.

So lets say after i execute that all off, and i turn on a single light down there. I want the led to do the following above so that it indicates something downstairs is on of off, not just if the lighting scene has been executed.

i tried a few variables on this but they all toggled each other out of sync and were not reliable for status. I know I'm just thinking this out wrong.

I thought of having each light set a string variable state and then saying if this light equals this and that light equals that then turn the led this color, but thats where i got messed up.

I did this one where i did a million if thens on each light and it was painful. it worked but was nuts. I dont want complex variables on all lights down there.

any suggestions?

Link to comment
Share on other sites


Interesting. I think the way I would do it is this:

for each light that's down there, I would add a single line of programming to the light itself that said, "When this light changes, if the state is "On" then set keypad button 2 LED to green and keypad button 3 LED to black." That would take care of all of the situations where a light is on, since you want the GREEN-BLACK sequence any time even ONE light is on.

The reverse, the BLACK-RED sequence, is a bit trickier since you only want it that way if ALL of the lights are off. A few ways come to mind to do this, neither as simple as the above.

My preferred method would be to create a Boolean or numeric variable called "AllDark" which would have 5 nested if/then statements as follows:

When variable "AllDark" changes,

- If Light 1 is off

- - If light 2 is off

- - - If light 3 is off

- - - - If light 4 is off

- - - - - If light 5 is off

- - - - - - then set button 2 LED to BLACK and set button 3 LED to RED

Now in the same 5 lines of programming that you did for the GREEN-BLACK sequence, you could add that when the light state changes, if the light is off, toggle the variable AllDark. Note that you don't actually care whether AllDark is true or false, I'm essentially just using it as a macro. You could also have it increment the number by one if you had a curiosity about how often it was running . . .

I think this is more efficient and easier to maintain that adding the if/thens to every light switch, and if you ever want to add more lights to the grouping you only need to add them in one place.

The other way that comes to mind would be to have a variable "LightCount" which gets incremented by one each time a light goes on and decremented by one each time a light goes off, and then in the programming for LightCount you could say that when the variable changes, if it is 0 set the LEDs to BLACK-RED and if it's not zero set the LEDs to GREEN-BLACK. The only problem with that one is if a light ever fails to increment or decrement the number and it gets out of sequence, you have a problem, so I would also add a line to Button 3 of the keypad that when it turns all of the lights off it sets the LightCount variable to zero. That way it will always be accurate when you press that button.

Do either of those sound like they'd achieve what you want to achieve? If they don't make sense, let me know and I'll try and explain them better! Good luck (and a very neat idea by the way!)

--Jason

Link to comment
Share on other sites

yeah i was doing almost exactly what you suggested, but it is still flawed. to achieve the all off led status: I was thinking of having each light downstairs have a string variable of of "LIGHT OFF" when its goes off. then have the keypad do something like if light1 = LIGHT OFF and light2 etc etc... then change led colors accordingly. then when any light comes on downstairs have it change the sting variable to "on" or whatever is not "LIGHT OFF". i think this can work...

i dunno what do you think?

Link to comment
Share on other sites

yeah i was doing almost exactly what you suggested, but it is still flawed. to achieve the all off led status: I was thinking of having each light downstairs have a string variable of of "LIGHT OFF" when its goes off. then have the keypad do something like if light1 = LIGHT OFF and light2 etc etc... then change led colors accordingly. then when any light comes on downstairs have it change the sting variable to "on" or whatever is not "LIGHT OFF". i think this can work...

i dunno what do you think?

Hmm . . . I suppose that would work, but I am curious as to why the variable checking the status of the 5 lights would not (or did not?) work for you. Do you know what the flaw was? Or is it just that you programmed it that way and it still was not working?

While I think what you're describing would also work, it would take many more variable and would have to run through more lines of code, which I would generally try and avoid. But for educational as well as practical purposes, I'd love to know what broke down in the original code . . .

--Jason

Link to comment
Share on other sites

worked perfect.

Added in a line that said to reset the variable to 0 at 1 AM so the number variable doesn't get so large. guess that doesn't matter. though...

thanks...

Glad I could assist.

That is a good idea. The way I did it was to set it to 0 if the system reboots (project loads).

One other nice feature about this method is that you can invoke it when the system reloads. Give this a try. Turn on one of the lights, the 3-button led should change color. Now power cycle the controller. Leave the light on. I think that when the system comes back up the 3-button will not reflect the state of the light. I fixed this by purring a 5 minute delay at the top of the project load event and then incrementing the variable.

Link to comment
Share on other sites

huh good idea... i think the when project loads event is over looked. I'm in the process of setting all my led changes for lights to variables and not just when the light comes on/off. this way all the keypads are synced up on a power cycle.

Link to comment
Share on other sites

If you want the led to change based on the scenes trigger the change based on the scene.

yeah sounds easy but it needs a bit more than that... I want the led to tell me if any light in the scene is on. not just if the scene has been executed. I'm upstairs and by an led i want to know is any lights are on downstairs. If i execute the scene and my wife turns on the kitchen then the indication is inccorect without the variables that were posted earlier.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.