Led options help

I’m an amateur at Xod and still learning about it but Ill see if I can come up with something for you.

Edit: Im having trouble getting this to work too. I suggested a new node to help fix this.

i understand, its not that simple but i thought someone knew or had the same problem

This isn’t what you wanted but its better than nothing. If I can come up with a better way of doing it then I will let you know. In this way. The led has low, medium, and high setting and you change through them by turning the led off and then back on. You can also change the step number on the count node and get more options from it as well. At a step of .14 you can get 4 brightness options on the led.
adjustable led with button.xodball (4.1 KB)

Thank you friend for your help … it helped me a lot … if you remember anything else just send me … thank you very much again for your time…

led-toggle-dim.xodball (29.8 KB)

As I mentioned in the initial response…this is not a trivial program. For those who don’t want to download the xodball, here is a picture:

The false at center-top is a tweak-boolean. It should be replaced with a button node. The watch directly below it near the bottom should be replaced with an led node.

The nodes between these two are just for switching led on/off. The nodes to the left are controlling what mode the program is in (toggle led on/off, make it brighter, make it dimmer). The nodes on the right are for controlling how bright the LED is when it is on.

This section of code on the right:

image
Is just to initialize the LED brightness to 1 when program starts, then use the stored value in buffer.

When the program starts, it is in toggle mode with LED at full brightness. A quick press of the button will turn the LED off. Another quick press will turn it back on.

Hold the button down for for 2 seconds, and the debounce node will send a pulse to the count node to switch to the next mode (make LED brighter). Entering brighter mode will also force the LED to turn on so we can see how bright it is. It will continue to get brighter as long as the button is held down. When you release the button, the pulse-on-false node in the upper-left will send a pulse to the count node to switch to the next mode (make the LED dimmer). Pressing the button again will make the LED dimmer as long as it is held. Releasing the button causes the pulse-on-false in the upper-left to again pulse the count node and return us to toggle mode.

On the right side is a buffer node to store the brightness for the LED when it is on. If we are NOT in toggle mode, the gate node above the buffer node allows the clock node above it to update the buffer every 2 seconds. The if-else below the buffer node determines whether we are adding a positive 0.2 (brighter) or a negative 0.2 (dimmer). The clip node below the add keeps us within our 0-1 range.

If you want the long-press to enter bright/dim mode, then the next button press to start making it brighter, you will need to add a “dummy” mode; when count=1, you actually do nothing, then when you release the button, it will advance to count=2, which will now be the brighter mode. You will need to reset when count>3 instead of the current count>2. To improve the user interface, you could flash the LED when count=1 so user knows they are now in bright/dim mode and they can release the button. led-toggle-dim2.xodball (35.5 KB)

Wow that is super complicated! Very cool.

gweimer, my friend thank you so much for the time and explanation, I see you know a lot, but for me an amateur it might be a little complicated, maybe some simplified example like this …

and this

And this…

These are WAY easier to program. The 1st could be done using buffer and adding to it, but it is probably easier to use count and use step <1. When value gets >1, reset count so it goes back to 0.

image

The two button option gets a little more complicated because you don’t want your value to go below zero or above 1. One option is to only enable the up button if value is <1 & only enable the down button if value is >0.

The color-changing program is a little more complicated. If you are only turning on one color with each click, you can just specify which LED is on based on count:

If you want “in between” colors (like purple; both red & blue), then you need to specify a value for each LED at each stage. One option would be select, which would need a pulse to select value, or since we are using count, we can use nth-input. nth-input node looks at the number on IDX pin. If it is zero, it outputs X0; if it is one, it outputs X1, etc.

(corrected & tested version; you can test without hardware by replacing button with tweak-boolean & led nodes with watch nodes, then running simulation; changing tweak to true is a button press, changing it to false is a button release)

The nth-input nodes can be grown/shrunk to specify as many colors in your cycle as desired. Just be sure to update value in greater node to match how many colors you are using. In this example, I cycle through red, green, blue, purple and back using on or off for each color. You could also get other colors like blue-purple by specifying 0.5 for red, 0 for green, 1 for blue.

great friend, really awesome and thanks a lot for this … I see you really know a lot and you are expert at this … I have a lot more clarity on this.
For example I have not seen before nod “nth input”, I will study a little. Thanks …
Do you have a file to download from these examples?

I tried the first example and it works … but I do not understand between the reset and the first step there is one step that does not respond

for example two i tried, currently i have only one led diode and one button and i just tried to make the intensity go up but i only get in step instead of fade up, i dont know what i am wrong about …

@gweimer I think there in the output of the nth, are they connected to the pin " - idx", can it be or am I wrong?

Yes…that’s what I get for posting code without testing it. I used the utility pin on the nth-input nodes instead of the correct output pin. I’ll go back & correct it.

The sample code makes a 0.2 intensity change every 2 seconds. You can change the if-else values to make bigger/smaller steps and/or change the clock-IVAL to make quicker/slower steps. If you want it to fade, then you want smaller, quicker steps, but if you make the clock-IVAL too small, it will change too fast & you will not be able to stop before it gets to full bright or off.

I’m not certain I understand, but I think you are saying in led-toggle-dim.xodball you hold the button to go into program mode (which turns on LED), then it starts getting brighter until you release button. On next button press it should get dimmer until you release the button, then the system resets (LED should be “on” at new brightness). Next button press should turn the LED off (you are saying nothing happens with this press?). If you dim the LED until it is off, then both on & off state will be 0 and you will need to hold the button down long enough to go into program mode and brighten the LED again.

This is my new button led adjustment program. In this one it starts off with full power and you can turn it off and on like normal with button. You can also dim the led light down by holding the button down when you turn the led on. Hold the button down for 2 seconds and the light will go into its dimming cycle. You pick the brightness level by letting go of the button.
led light with button hold adjust.xodball (8.0 KB)

great friend, that’s awesome, can you make fade instead of dim fixed value

You mean like this? All I did was change the clock interval and count step values.

led light with button hold adjust (fade).xodball (8.0 KB)

To tell you the truth. The reason why I chose the step down is because leds are extremely efficient and its hard to tell when they start to fade and its usually at the very end or lowest of the pwm signal and then bam its 100 again in my program. I have yet to learn how to map range it into something useful.

ok, i get it. Thank you very much, it helped me a lot and what you did anyway …