def vari_fields(): print('Variable label styles.') refresh(st7735, True) # Clear any prior image wri_large = CWriter(st7735, freesans20, GREEN, BLACK, verbose=False) wri_large.set_clip(True, True, False) Label(wri_large, 0, 0, 'Text') Label(wri_large, 20, 0, 'Border') width = wri_large.stringlen('Yellow') lbl_text = Label(wri_large, 0, 65, width) lbl_bord = Label(wri_large, 20, 65, width) lbl_text.value('Red') lbl_bord.value('Red') lbl_var = Label(wri_large, 50, 2, '25.46', fgcolor=RED, bdcolor=RED) refresh(st7735) utime.sleep(2) lbl_text.value('Red') lbl_bord.value('Yellow') lbl_var.value(bdcolor=YELLOW) refresh(st7735) utime.sleep(2) lbl_text.value('Red') lbl_bord.value('None') lbl_var.value(bdcolor=False) refresh(st7735) utime.sleep(2) lbl_text.value('Yellow') lbl_bord.value('None') lbl_var.value(fgcolor=YELLOW) refresh(st7735) utime.sleep(2) lbl_text.value('Blue') lbl_bord.value('Green') lbl_var.value('18.99', fgcolor=BLUE, bdcolor=GREEN) Label(wri, st7735.height - wri.height - 2, 0, 'Done', fgcolor=RED) refresh(st7735)
def __init__(self, ScreenDriver): self.width = SCR_WIDTH self.height = SCR_HEIGHT self.ScreenDriver = ScreenDriver self.buffer = bytearray(self.height * self.width * 2) super().__init__(self.buffer, self.width, self.height, framebuf.RGB565) self.writer = {} self.writer['font6'] = CWriter(self, font6, 0xffff, 0) self.writer['roboto18'] = CWriter(self, roboto18, 0xffff, 0)
def renderText(self, text, x, y, fgcolor=0xffff, bgcolor=0x0000, font='font6'): CWriter.set_textpos(self, y, x) self.writer[font].setcolor(fgcolor, bgcolor) self.writer[font].printstring(text)
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 __init__(self, x, text): 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) super().__init__(wri, 5, x, divisions=4, ptcolor=YELLOW, label=text, style=Meter.BAR, legends=('0.0', '0.5', '1.0')) self.led = LED(wri, ssd.height - 16 - wri.height, x, bdcolor=YELLOW, label='over') self.task = asyncio.create_task(self._run())
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') CWriter.set_textpos(st7735, 0, 0) # In case previous tests have altered it wri = CWriter(st7735, arial10, GREEN, BLACK, verbose=False) wri.set_clip(True, True, False) # Instantiate displayable objects refresh(st7735, True) # Clear any prior image 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 = cetTime() 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(st7735) utime.sleep(1)
mosi = Pin(23) SPI_CS = 26 SPI_DC = 5 spi = SPI(2, baudrate=32000000, sck=sck, mosi=mosi, miso=miso) tft = Display(spi, SPI_CS, SPI_DC) # Fonts import fonts.arial10 as arial10 import fonts.freesans20 as freesans20 GREEN = color565(0, 255, 0) RED = color565(255, 0, 0) BLUE = color565(0, 0, 255) YELLOW = color565(255, 255, 0) BLACK = 0 CWriter.set_textpos(tft, 0, 0) # In case previous tests have altered it wri = CWriter(tft, arial10, GREEN, BLACK, verbose=False) wri.set_clip(True, True, False) class Point(): def __init__(self, dial): self.dial = dial self.val = 0 + 0j self.color = None def value(self, v=None, color=None): self.color = color if v is not None: if isinstance(v, complex): l = cmath.polar(v)[0]
SPI_DC = 15 spi = SPI(1) elif sys.platform == 'esp32': print('1.4 inch TFT screen test on ESP32') sck = Pin(18) miso = Pin(19) mosi = Pin(23) SPI_CS = 26 SPI_DC = 5 spi = SPI(2, baudrate=32000000, sck=sck, mosi=mosi, miso=miso) st7735 = Display(spi, SPI_CS, SPI_DC) refresh(st7735) CWriter.set_textpos(st7735, 0, 0) # In case previous tests have altered it wri = CWriter(st7735, arial10, Display.GREEN, Display.BLACK, verbose=False) wri.set_clip(True, True, False) def meter(): print('meter') refresh(st7735, True) # Clear any prior image title = Label(wri, 2, 10, 'SHT30 measurements', fgcolor=Display.WHITE, bdcolor=Display.WHITE) tempLabel = Label(wri,
def test(): st7735.clear() rhs = st7735.size()[0] - 1 print("rhs: ", rhs) st7735.line(rhs - 20, 0, rhs, 20, Display.WHITE) square_side = 10 st7735.fill_rect(rhs - square_side, 0, square_side, square_side, Display.BLUE) wri = CWriter(st7735, freesans20) wri.setcolor(Display.GREEN, Display.BLACK) wri.set_textpos(st7735, 0, 0) # verbose = False to suppress console output wri.printstring('Sunday\n') wri.printstring('12 Aug 2018\n') wri.printstring('10.30am') st7735.show()
def usd_scroll(use_spi=False, soft=True): ssd = setup(use_spi, soft) # Create a display instance # Only CWriter can do usd CWriter.invert_display(ssd) CWriter.set_textpos(ssd, 0, 0) wri = CWriter(ssd, freesans20, verbose=False) wri.set_clip(False, False, False) # Char wrap wri.printstring('Sunday\n') wri.printstring('12 Aug 2018\n') wri.printstring('10.30am') for x in range(5): ssd.show() utime.sleep(2) wri.printstring('\nCount = {:2d}'.format(x)) ssd.show() utime.sleep(2) wri.printstring('\nDone.') ssd.show() CWriter.invert_display(ssd, False) # For subsequent tests
def usd_tabs(use_spi=False, soft=True): ssd = setup(use_spi, soft) # Create a display instance CWriter.invert_display(ssd) CWriter.set_textpos(ssd, 0, 0) wri = CWriter(ssd, fixed, verbose=False) wri.set_clip(False, False, False) # Char wrap wri.printstring('1\t2\n') wri.printstring('111\t22\n') wri.printstring('1111\t1') ssd.show() CWriter.invert_display(ssd, False) # For subsequent tests
def usd(use_spi=False, soft=True): ssd = setup(use_spi, soft) # Create a display instance # Only CWriter can do usd CWriter.invert_display(ssd) CWriter.set_textpos(ssd, 0, 0) wri = CWriter(ssd, freesans20, verbose=False) wri.set_clip(False, False, False) # Char wrap wri.printstring('Sunday\n') wri.printstring('12 Aug 2018\n') wri.printstring('10.30am') ssd.show() CWriter.invert_display(ssd, False) # For subsequent tests
async def run(self, pir, ssd): # Define colors white = ssd.rgb(255, 255, 255) black = ssd.rgb(0, 0, 0) red = ssd.rgb(255, 0, 0) blue = ssd.rgb(0, 0, 255) yellow = ssd.rgb(255, 255, 0) green = ssd.rgb(0, 255, 0) # Instantiate CWriters wri_l = CWriter(ssd, font, green, black, self.verbose) # Large font. wri_s = CWriter(ssd, arial10, white, black, self.verbose) # Small text # Instantiate interpolator and draw the scale interp = Interpolator(pir) self.draw_scale(ssd) while True: t = ticks_ms() # For verbose timing self.mapper.set_range(self.tmin, self.tmax) interp.refresh() # Acquire data max_t = -1000 min_t = 1000 sum_t = 0 for row in range(32): for col in range(32): # Transpose, reflect and invert val = interp((31 - col) / 31, row / 31) max_t = max(max_t, val) min_t = min(min_t, val) sum_t += val ssd.rect(col * 2, row * 2, 2, 2, ssd.rgb(*self.mapper(val))) await asyncio.sleep(0) self.avg = round(sum_t / 1024) if self.mode == _AUTO: self.tmin = round(min_t) self.tmax = round(max_t) if self.rf_disp: if self.rf_txt: wri_l.set_textpos(ssd, 66, 0) wri_l.printstring('Max:{:+4d}C\n'.format(int(max_t))) wri_l.printstring('Min:{:+4d}C\n'.format(int(min_t))) wri_l.printstring('Avg:{:+4d}C'.format(self.avg)) wri_s.set_textpos(ssd, 128 - arial10.height(), 64) wri_s.setcolor(yellow, black) wri_s.printstring('Chip:{:5.1f}C'.format( pir.temperature())) wri_s.set_textpos(ssd, 0, 90) wri_s.setcolor(red, black) wri_s.printstring('{:4d}C '.format(self.tmax)) wri_s.set_textpos(ssd, 28, 95) wri_s.setcolor(green, black) if self.mode == _HOG: wri_s.printstring('Hog ') elif self.mode == _NORM: wri_s.printstring('Norm ') else: wri_s.printstring('Auto ') wri_s.set_textpos(ssd, 64 - arial10.height(), 90) wri_s.setcolor(blue, black) wri_s.printstring('{:4d}C '.format(self.tmin)) self.rf_txt = False ssd.show() self.verbose and print(ticks_diff(ticks_ms(), t)) gc.collect()