def __init__(self): super().__init__() labels = { 'width' : 50, 'fontcolor' : WHITE, 'border' : 2, 'fgcolor' : RED, 'bgcolor' : DARKGREEN, 'font' : font10, } quitbutton() self.dial = Dial((109, 0), fgcolor = YELLOW, border = 2, pointers = (0.9, 0.7)) self.lbl_result = Label((109, 80), **labels) self.master = Slider((0, 5), 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 = Slider((60, 5), 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((109, 53), font = font10, fontcolor = BLACK, fgcolor = GREEN, text = 'Dis', args = [True, lst_en_dis]) button = bs.add_button((109, 53), font = font10, fontcolor = BLACK, fgcolor = RED, text = 'En', args = [False, lst_en_dis])
def aclock(): uv = lambda phi : cmath.rect(1, phi) # Return a unit vector of phase phi pi = cmath.pi days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday') months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec') # Instantiate CWriter CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False) wri.set_clip(True, True, False) # Instantiate displayable objects dial = Dial(wri, 2, 2, height = 75, ticks = 12, bdcolor=None, label=120, pip=False) # Border in fg color lbltim = Label(wri, 5, 85, 35) hrs = Pointer(dial) mins = Pointer(dial) secs = Pointer(dial) hstart = 0 + 0.7j # Pointer lengths and position at top mstart = 0 + 0.92j sstart = 0 + 0.92j while True: t = utime.localtime() hrs.value(hstart * uv(-t[3]*pi/6 - t[4]*pi/360), YELLOW) mins.value(mstart * uv(-t[4] * pi/30), YELLOW) secs.value(sstart * uv(-t[5] * pi/30), RED) lbltim.value('{:02d}.{:02d}.{:02d}'.format(t[3], t[4], t[5])) dial.text('{} {} {} {}'.format(days[t[6]], t[2], months[t[1] - 1], t[0])) refresh(ssd) utime.sleep(1)
class VerticalSliderScreen(Screen): def __init__(self): super().__init__() labels = { 'width' : 50, 'fontcolor' : WHITE, 'border' : 2, 'fgcolor' : RED, 'bgcolor' : DARKGREEN, 'font' : font10, } quitbutton() self.dial = Dial((109, 0), fgcolor = YELLOW, border = 2, pointers = (0.9, 0.7)) self.lbl_result = Label((109, 80), **labels) self.master = Slider((0, 5), 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 = Slider((60, 5), 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((109, 53), font = font10, fontcolor = BLACK, fgcolor = GREEN, text = 'Dis', args = [True, lst_en_dis]) button = bs.add_button((109, 53), 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.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) # 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): angle = 0 while True: await asyncio.sleep_ms(100) delta = self.slave.value() angle += pi * 2 * delta / 10 self.dial.value(angle) self.dial.value(angle /10, 1)
def main(): print('alevel test is running.') CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False) wri.set_clip(True, True, False) acc = pyb.Accel() dial = Dial(wri, 5, 5, height=75, ticks=12, bdcolor=None, label='Tilt Pyboard', style=Dial.COMPASS, pip=YELLOW) # Border in fg color ptr = Pointer(dial) scale = 1 / 40 while True: x, y, z = acc.filtered_xyz() # Depending on relative alignment of display and Pyboard this line may # need changing: swap x and y or change signs so arrow points in direction # board is tilted. ptr.value(-y * scale + 1j * x * scale, YELLOW) refresh(ssd) utime.sleep_ms(200)
def clock(x): print('Clock test.') refresh(ssd, True) # Clear any prior image lbl = Label(wri, 5, 85, 'Clock') dial = Dial(wri, 5, 5, height = 75, ticks = 12, bdcolor=None, label=50) # Border in fg color hrs = Pointer(dial) mins = Pointer(dial) hrs.value(0 + 0.7j, RED) mins.value(0 + 0.9j, YELLOW) dm = cmath.rect(1, -cmath.pi/30) # Rotate by 1 minute (CW) dh = cmath.rect(1, -cmath.pi/1800) # Rotate hours by 1 minute for n in range(x): refresh(ssd) utime.sleep_ms(200) mins.value(mins.value() * dm, YELLOW) hrs.value(hrs.value() * dh, RED) dial.text('ticks: {}'.format(n)) lbl.value('Done')
def compass(): dial = Dial(wri, 5, 5, height=75, ticks=12, bdcolor=None, label='Direction', style=Dial.COMPASS) ptr = Pointer(dial) ptr.value(1 + 1j)
def compass(x): print('Compass test.') refresh(ssd, True) # Clear any prior image dial = Dial(wri, 5, 5, height = 75, bdcolor=None, label=50, style = Dial.COMPASS) bearing = Pointer(dial) bearing.value(0 + 1j, RED) dh = cmath.rect(1, -cmath.pi/30) # Rotate by 6 degrees CW for n in range(x): utime.sleep_ms(200) bearing.value(bearing.value() * dh, RED) refresh(ssd)
async def compass(evt): wri = Writer(ssd, arial10, verbose=False) wri.set_clip(False, False, False) v1 = 0 + 0.9j v2 = exp(0 - (pi / 6) * 1j) dial = Dial(wri, 5, 5, height=75, ticks=12, bdcolor=None, label='Direction', style=Dial.COMPASS) ptr = Pointer(dial) while True: ptr.value(v1) v1 *= v2 await evt.wait()
async def aclock(): do_connect.do_connect() asyncio.create_task(set_rtc()) asyncio.create_task(ramcheck()) uv = lambda phi: cmath.rect(1, phi) # Return a unit vector of phase phi pi = cmath.pi days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday') months = ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December') # Instantiate CWriter CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it wri = CWriter(ssd, font, GREEN, BLACK, verbose=False) wri.set_clip(True, True, False) # Instantiate displayable objects dial = Dial(wri, 2, 2, height=130, ticks=12, bdcolor=None) # Border in fg color lbltim = Label(wri, 140, 2, 130) lblday = Label(wri, 170, 2, 130) lblmonth = Label(wri, 190, 2, 130) lblyr = Label(wri, 210, 2, 130) hrs = Pointer(dial) mins = Pointer(dial) secs = Pointer(dial) hstart = 0 + 0.7j # Pointer lengths and position at top mstart = 0 + 0.92j sstart = 0 + 0.92j t = time.localtime() while True: hrs.value(hstart * uv(-t[3] * pi / 6 - t[4] * pi / 360), YELLOW) mins.value(mstart * uv(-t[4] * pi / 30 - t[5] * pi / 1800), YELLOW) secs.value(sstart * uv(-t[5] * pi / 30), RED) lbltim.value('{:02d}.{:02d}.{:02d} {}'.format(t[3], t[4], t[5], 'BST' if bst else 'UTC')) lblday.value('{}'.format(days[t[6]])) lblmonth.value('{} {}'.format(t[2], months[t[1] - 1])) lblyr.value('{}'.format(t[0])) refresh(ssd) st = t while st == t: await asyncio.sleep_ms(100) t = time.localtime()
def aclock(): rtc = pyb.RTC() uv = lambda phi: cmath.rect(1, phi) # Return a unit vector of phase phi pi = cmath.pi days = ('Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun') months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec') # Instantiate Writer Writer.set_textpos(ssd, 0, 0) # In case previous tests have altered it wri = Writer(ssd, font_small, verbose=False) wri.set_clip(True, True, False) wri_tim = Writer(ssd, font_large, verbose=False) wri_tim.set_clip(True, True, False) # Instantiate displayable objects dial = Dial(wri, 2, 2, height=215, ticks=12, bdcolor=None, pip=True) lbltim = Label(wri_tim, 50, 230, '00.00.00') lbldat = Label(wri, 100, 230, 100) hrs = Pointer(dial) mins = Pointer(dial) hstart = 0 + 0.7j # Pointer lengths and position at top mstart = 0 + 0.92j while True: t = rtc.datetime( ) # (year, month, day, weekday, hours, minutes, seconds, subseconds) hang = -t[4] * pi / 6 - t[5] * pi / 360 # Angles of hands in radians mang = -t[5] * pi / 30 if abs(hang - mang) < pi / 360: # Avoid visually confusing overlap of hands hang += pi / 30 # by making hr hand lag slightly hrs.value(hstart * uv(hang)) mins.value(mstart * uv(mang)) lbltim.value('{:02d}.{:02d}'.format(t[4], t[5])) lbldat.value('{} {} {} {}'.format(days[t[3] - 1], t[2], months[t[1] - 1], t[0])) refresh(ssd) # Power saving: only refresh every 30s for _ in range(30): upower.lpdelay(1000) ssd.update() # Toggle VCOM
def aclock(): uv = lambda phi : cmath.rect(1, phi) # Return a unit vector of phase phi pi = cmath.pi days = ('Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun') months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec') # Instantiate Writer Writer.set_textpos(ssd, 0, 0) # In case previous tests have altered it wri = Writer(ssd, font_small, verbose=False) wri.set_clip(True, True, False) wri_tim = Writer(ssd, font_large, verbose=False) wri_tim.set_clip(True, True, False) # Instantiate displayable objects dial = Dial(wri, 2, 2, height = 215, ticks = 12, bdcolor=None, pip=True) lbltim = Label(wri_tim, 50, 230, '00.00.00') lbldat = Label(wri, 100, 230, 100) hrs = Pointer(dial) mins = Pointer(dial) secs = Pointer(dial) hstart = 0 + 0.7j # Pointer lengths and position at top mstart = 0 + 0.92j sstart = 0 + 0.92j while True: t = utime.localtime() hang = -t[3]*pi/6 - t[4]*pi/360 # Angles of hour and minute hands mang = -t[4] * pi/30 sang = -t[5] * pi/30 if abs(hang - mang) < pi/360: # Avoid overlap of hr and min hands hang += pi/30 # which is visually confusing. Add slight lag to hrs hrs.value(hstart * uv(hang)) mins.value(mstart * uv(mang)) secs.value(sstart * uv(sang)) lbltim.value('{:02d}.{:02d}.{:02d}'.format(t[3], t[4], t[5])) lbldat.value('{} {} {} {}'.format(days[t[6]], t[2], months[t[1] - 1], t[0])) refresh(ssd) utime.sleep(1)