Jump to content
C4 Forums | Control4

Composer Pro(HE) programming request / suggestion for new command


Recommended Posts

I find that ComposerPro (HE) is missing a logic command equivalent to the CASE function in Excel's VBA.

Consider an instance in which you want a singular event to be triggered when a button is pressed and the brightness of a particular light is within a set of ranges.

For example:

  • CASE
    • LL Bedroom-->Entry is on <AND> if LL Bedroom->Entry current brightness <=25%
      • Set the brightness to 25 on LL Bedroom -> Entry
    • LL Bedroom-->Entry is on <AND> if LL Bedroom->Entry current brightness <=50%
      • Set the brightness to 50 on LL Bedroom -> Entry
    • LL Bedroom-->Entry is on <AND> if LL Bedroom->Entry current brightness <=75%
      • Set the brightness to 75 on LL Bedroom -> Entry
    • LL Bedroom-->Entry is on <AND> if LL Bedroom->Entry current brightness <=100%
      • Set the brightness to 100 on LL Bedroom -> Entry
  • additional code follows....

Yes, a set of STOP or ELSE commands can be used but not very efficiently.

I also would propose either a SUBroutine or GOTO command for additional flexibility.

Thoughts appreciated.

Link to comment
Share on other sites


I think the devs didn't ever consider it to that extent especially when they allowed for nested IFs to begin with. It would be a lot easier if there was such a function and i agree, it would be a helpful addition. The marginally cleaner way would be to use a WHILE statement (ie for when the light is on) but that does little to improve the efficiency overall. A GOTO or a 'jump to' function was an obvious one that i was also surprised was not added in. Someone over there must have played around with BASIC when they were younger right?

By the way, i am sure your example was purely that but i think you'd need some lower limits as well to those AND statements.

Link to comment
Share on other sites

While I appreciate the method myself, I suspect that for most adding a CASE command will be just more confusing than creating a macro to trigger that uses the basic stop and buried if statements

 

WHEN button is pressed
IF Light bightness >0
	IF brightness <25
       set to 25
       stop
           IF brightness <50
				set to 50
				stop
					etc
                   

More options is not ALWAYS better.

Link to comment
Share on other sites

If Bedroom is on, run macro BedLevel

Macro BedLevel
If light is <25, set light to 25, stop
If light is <50, set light to 50, stop
if light is <75, set light to 75, stop
Set light to 100

Lots of ways to skin the cat. Above feels like same or less amount of code as a CASE.

Link to comment
Share on other sites

thank you for your reply.  I will count another vote in favor of adding GOTO and CASE.

With respect to your comment regarding lower limits, in the VBA world, each of the conditionals listed under CASE would be considered in order; once ONE of the conditionals were true, the <then> portion would be executed AND the operating system would jump to the additional code -- the other conditionals of the CASE command would not be considered.  By listing the conditionals in ascending order, we can eliminate the lower bounds.  This is very efficient.

Link to comment
Share on other sites

11 minutes ago, Popolou said:

Someone over there must have played around with BASIC when they were younger right?

More or less as per above, I think the issue was never the people creating the program, but the people they were creating the program for.

MOST (field) programmers for C4 aren't IT trained or even hobbyist. Let alone the end-user using HE.

 

Sure the upcoming generation of starting tech may have a much higher knowledge of programming terminology, but most that are now doing it needed to even learn the principal of what an IF statement is to begin with.

C4's goal was/is (I believe) to ensure the programming software is as accessible as possible.

 

Of course, the base software is about 2 decades old at this point and has been pushed far beyond it's initial boundaries to begin with.

Perhaps by OS 4/5 there will just have to be a new 'Composer' to begin with: but it will likely require a full new training setup and for all programmers/dealers to get re-certified. Not against that myself - but I can't help but wonder at the failure rate of that re-certification (for better or worse...)

Link to comment
Share on other sites

@Cyknight Agree entirely and this discussion is quite timely because i recently got buried into some complex nested IF and WHILE statements which was rather exhausting once completed. However, it made me wonder about this very same discussion and how they could have adopted a little from here and there of all the different programming routines that are commonly used.

In my view, the OP is on to a point and where surely an evolution of all these nested IF statements is simply a single use of CASE.

Link to comment
Share on other sites

I recall a stat once that I heard less than 20% of projects have ANY code in the programming tab.

Control4 did a road tour education to highlight things like basic motion triggers.
So yeah, the bar is very low. Everyone here is the exception.

Link to comment
Share on other sites

21 minutes ago, BDavisNJ said:

 By listing the conditionals in ascending order, we can eliminate the lower bounds.  This is very efficient.

Interesting, my gut is telling me that this won't happen with Composer's programming and without lower bounds, you will need to add a BREAK after each successful validation & match so that it exits that routine to then process any subsequent code. Or a STOP if that is all there is.

Link to comment
Share on other sites

First thank you all for your comments.  This forum is a tremendous resource. 

By way of follow-up, I wanted to post the code that is successfully working in my project.  I have attached the screenshot.  I am not using STOP commands because my use case requires that when a KCB button marked "Brighter" is pressed, all of the 4 lighting circuits that service a room get brighter <IF> that particular lighting circuit is already on.  If the lighting circuit is off, the button press has no impact on that circuit.

Many experienced C4 programmers are on this board.  I invite / welcome all comments, criticisms, and suggestions.

image.thumb.png.2dc0652433a78aaf0559690b5e4079e8.png

Link to comment
Share on other sites

You may want to bump up your <=20 to be <=35.
If it's at 21, you'd end up at 1, not 15 which I interpreted is your target minimum?

I prefer to nest under the if on, as the indents show a logical progression, do the first indent else the second, just how I visualize programming personally.

image.png.e5a028defd5cfc5aba4c2ca46a6d2c9b.png

Link to comment
Share on other sites

@RAV  100% agree with both of your points; I have revised my code and appreciate your commentary.  I learned some today and I hope others reviewing these notes are equally benefited.  Thank you.

Link to comment
Share on other sites

I find programming in C4 very awkward, inefficient and slow since you are clicking on various windows and having to scroll down in quite small little windows. 

And the way that lists are handle seems inconsistent.  Like when you are programming with macros you select the macro from a dropdown list, but the list of Scheduler Events are all displayed in a full list.

And some of the lists you can reorder, or sort by name, but others seem to be permanently fixed with the order that they were created.

They really should clean this up and make it more friendly to real programmers, especially since we are now in an age where AI can help you code.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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