I’m fairly new to Pd, so I am assuming this is one of those “it’s easy if you know” sorta things: how to read the position of a “logical” switch at patch load.
The switch here is a 3-way toggle using two pins on the Daisy Seed: one for UP and the other for DOWN. When I say “logical”, I mean the MIDDLE switch position must be deduced: if neither of the two physical switches results in a bang at start-up, then, logically, the switch can only be in the MIDDLE position.
So, as an example, let’s set an LED to 100%, 66%, or 0% brightness depending on the toggle switch position when the patch loads. This is one approach I’ve come up with:
Using the *_fall variants at runtime is simple enough. However, using a flag and delay to handle patch start-up feels dirty and over-complicated. Is there something more elegant in Pd?
There are smarter and more Pd-experienced folks than me on these forums: am I missing something obvious?
This came up in a discord server earlier this week and I don’t really remember what solution we came up with then, but was also using the rising and falling edge behavior.
However you could also “poll” the current state of the switch as @tele_player suggested.
when either switch is on/1 select and send its associated message
when the switches are the same, they must both be closed (0) and then send this message
I haven’t tested this patch, but logically it should work. Downside with control logic is that the order of operations is very important (cold inlet on the == for instance). There might be some edge-case bugs here, but since these switches are handled by a single mechanical input that’s hopefully less likely.
The bang was needed to make the DOWN-to-MIDDLE case work. This worked in Plugdata, but when flashed to the Daisy Seed (after swapping in the @hv_params), I got a constant 66% brightness on the LED and I gave up on debugging it.
BTW, the only “edge case” bugs I could find in the [==] solution were around both switches being ON at the same time. Which is impossible with a 3-way toggle in the real world.
With trigger you get the proper directed control flow of “right-to-left”.
Still not 100% sure if it is needed, but in general it’s good practice to make sure you deal with this in the control flow logic or you might get unintended consequences.
Practically, I don’t believe it is needed here (because of the constant stream of polling messages). But I’ve watched enough cheetomoskeeto videos to prefer it. “Belt and bracers”, as they say.
As an aside, I think omitting the [t b f] while using a Pd [tgl] would not work for the DOWN-to-MIDDLE case while testing. Learning the differences between vanilla Pd objects at design time vs. how the hardware and [r foo @hv_param] behave at runtime has been a big part of the learning curve.