I am a max user, not familiar with gen~ which daisy field required.
I want to control four buttons (and leds) , when I press any of it, the led keeps on, at the same time, the other three leds(under the button) goes out.
I need there’s always one and only one button/led(which I pressed latest) keeps on, hope someone can give me some advise.
what I can do now is switch the button led on/off individually :
need some one told me how to do next !
Hey! There’s many ways you could do this of course, but I think one of the most straightforward approaches would be a priority encoder with a bit of feedback:
The “priority encoder” is handled by the expr object. All it’s doing is chaining ternary operators. If any button is pressed, the value returned will be that button’s “index.” Otherwise, the result will be zero. This only allow one button to be “selected” at a time, so will only pass the values 0, 1, 2, 3, and 4. If the value passed through is 0, then the next stage can use another ternary operator (also known as a switch object) to pass through the previous value (using the history object) or a new value if that value is greater than 0. The history object is essentially acting as the toggle, keeping the LED on even after it’s been released. The gate object then passes through a 1 to whichever LED is selected.
If the expr object is a bit confusing, you could also just chain switch objects together like this:
Notice the priority order is actually reversed with this configuration (i.e. if A1 and A2 are pressed, the index of A2 will pass through).
With these setups, no button will be selected at startup. If you want a particular button to start on by default, you’ll need to figure out a loadbang-type initialization.
I hope that helps!