# Copyright 2024 Allen Synthesis
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from europi import k1, k2, b1, b2, oled, MAX_UINT16
from europi_script import EuroPiScript
from experimental.knobs import KnobBank
An example program showing the use of a KnobBank or LockableKnobs. This script is not meant to be merged into main,
it only exists so that PR reviewers can try out a LockableKnob in physical hardware easily.
class KnobPlayground(EuroPiScript):
.with_locked_knob("p1", initial_uint16_value=0, threshold_percentage=0.02)
.with_locked_knob("p2", initial_uint16_value=MAX_UINT16 / 5)
.with_locked_knob("p3", initial_uint16_value=MAX_UINT16 / 3)
.with_locked_knob("p4", initial_percentage_value=0.5, threshold_from_choice_count=7)
.with_locked_knob("p5", initial_percentage_value=1, threshold_from_choice_count=3)
choice_p4 = ["a", "b", "c", "d", "e", "f", "g"]
choice_p5 = ["one", "two", "three"]
p1 = "X" if self.kb1.index == 0 else " "
p2 = "*" if self.kb1.index == 1 else " "
p3 = "*" if self.kb1.index == 2 else " "
pd = "*" if self.kb2.index == 0 else " "
p4 = "*" if self.kb2.index == 1 else " "
p5 = "*" if self.kb2.index == 2 else " "
f"{p1} {self.kb1.p1.range(1000):4} {pd} {k2.range()} \n"
+ f"{p2} {int(round(self.kb1.p2.percent(), 2)*100):3}% {p4} {self.kb2.p4.choice(choice_p4):5}\n"
+ f"{p3} {self.kb1.p3.read_position():4} {p5} {self.kb2.p5.choice(choice_p5):5}"
if __name__ == "__main__":