Hy friends, i need help with one thing, i have one button and one led diode, i want when i press the button the diode power on and stays on, an then i press button for the second time and hold say for 3 sec then i enter the mode of manual adjustment ( press and hold goes up, and when i press button sec time led intesity goes down) of light intensity of the diode, and when i press the third time and I hold the button for say 3 sec until the diode goes off.
Although it sounds like this should be simple, it isn’t. You need to remember if the LED is on or off (probably a flip-flop), the brightness of the LED (probably a buffer), and the current mode (on/off, brighten, dim; maybe a couple flip-flops).
There are also additional questions that need answered. What happens if second button press is short? If it just turns off the light, there is no reason for a 3 second press to turn off light after bright adjust; third press will do that (or long press can put it back into bright adjust mode). If you are not doing that, what would a third button press do if it is short?
I’m not at my computer, but I’m guessing you can probably use debounce node to determine when it is a long button press.
One option for controlling program mode (on/off, brighten, dim) is to use gate nodes to disable button press for parts of program for modes that are not currently active.
If you want light to slowly get brighter/dimmer while holding button, you will need some sort of delay between each time you add or subtract from current value.
Lots of information to get you started. If you are trying to learn and not just have the answer given to you, it will generally be better for us to help you figure out what you are doing wrong rather than us giving you a working program.
If you don’t know what you are doing, it is best to start with a small part and get that working, then add another part. In this example, get LED on/off working, then add a tweak node to set brightness while it is on, then figure out how to replace the tweak node with a buffer and use the button to adjust brightness (you may even want to make a separate program just to adjust a number with button, then figure out how to merge it into LED on/off program). You want as few unknowns as possible when trying to combine everything together, or it will be difficult to narrow down where any problems are if it doesn’t work. As you begin to understand XOD and programming better, there is more you understand before you get started and you can work in bigger chunks.
ok, thanks a lot for the reply … i’m more of a visual type and i’m easier when someone does then i study it and i’m easier that way. I’ve done some simpler projects already, but I have no idea how to do this. I actually started how to make with one button to switch on and off 3 LEDs in order. Then I’m interested in something like this, how to change the brightness when I hold the button, etc.
I used to work a bit with xod earlier, and after a long time I see that some things have changed (like when I connect a regular project diode to a button, only when I press the button then the diode goes off? Which shouldn’t be the other way around? But never mind … I solved it with another nod).
for each node there is a brief description but it is not enough for me to know exactly how that node works and what can be done with it, so from the examples I can see in practice I can see their function, it is easier for me. I don’t know where to learn more about all these features.
Can you do me any of the above for an example … thanks a lot in advance
How far have you gotten? Can you figure out how to add a flop-flop to change the “light on while button pressed” circuit to an “on with first button press, off with second button press” circuit? If you can’t figure that much out after being told the flip-flop can be used to remember the current state and goes between the button and LED nodes, then I don’t know how to help you besides just giving you the final solution, and that is not helping you learn to write your own code.
If the flip-flop description isn’t enough to tell you how to use it, you can wire tweak nodes to the inputs and watch nodes to the output and run a simulation to see what happens to the output with each change of input. Between the description and seeing results of different inputs, you should be able to get an understanding of what the node does. Seeing one way someone uses a node isn’t likely to show you the real power of the node.
If you don’t know what someone is taking about when they mention a node and don’t know where to find it, use the search function (double click in the workspace or single click in the workspace and type ‘i’, then type your search). For example, searching for ‘tweak’ will show input nodes for each data type. By choosing the data type that matches the flip-flop node inputs, you can change those inputs during the simulation (click on the tweak node, then change value or click pulse button in the node details pane to the left of the workspace). Note that some input pins will always do the same thing, while other pins might depend on the current state of the node (pins on flip-flop node are a good example of both cases).
It might take a lot of input changes to fully understand how a single node works in all cases, especially if you are using implicit type conversions (like wiring the Boolean button output to a pulse flip-flop input); sometimes this works… sometimes it is not even allowed because it doesn’t make sense out it is not obvious how it should be converted, but there might be additional nodes that do the conversation for you (like pulse-on-true or pulse-on-false).
It’s clear to me what you mean, and I know some basic functions, but sometimes it can be quite confusing and I need what I’ve been praying for some of my projects when I’m working, so I’m limited by time.
I prayed if someone could show it to me visually and that’s it … if you can help me help, and if you can’t help it, you don’t have to, and that’s okay.
So, for example, say every time I press a button that the intensity changes up or down by one fixed value or constant (it doesn’t matter), or that every time I press a button that another diode lights up and so on, it’s like I have an example and then I will already combine and play when I have more time.
That’s all I asked for … how much we’re already writing during this time you could have already sent me this if you know …
Thank you…
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:
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.
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.