Button-Board


Main Image

After finally (and only for now) accepting that a reliable sound2light-bassline-detection is probably more trouble than it’s worth, I next needed a way for tap2bpm instead. This, however, required new Hardware, and thus, I developed this Button-Board.

While there are quite a few designs for input-devices on Thingiverse and the like, those generally tend to be either just HIDsHuman-Interface-Devices where the Buttons send Keystroke-Commands (which my Board of course can do as well) or MIDI-Controllers. As I was looking for something more flexible, I started working on my own system instead.


ledstrip = MagichueStrip()
shelly = ShellyOutlet("shelly1-9FDB845893CD8")
screen_shelly = ShellyOutlet("shellyplug-s-39CA9D")
inputs = [
    ShiftButton("button1", shift_name="s1", on_clickfn=mic_toggle, shift_light=Colors.WHITE),
    SimKeyButton("button2", key="KEY_PLAYPAUSE", click_light=Colors.RED),
    SimKeyButton("button3", key="KEY_NEXTSONG", click_light=Colors.YELLOW),
    SimKeyButton("s1+button3", key="KEY_PREVIOUSSONG", click_light=Colors.BLUE),
    ToggleButton("button4", on_release_fn=ledstrip.toggle, on_longclick_fn=ledstrip.set_max_brigthness, 
                 on_light=Colors.YELLOW, on_condition=ledstrip.ison, check_interval=2),
    Switch("onoffl", onoff_fn=lambda on: ledstrip.toggle(force_to=on), read_fn=ledstrip.ison),
    RotaryEncoder("leftrotary", absval_fn=lambda val: ledstrip.change_brightness(absval=val*255), edge_behav="cap"),
    Button("rightrotaryswitch", on_release_fn=ledstrip.switch_white),
    RotaryEncoder("rightrotary", inc_fn=partial(ledstrip.change_hue, increase=True), 
                                 dec_fn=partial(ledstrip.change_hue, increase=False), led_display_value=None),
    RotaryEncoder("s1+rightrotary", led_display_value=None 
                  inc_fn=lambda: subprocess.get_output("qdbus org.kde.kglobalaccel /component/kmix invokeShortcut increase_volume"), 
                  dec_fn=lambda: subprocess.get_output("qdbus org.kde.kglobalaccel /component/kmix invokeShortcut decrease_volume")),
    Button("rightrotaryswitch", on_click_fn = lambda: subprocess.get_output("qdbus org.kde.kglobalaccel /component/kmix invokeShortcut mute")), 
    RotaryEncoder("s1+leftrotary", inc_fn=partial(slide_onlinevid, inc=True), 
                  dec_fn=partial(slide_onlinevid, inc=False), led_display_value=None),
    Button("leftrotaryswitch", on_release_fn=partial(monitor_toggle, screen_shelly)),
    Switch("onoffr", onoff_fn=shelly.toggle, read_fn=shelly.on_condition),
]

with Board(init_flash=Colors.GREEN, wait_until_connected=True, inputs=inputs, verbose=False) as board:
    board.add_subscr_func(partial(mic_func, button="button3"), loop=True, interval=1)
    board.blocking_main(allow_disconnect=True)