def meter(): m = Meter(wri, 5, 100, height=75, divisions=4, label='Peak', style=Meter.BAR, legends=('0', '50', '100')) m.value(0.72)
async def meter(n, x, text, t): print('Meter {} test.'.format(n)) m = Meter(wri, 5, x, divisions = 4, ptcolor=YELLOW, label=text, style=Meter.BAR, legends=('0.0', '0.5', '1.0')) l = LED(wri, ssd.height - 16 - wri.height, x, bdcolor=YELLOW, label ='over') while True: v = int.from_bytes(uos.urandom(3),'little')/16777216 m.value(v, color(v)) l.color(color(v)) l.text(txt(v), fgcolor=color(v)) refresh(ssd) await asyncio.sleep_ms(t)
def meter(): print('meter') refresh(ssd, True) # Clear any prior image m = Meter(wri, 5, 2, height = 45, divisions = 4, ptcolor=YELLOW, label='level', style=Meter.BAR, legends=('0.0', '0.5', '1.0')) l = LED(wri, 5, 40, bdcolor=YELLOW, label ='over') steps = 10 for _ in range(steps): v = int.from_bytes(uos.urandom(3),'little')/16777216 m.value(v) l.color(GREEN if v < 0.5 else RED) refresh(ssd) utime.sleep(1) refresh(ssd)
def __init__(self): super().__init__() labels = { 'width': 50, 'fontcolor': WHITE, 'border': 2, 'fgcolor': RED, 'bgcolor': DARKGREEN, 'font': font10, } quitbutton() self.meter = Meter((129, 0), font=font6, legends=('0', '5', '10'), pointercolor=YELLOW, fgcolor=CYAN) self.lbl_result = Label((25, 80), **labels) self.led = LED((0, 80), border=2) self.master = HorizSlider((0, 16), font=font6, fgcolor=YELLOW, fontcolor=WHITE, legends=('0', '5', '10'), cb_end=self.callback, cbe_args=('Master', ), cb_move=self.master_moved, value=0.5, border=2) self.slave = HorizSlider((0, 44), fgcolor=GREEN, cbe_args=('Slave', ), cb_move=self.slave_moved, border=2) self.reg_task(self.coro()) # On/Off toggle: enable/disable quit button and one slider bs = ButtonList(self.cb_en_dis) lst_en_dis = [self.slave, self.master] button = bs.add_button((0, 107), font=font10, fontcolor=BLACK, fgcolor=GREEN, text='Dis', args=[True, lst_en_dis]) button = bs.add_button((0, 107), font=font10, fontcolor=BLACK, fgcolor=RED, text='En', args=[False, lst_en_dis])
def meter(): ssd.fill(0) refresh(ssd) wri = Writer(ssd, arial10, verbose=False) m0 = Meter(wri, 5, 2, height = 50, divisions = 4, legends=('0.0', '0.5', '1.0')) m1 = Meter(wri, 5, 44, height = 50, divisions = 4, legends=('-1', '0', '+1')) m2 = Meter(wri, 5, 86, height = 50, divisions = 4, legends=('-1', '0', '+1')) steps = 10 random = xorshift64star(2**24 - 1) for n in range(steps + 1): m0.value(random() / 16777216) m1.value(n/steps) m2.value(1 - n/steps) refresh(ssd) utime.sleep(1)
class SliderScreen(Screen): def __init__(self): super().__init__() labels = { 'width': 50, 'fontcolor': WHITE, 'border': 2, 'fgcolor': RED, 'bgcolor': DARKGREEN, 'font': font10, } quitbutton() self.meter = Meter((129, 0), font=font6, legends=('0', '5', '10'), pointercolor=YELLOW, fgcolor=CYAN) self.lbl_result = Label((25, 80), **labels) self.led = LED((0, 80), border=2) self.master = HorizSlider((0, 16), font=font6, fgcolor=YELLOW, fontcolor=WHITE, legends=('0', '5', '10'), cb_end=self.callback, cbe_args=('Master', ), cb_move=self.master_moved, value=0.5, border=2) self.slave = HorizSlider((0, 44), fgcolor=GREEN, cbe_args=('Slave', ), cb_move=self.slave_moved, border=2) self.reg_task(self.coro()) # On/Off toggle: enable/disable quit button and one slider bs = ButtonList(self.cb_en_dis) lst_en_dis = [self.slave, self.master] button = bs.add_button((0, 107), font=font10, fontcolor=BLACK, fgcolor=GREEN, text='Dis', args=[True, lst_en_dis]) button = bs.add_button((0, 107), font=font10, fontcolor=BLACK, fgcolor=RED, text='En', args=[False, lst_en_dis]) # CALLBACKS # cb_end occurs when user stops touching the control def callback(self, slider, device): print('{} returned {}'.format(device, slider.value())) def master_moved(self, slider): val = slider.value() self.led.value(val > 0.8) self.slave.value(val) self.lbl_result.value(to_string(val)) def cb_en_dis(self, button, disable, itemlist): for item in itemlist: item.greyed_out(disable) # Either slave has had its slider moved (by user or by having value altered) def slave_moved(self, slider): val = slider.value() if val > 0.8: slider.color(RED) else: slider.color(GREEN) self.lbl_result.value(to_string(val)) # COROUTINE async def coro(self): oldvalue = 0 await asyncio.sleep(0) while True: val = int.from_bytes(os.urandom(1), 1) / 255 steps = 20 delta = (val - oldvalue) / steps for _ in range(steps): oldvalue += delta self.meter.value(oldvalue) await asyncio.sleep_ms(100)
async def meter(evt): wri = Writer(ssd, arial10, verbose=False) args = {'height' : 80, 'width' : 15, 'divisions' : 4, 'style' : Meter.BAR} m0 = Meter(wri, 165, 2, legends=('0.0', '0.5', '1.0'), **args) m1 = Meter(wri, 165, 62, legends=('-1', '0', '+1'), **args) m2 = Meter(wri, 165, 122, legends=('-1', '0', '+1'), **args) random = xorshift64star(2**24 - 1) while True: steps = 10 for n in range(steps + 1): m0.value(random() / 16777216) m1.value(n/steps) m2.value(1 - n/steps) await evt.wait()
def meter(): print('Meter test.') refresh(ssd, True) # Clear any prior image color = lambda v: RED if v > 0.7 else YELLOW if v > 0.5 else GREEN txt = lambda v: 'ovr' if v > 0.7 else 'high' if v > 0.5 else 'ok' m0 = Meter(wri, 5, 2, divisions=4, ptcolor=YELLOW, label='left', style=Meter.BAR, legends=('0.0', '0.5', '1.0')) l0 = LED(wri, ssd.height - 16 - wri.height, 2, bdcolor=YELLOW, label='over') m1 = Meter(wri, 5, 50, divisions=4, ptcolor=YELLOW, label='right', style=Meter.BAR, legends=('0.0', '0.5', '1.0')) l1 = LED(wri, ssd.height - 16 - wri.height, 50, bdcolor=YELLOW, label='over') m2 = Meter(wri, 5, 98, divisions=4, ptcolor=YELLOW, label='bass', style=Meter.BAR, legends=('0.0', '0.5', '1.0')) l2 = LED(wri, ssd.height - 16 - wri.height, 98, bdcolor=YELLOW, label='over') steps = 10 for n in range(steps): v = int.from_bytes(uos.urandom(3), 'little') / 16777216 m0.value(v, color(v)) l0.color(color(v)) l0.text(txt(v), fgcolor=color(v)) v = n / steps m1.value(v, color(v)) l1.color(color(v)) l1.text(txt(v), fgcolor=color(v)) v = 1 - n / steps m2.value(v, color(v)) l2.color(color(v)) l2.text(txt(v), fgcolor=color(v)) refresh(ssd) utime.sleep(1)