def test(): """Test code.""" spi = SPI(1, baudrate=10000000, sck=Pin(14), mosi=Pin(13)) display = Display(spi, dc=Pin(4), cs=Pin(5), rst=Pin(2)) print("Loading fonts. Please wait.") bally = XglcdFont('fonts/Bally7x9.c', 7, 9) rototron = XglcdFont('fonts/Robotron13x21.c', 13, 21) unispace = XglcdFont('fonts/Unispace12x24.c', 12, 24) wendy = XglcdFont('fonts/Wendy7x8.c', 7, 8) print("Drawing fonts.") text_height = bally.height display.draw_text(display.width, display.height // 2 - text_height // 2, "Bally", bally, rotate=180) text_width = rototron.measure_text("ROTOTRON") display.draw_text(display.width // 2 - text_width // 2, 0, "ROTOTRON", rototron) text_width = unispace.measure_text("Unispace") text_height = unispace.height display.draw_text(display.width // 2 - text_width // 2, display.height - text_height, "Unispace", unispace, invert=True) text_width = wendy.measure_text("Wendy") display.draw_text(0, display.height // 2 - text_width // 2, "Wendy", wendy, rotate=90) display.present() sleep(10) display.cleanup() print('Done.')
def test(): """Test code.""" spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(4), cs=Pin(5), rst=Pin(2), busy=Pin(15)) print("Loading fonts. Please wait.") broadway = XglcdFont('fonts/Broadway17x15.c', 17, 15) espresso = XglcdFont('fonts/EspressoDolce18x24.c', 18, 24) rototron = XglcdFont('fonts/Robotron13x21.c', 13, 21) unispace = XglcdFont('fonts/Unispace12x24.c', 12, 24) wendy = XglcdFont('fonts/Wendy7x8.c', 7, 8) print("Drawing fonts.") text_width = rototron.measure_text("ROTOTRON") display.draw_text(64 - text_width // 2, 0, "ROTOTRON", rototron, red=True, rotate=0) text_width = espresso.measure_text("Espresso Dolce") text_height = espresso.height display.draw_text(64 - text_height // 2, 148 - text_width // 2, "Espresso Dolce", espresso, rotate=90) display.draw_text(120, 120, "Wendy", wendy, rotate=90) display.draw_text(100, 270, "Broadway", broadway, rotate=180) display.draw_text(0, 200, "Unispace", unispace, rotate=270) display.present() sleep(10) display.clear() display.sleep() print("Done.")
def __init__(self): """ docstring """ # Display spi = SPI(1, baudrate=25000000, polarity=1, phase=0, sck=Pin(18, Pin.OUT, Pin.PULL_DOWN), mosi=Pin(23, Pin.OUT, Pin.PULL_UP), miso=Pin(19, Pin.IN, Pin.PULL_UP)) self.display = ST7789(spi, 240, 240, rst=Pin(2, Pin.OUT, Pin.PULL_UP), dc=Pin(4, Pin.OUT, Pin.PULL_UP), cs=Pin(0)) self.display.init() self.display.inversion_mode(1) self.display._set_mem_access_mode(4, 0, 0, 1) self.fixed_font = XglcdFont('/fonts/FixedFont5x8.c', 5, 8) self.neato = XglcdFont('/fonts/Neato5x7.c', 5, 7, letter_count=223) self.unispace = XglcdFont('/fonts/Unispace12x24.c', 12, 24) self.f18x24 = XglcdFont('/fonts/EspressoDolce18x24.c', 18, 24) self.f7x11 = XglcdFont('fonts/Robotron7x11.c', 7, 11)
def test(): """Test code.""" spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) display.draw_image('images/Tabby128x128.raw', 0, 0, 128, 128) print("Loading fonts, please wait.") fixed_font = XglcdFont('fonts/FixedFont5x8.c', 5, 8) unispace = XglcdFont('fonts/Unispace12x24.c', 12, 24) print("Fonts loaded.") display.draw_text(0, 0, 'Not transparent', fixed_font, color565(255, 0, 255)) display.draw_text(0, 80, 'Transparent', unispace, color565(0, 128, 255), spacing=0, transparent=True) display.draw_text(0, 103, 'Background', unispace, color565(0, 128, 255), color565(255, 255, 255), spacing=0) display.draw_text(103, 20, 'Test', unispace, color565(0, 255, 128), landscape=True, spacing=2, transparent=True) display.draw_text(0, 20, 'Test', unispace, color565(128, 255, 0), landscape=True) sleep(9) display.cleanup()
def setup_screen(self): self.screen_power = Pin(m5stack.TFT_LED_PIN, Pin.OUT) self.screen_power.value(1) spi = SPI( 2, baudrate=40000000, miso=Pin(m5stack.TFT_MISO_PIN), mosi=Pin(m5stack.TFT_MOSI_PIN), sck=Pin(m5stack.TFT_CLK_PIN)) #display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17)) self.display = Display( spi, cs=Pin(m5stack.TFT_CS_PIN), dc=Pin(m5stack.TFT_DC_PIN), rst=Pin(m5stack.TFT_RST_PIN), width=320, height=240, rotation=0) self.display.clear() self.header_font = XglcdFont('/screen/m5stack/fonts/Unispace12x24.c', 12, 24) self.large_label_font = XglcdFont('/screen/m5stack/fonts/IBMPlexMono12x24.c', 12, 24) self.small_label_font = XglcdFont('/screen/m5stack/fonts/ArcadePix9x11.c', 9, 11) self.display.draw_text(0, 0, 'Loading...', self.large_label_font, color565(0, 0, 0), background=color565(255, 255, 255))
def test(): """CircuitPython Text, Shape & Sprite""" if implementation.name != 'circuitpython': print() print('This demo is for CircuitPython only!') exit() try: # Configuratoin for CS and DC pins: cs_pin = DigitalInOut(board.P0_15) dc_pin = DigitalInOut(board.P0_17) rst_pin = DigitalInOut(board.P0_20) # Setup SPI bus using hardware SPI: spi = SPI(clock=board.P0_24, MOSI=board.P0_22) # Create the ILI9341 display: display = Display(spi, dc=dc_pin, cs=cs_pin, rst=rst_pin) display.clear() # Load Fixed Font fixed = XglcdFont('fonts/FixedFont5x8.c', 5, 8, letter_count=96) # Title WIDTH = 128 text = 'CircuitPython Demo' # Measure text and center length = fixed.measure_text(text) x = int((WIDTH / 2) - (length / 2)) display.draw_text(x, 6, text, fixed, color565(255, 255, 0)) # Draw title outline display.draw_rectangle(0, 0, 127, 20, color565(0, 255, 0)) # Load sprite logo = BouncingSprite('images/blinka45x48.raw', 45, 48, 239, 319, 1, display) while True: timer = monotonic() logo.update_pos() logo.draw() # Attempt to set framerate to 30 FPS timer_dif = .033333333 - (monotonic() - timer) if timer_dif > 0: sleep(timer_dif) except KeyboardInterrupt: display.cleanup()
def test(): """Test code.""" spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) display.contrast(0) display.draw_image('images/MicroPython128x128.raw', 0, 0, 128, 128) fixed_font = XglcdFont('fonts/FixedFont5x8.c', 5, 8) contrast_range = list(range(1, 16)) + list(reversed(range(15))) for c in contrast_range: display.contrast(c) display.draw_text(30, 120, 'contrast: {0:02d}'.format(c), fixed_font, color565(255, 255, 255)) sleep(1) display.cleanup()
def __init__(self, display): """Initialize score. Args: display (SSD1351): OLED display. """ margin = 5 self.display = display self.xfont = XglcdFont('fonts/NeatoReduced5x7.c', 5, 7) self.display.draw_text(margin, 0, 'SCORE:', self.xfont, color565(255, 0, 0)) text_length = self.xfont.measure_text('SCORE: ') self.x = text_length + margin self.y = 0 self.value = 0 self.draw()
def __init__(self): #font_path = "/ArcadePix9x11.c" font_path = "/Unispace12x24.c" spi = machine.SPI(1, baudrate=1000000, miso=machine.Pin(19), mosi=machine.Pin(23), sck=machine.Pin(18)) self.__display = ili9341.Display(spi, cs=machine.Pin(15), dc=machine.Pin(2), rst=machine.Pin(4), width=320, height=240, rotation=270) self.__color_white = ili9341.color565(255, 255, 255) self.__font_obj = XglcdFont( font_path, 12, 24 ) #def __init__(self, path, width, height, start_letter=32, letter_count=96):
def __init__(self, spi1, spi2, dc=4, cs1=16, rst=17, cs2=5, rotation=270): """Initialize PwnLookup.""" # Set up display self.display = Display(spi1, dc=Pin(dc), cs=Pin(cs1), rst=Pin(rst), width=320, height=240, rotation=rotation) # Load font self.unispace = XglcdFont('fonts/Unispace12x24.c', 12, 24) # Set up Keyboard self.keyboard = TouchKeyboard(self.display, self.unispace) # Set up touchscreen self.xpt = Touch(spi2, cs=Pin(cs2), int_pin=Pin(0), int_handler=self.touchscreen_press) self.wlan = WLAN(STA_IF)
def bme280_test(c): import bme280 from ssd1351 import color565 from xglcd_font import XglcdFont font = XglcdFont('fonts/Bally7x9.c', 7, 9) try: bme = bme280.BME280(i2c=c.i2c) c.display.clear() (t, p, h) = bme.read_compensated_data() c.display.draw_text(0, 0, bme.values[0], font, color565(255, 0, 0)) c.display.draw_text(0, 20, bme.values[1], font, color565(0, 255, 0)) c.display.draw_text(0, 40, bme.values[2], font, color565(0, 0, 255)) c.display.draw_hline(0, 50, (h // 1024) * 128 // 100, color565(0, 0, 255)) print(bme.values) time.sleep(3) c.display.fill_circle(64, 64, 10, color565(255, 255, 255)) except Exception as e: c.display.clear() c.display.draw_text(0, 40, str(e), font, color565(0, 0, 255)) finally: time.sleep(2)
def get_field(self): # CONSTS square_num = 0 err_margin = 0.15 color = ili9341.color565(255, 255, 255) dict_of_values = { 4.63: 1, 3.67: 2, 3: 3, 2.47: 4, 2: 5, 1.56: 6, 1.19: 7, 0.87: 8, 0.63: 9, 5: 10 } # CONSTS END # FONT font_path = "/Unispace12x24.c" unispace = XglcdFont( font_path, 12, 24 ) #def __init__(self, path, width, height, start_letter=32, letter_count=96): # FONT END self.__display.draw_text(100, 100, "Wprowadz pole", unispace, color) # GET VOLTAGE FROM ONE OF THE MODULES while True: time.sleep_ms(10) voltage_val_1 = self.__module_1.read() * 5 / 4095 voltage_val_2 = self.__module_2.read() * 5 / 4095 print("Voltage_val_1: ", voltage_val_1, "Voltage_val_2: ", voltage_val_2) if voltage_val_1 >= 0.1: voltage = voltage_val_1 print("Voltage 1: ", voltage) base = 0 break if voltage_val_2 >= 0.1: voltage = voltage_val_2 print("Voltage 1: ", voltage) base = 10 break # PICK SQUARE NUM ACCORDING TO VOLTAGE for key in dict_of_values: if abs(key - voltage) <= err_margin: square_num = dict_of_values[key] self.__display.draw_text(100, 100, "Pole odczytane", unispace, color) sleep(2) numer_pola = str(base + square_num) self.__display.draw_text(130, 130, numer_pola, unispace, color) sleep(3) return base + square_num
def test(): """Test code.""" print('Loading Espresso Dolce font...') espresso_dolce = XglcdFont('fonts/EspressoDolce18x24.c', 18, 24) print('Font loaded.') # Baud rate of 40000000 seems about the max spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13)) display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17), width=240, height=320, rotation=0) display.draw_text(0, 0, 'Espresso Dolce 18x24', espresso_dolce, color565(0, 255, 255)) display.draw_text(0, 319, 'Espresso Dolce 18x24', espresso_dolce, color565(255, 255, 0), landscape=True) sleep(5) display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17), width=320, height=240, rotation=90) display.draw_text(0, 215, 'Espresso Dolce 18x24', espresso_dolce, color565(255, 0, 255)) display.draw_text(295, 239, 'Espresso Dolce 18x24', espresso_dolce, color565(255, 255, 255), landscape=True) sleep(5) display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17), width=240, height=320, rotation=180) display.draw_text(0, 0, 'Espresso Dolce 18x24', espresso_dolce, color565(0, 0, 255)) display.draw_text(0, 319, 'Espresso Dolce 18x24', espresso_dolce, color565(255, 0, 0), landscape=True) sleep(5) display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17), width=320, height=240, rotation=270) display.draw_text(0, 215, 'Espresso Dolce 18x24', espresso_dolce, color565(225, 0, 128)) display.draw_text(295, 239, 'Espresso Dolce 18x24', espresso_dolce, color565(0, 255, 0), landscape=True) sleep(5) display.cleanup()
def test(): rot = 0 """Test code.""" BL_Pin = 4 #backlight pin SCLK_Pin = 18 #clock pin MOSI_Pin = 19 #mosi pin MISO_Pin = 2 #miso pin RESET_Pin = 23 #reset pin DC_Pin = 16 #data/command pin CS_Pin = 5 #chip select pin Button1_Pin = 35; #right button Button2_Pin = 0; #left button button1 = Pin(Button1_Pin, Pin.IN, Pin.PULL_UP) button2 = Pin(Button2_Pin, Pin.IN, Pin.PULL_UP) BLK = Pin(BL_Pin, Pin.OUT) BLK.value(1) spi = SPI(baudrate=40000000, miso=Pin(MISO_Pin), mosi=Pin(MOSI_Pin, Pin.OUT), sck=Pin(SCLK_Pin, Pin.OUT)) display = ST7789(spi, 135, 240, cs=Pin(CS_Pin), dc=Pin(DC_Pin), rst=None) display.fill(0) def cls(): display.fill(0) display.pixel(10,10,color565(0, 255, 0)) def draw(): display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0)) display.draw_text(0, 12, 'Bally 7x9', bally, color565(0, 255, 0)) display.draw_text(0, 23, 'Broadway', broadway, color565(0, 0, 255)) display.draw_text(0, 36, 'Espresso', espresso_dolce, color565(0, 255, 255)) display.draw_text(0, 64, 'Fixed Font 5x8', fixed_font, color565(255, 0, 255)) display.draw_text(0, 76, 'Neato 5x7', neato, color565(255, 255, 0)) display.draw_text(0, 85, 'Robotron 7x11', robotron, color565(255, 255, 255)) display.draw_text(0, 96, 'Unispace', unispace, color565(255, 128, 0)) display.draw_text(0, 120, 'Wendy 7x8', wendy, color565(255, 0, 128)) sleep(2) arcadepix = XglcdFont('fonts/ArcadePix9x11.c', 9, 11) bally = XglcdFont('fonts/Bally7x9.c', 7, 9) broadway = XglcdFont('fonts/Broadway17x15.c', 17, 15) espresso_dolce = XglcdFont('fonts/EspressoDolce18x24.c', 18, 24) fixed_font = XglcdFont('fonts/FixedFont5x8.c', 5, 8) neato = XglcdFont('fonts/Neato5x7.c', 5, 7, letter_count=223) robotron = XglcdFont('fonts/Robotron7x11.c', 7, 11) unispace = XglcdFont('fonts/Unispace12x24.c', 12, 24) wendy = XglcdFont('fonts/Wendy7x8.c', 7, 8) while True: cls() draw() sleep(1) cls() display.draw_text(0, 127, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0), landscape=True) display.draw_text(12, 127, 'Bally 7x9', bally, color565(0, 255, 0), landscape=True) display.draw_text(23, 127, 'Broadway', broadway, color565(0, 0, 255), landscape=True) display.draw_text(36, 127, 'Espresso', espresso_dolce, color565(0, 255, 255), landscape=True) display.draw_text(64, 127, 'Fixed Font 5x8', fixed_font, color565(255, 0, 255), landscape=True) display.draw_text(76, 127, 'Neato 5x7', neato, color565(255, 255, 0), landscape=True) display.draw_text(85, 127, 'Robotron 7x11', robotron, color565(255, 255, 255), landscape=True) display.draw_text(96, 127, 'Unispace', unispace, color565(255, 128, 0), landscape=True) display.draw_text(120, 127, 'Wendy 7x8', wendy, color565(255, 0, 128), landscape=True) sleep(1) display.fill(0) display.fill(color565(0, 0, 255)) display.fill(0) display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0), background=color565(0, 255, 255)) display.draw_text(0, 12, 'Bally 7x9', bally, color565(0, 255, 0), background=color565(0, 0, 128)) display.draw_text(0, 23, 'Broadway', broadway, color565(0, 0, 255), background=color565(255, 255, 0)) display.draw_text(0, 36, 'Espresso', espresso_dolce, color565(0, 255, 255), background=color565(255, 0, 0)) display.draw_text(0, 64, 'Fixed Font 5x8', fixed_font, color565(255, 0, 255), background=color565(0, 128, 0)) display.draw_text(0, 76, 'Neato 5x7', neato, color565(255, 255, 0), background=color565(0, 0, 255)) display.draw_text(0, 85, 'Robotron 7x11', robotron, color565(255, 255, 255), background=color565(128, 128, 128)) display.draw_text(0, 96, 'Unispace', unispace, color565(255, 128, 0), background=color565(0, 128, 255)) display.draw_text(0, 120, 'Wendy 7x8', wendy, color565(255, 0, 128), background=color565(255, 255, 255)) sleep(1)
from xglcd_font import XglcdFont if os.environ.get('MOCK_RPI') == 'true': from soft_display import mock_gpio, Glcd mock_gpio() else: from st7565 import Glcd glcd = Glcd(rgb=[21, 20, 16]) glcd.init() glcd.set_backlight_color(0, 100, 0) x0, y0 = 40, 31 rout, rmid, rin = 30, 20, 10 incr = 2 wendy = XglcdFont(root + '/fonts/Wendy7x8.c', 7, 8) ship = glcd.load_bitmap(root + '/images/ship_38x29.raw', width=38, height=29, invert=True) for angle in range(0, 360, incr): glcd.clear_back_buffer() glcd.draw_rectangle(0, 0, 128, 64) glcd.draw_string("Angle: {0}".format(angle), wendy, 85, 2, spacing=0) glcd.draw_bitmap(ship, 87, 32) glcd.draw_polygon(6, x0, y0, rout, rotate=angle - 180, color=1) glcd.draw_polygon(5, x0, y0, rmid, rotate=-angle, color=1) glcd.fill_polygon(3, x0, y0, rin, rotate=angle, color=1)
def test(): """Test code.""" spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) print("Loading fonts, please wait.") arcadepix = XglcdFont('fonts/ArcadePix9x11.c', 9, 11) bally = XglcdFont('fonts/Bally7x9.c', 7, 9) broadway = XglcdFont('fonts/Broadway17x15.c', 17, 15) espresso_dolce = XglcdFont('fonts/EspressoDolce18x24.c', 18, 24) fixed_font = XglcdFont('fonts/FixedFont5x8.c', 5, 8) neato = XglcdFont('fonts/Neato5x7.c', 5, 7, letter_count=223) robotron = XglcdFont('fonts/Robotron7x11.c', 7, 11) unispace = XglcdFont('fonts/Unispace12x24.c', 12, 24) wendy = XglcdFont('fonts/Wendy7x8.c', 7, 8) print("Fonts loaded.") display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0)) display.draw_text(0, 12, 'Bally 7x9', bally, color565(0, 255, 0)) display.draw_text(0, 23, 'Broadway', broadway, color565(0, 0, 255)) display.draw_text(0, 36, 'Espresso', espresso_dolce, color565(0, 255, 255)) display.draw_text(0, 64, 'Fixed Font 5x8', fixed_font, color565(255, 0, 255)) display.draw_text(0, 76, 'Neato 5x7', neato, color565(255, 255, 0)) display.draw_text(0, 85, 'Robotron 7x11', robotron, color565(255, 255, 255)) display.draw_text(0, 96, 'Unispace', unispace, color565(255, 128, 0)) display.draw_text(0, 120, 'Wendy 7x8', wendy, color565(255, 0, 128)) sleep(9) display.clear() display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0), landscape=True) display.draw_text(12, 0, 'Bally 7x9', bally, color565(0, 255, 0), landscape=True) display.draw_text(23, 0, 'Broadway', broadway, color565(0, 0, 255), landscape=True) display.draw_text(36, 0, 'Espresso', espresso_dolce, color565(0, 255, 255), landscape=True) display.draw_text(64, 0, 'Fixed Font 5x8', fixed_font, color565(255, 0, 255), landscape=True) display.draw_text(76, 0, 'Neato 5x7', neato, color565(255, 255, 0), landscape=True) display.draw_text(85, 0, 'Robotron 7x11', robotron, color565(255, 255, 255), landscape=True) display.draw_text(96, 0, 'Unispace', unispace, color565(255, 128, 0), landscape=True) display.draw_text(120, 0, 'Wendy 7x8', wendy, color565(255, 0, 128), landscape=True) sleep(9) display.clear() display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0), background=color565(0, 255, 255)) display.draw_text(0, 12, 'Bally 7x9', bally, color565(0, 255, 0), background=color565(0, 0, 128)) display.draw_text(0, 23, 'Broadway', broadway, color565(0, 0, 255), background=color565(255, 255, 0)) display.draw_text(0, 36, 'Espresso', espresso_dolce, color565(0, 255, 255), background=color565(255, 0, 0)) display.draw_text(0, 64, 'Fixed Font 5x8', fixed_font, color565(255, 0, 255), background=color565(0, 128, 0)) display.draw_text(0, 76, 'Neato 5x7', neato, color565(255, 255, 0), background=color565(0, 0, 255)) display.draw_text(0, 85, 'Robotron 7x11', robotron, color565(255, 255, 255), background=color565(128, 128, 128)) display.draw_text(0, 96, 'Unispace', unispace, color565(255, 128, 0), background=color565(0, 128, 255)) display.draw_text(0, 120, 'Wendy 7x8', wendy, color565(255, 0, 128), background=color565(255, 255, 255)) sleep(9) display.cleanup()
display.fill_hrect(1, 53, water_level, 18, color) display.fill_hrect(water_level + 1, 53, 121 - water_level, 18, color565(0, 0, 0)) display.draw_text(37, 40, str(water_level) + '/' + str(MAX_WATER) + ' ', bally, color565(255, 255, 255)) if spi is None: spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) display.draw_image('MicroPython128x128.raw', 0, 0, 128, 128) sleep(1) display.clear() bally = XglcdFont('Bally7x9.c', 7, 9) display.draw_text(0, 0, 'Diesel:', bally, color565(255, 255, 255)) display.draw_text(0, 40, 'Vann:', bally, color565(255, 255, 255)) display.draw_text(0, 80, 'Septik:', bally, color565(255, 255, 255)) display.draw_rectangle(0, 12, 120, 20, color565(255, 255, 255)) display.draw_rectangle(0, 52, 120, 20, color565(255, 255, 255)) display.draw_rectangle(0, 92, 120, 20, color565(255, 255, 255)) adc = ADC(Pin(35)) adc.atten(adc.ATTN_11DB) #normalized to 3.3v while True: # read_septic() read_water() sleep(0.1)
spi = SPI(1, baudrate=32000000, sck=Pin(18), mosi=Pin(23), miso=Pin(19)) display = Display(spi, dc=Pin(26), cs=Pin(5), rst=Pin(25), rotation=270, width=320, height=240) display.clear() return display DISPLAY = initialize_display() # To display images PHOTORESISTOR = ADC(Pin(32)) # To sense if lid is open of closed SERVO = PWM(Pin(4), freq=50, duty=70) # To notify the user unispace_font = XglcdFont('Unispace12x24.c', 12, 24) # this file needs to exist in the root lbox = LetterBox(DISPLAY, SERVO, PHOTORESISTOR, unispace_font) try: if lbox.initialize(): lbox.bootup() loop = get_event_loop() loop.create_task(lbox.poll_async()) loop.run_forever() finally: print("Didn't start LetterBox.") DISPLAY.clear() DISPLAY.draw_text(0, 54, 'Something went wrong!', unispace_font, 65535) DISPLAY.draw_text(0, 90, "LetterBox cannot continue.", unispace_font, 65535) DISPLAY.draw_text(0, 126, "Please contact us for help.", unispace_font,
display.init() spi2 = machine.SPI(1, baudrate=10000000, sck=machine.Pin(27), mosi=machine.Pin(21)) oled = Display(spi2, dc=machine.Pin(13), cs=machine.Pin(26), rst=machine.Pin(22)) fonts = [ "astrol.fnt", "cyrilc.fnt", "gotheng.fnt", "greeks.fnt", "italicc.fnt", "italiccs.fnt", "meteo.fnt", "music.fnt", "romanc.fnt", "romancs.fnt", "romand.fnt", "romanp.fnt", "romans.fnt", "romant.fnt", "scriptc.fnt", "scripts.fnt" ] perfect_big = XglcdFont('PerfectPixel_23x32.c', 23, 32) perfect_small = XglcdFont('PerfectPixel_18x25.c', 18, 25) # turn on the backlight on IPS p = machine.Pin(4, machine.Pin.OUT) p.value(1) utc_shift = 3 def sync_time(): #пробуем синхронизировать время try: ntptime.settime() time.sleep(1) except Exception as ex: time.sleep(15) else:
baudrate=80000000, mosi=machine.Pin(13), sck=machine.Pin(14)) display = ili9341.Display(spi, cs=pca.pin(5), dc=pca.pin(3), rst=pca.pin(4), width=SCREEN_W, height=SCREEN_H, rotation=270) #display = ILI9341( spi, cs=pca.pin(5), dc=pca.pin(3), rst=pca.pin(4), w=SCREEN_W, h=SCREEN_H, r=1) #display.set_font(tt14) #display.erase() #buf = bytearray( SCREEN_W * SCREEN_H * 2 ) #fb = framebuf.FrameBuffer( buf, SCREEN_W, SCREEN_H, framebuf.RGB565 ) arcadepix = XglcdFont('ArcadePix9x11.c', 9, 11) buzz = machine.PWM(machine.Pin(4), freq=800, duty=512) time.sleep_ms(500) buzz.deinit() while True: #display.erase() #display.fill_rectangle( 0, 0, 100, 40 ) #display.set_pos( 20, 20 ) display.draw_text(20, 20, '{:8d}, {:8d}'.format(adc.read(channel1=0), adc.read(channel1=1)), font=arcadepix, color=0xffff)
from time import sleep_ms from controller_box import controller as c from ssd1351 import color565 from xglcd_font import XglcdFont font = XglcdFont('fonts/Bally7x9.c', 7, 9) maxduty = const(122) minduty = const(30) def polygon_select(): e = c.encoder display = c.display colors = [ (255, 0, 0), (153, 50, 0), (0, 255, 0), (0, 0, 255), (0, 0, 0), (255, 255, 0), (0, 255, 255), ] names = [ 'Victor', 'Olav', 'Ina', 'Dagfinn', 'Sebastian',
def test(): """Test code.""" # Baud rate of 40000000 seems about the max spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13)) display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17)) print('Loading fonts...') print('Loading arcadepix') arcadepix = XglcdFont('fonts/ArcadePix9x11.c', 9, 11) print('Loading bally') bally = XglcdFont('fonts/Bally7x9.c', 7, 9) print('Loading broadway') broadway = XglcdFont('fonts/Broadway17x15.c', 17, 15) print('Loading espresso_dolce') espresso_dolce = XglcdFont('fonts/EspressoDolce18x24.c', 18, 24) print('Loading fixed_font') fixed_font = XglcdFont('fonts/FixedFont5x8.c', 5, 8) print('Loading neato') neato = XglcdFont('fonts/Neato5x7.c', 5, 7, letter_count=223) print('Loading robotron') robotron = XglcdFont('fonts/Robotron13x21.c', 13, 21) print('Loading unispace') unispace = XglcdFont('fonts/Unispace12x24.c', 12, 24) print('Loading wendy') wendy = XglcdFont('fonts/Wendy7x8.c', 7, 8) print('Fonts loaded.') display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0)) display.draw_text(0, 22, 'Bally 7x9', bally, color565(0, 255, 0)) display.draw_text(0, 43, 'Broadway 17x15', broadway, color565(0, 0, 255)) display.draw_text(0, 66, 'Espresso Dolce 18x24', espresso_dolce, color565(0, 255, 255)) display.draw_text(0, 104, 'Fixed Font 5x8', fixed_font, color565(255, 0, 255)) display.draw_text(0, 125, 'Neato 5x7', neato, color565(255, 255, 0)) display.draw_text(0, 155, 'ROBOTRON 13X21', robotron, color565(255, 255, 255)) display.draw_text(0, 190, 'Unispace 12x24', unispace, color565(255, 128, 0)) display.draw_text(0, 220, 'Wendy 7x8', wendy, color565(255, 0, 128)) sleep(9) display.clear() display.draw_text(0, 255, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0), landscape=True) display.draw_text(22, 255, 'Bally 7x9', bally, color565(0, 255, 0), landscape=True) display.draw_text(43, 255, 'Broadway 17x15', broadway, color565(0, 0, 255), landscape=True) display.draw_text(66, 255, 'Espresso Dolce 18x24', espresso_dolce, color565(0, 255, 255), landscape=True) display.draw_text(104, 255, 'Fixed Font 5x8', fixed_font, color565(255, 0, 255), landscape=True) display.draw_text(125, 255, 'Neato 5x7', neato, color565(255, 255, 0), landscape=True) display.draw_text(155, 255, 'ROBOTRON 13X21', robotron, color565(255, 255, 255), landscape=True) display.draw_text(190, 255, 'Unispace 12x24', unispace, color565(255, 128, 0), landscape=True) display.draw_text(220, 255, 'Wendy 7x8', wendy, color565(255, 0, 128), landscape=True) sleep(9) display.clear() display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0), background=color565(0, 255, 255)) display.draw_text(0, 22, 'Bally 7x9', bally, color565(0, 255, 0), background=color565(0, 0, 128)) display.draw_text(0, 43, 'Broadway', broadway, color565(0, 0, 255), background=color565(255, 255, 0)) display.draw_text(0, 66, 'Espresso', espresso_dolce, color565(0, 255, 255), background=color565(255, 0, 0)) display.draw_text(0, 104, 'Fixed Font 5x8', fixed_font, color565(255, 0, 255), background=color565(0, 128, 0)) display.draw_text(0, 125, 'Neato 5x7', neato, color565(255, 255, 0), background=color565(0, 0, 255)) display.draw_text(0, 155, 'ROBOTRON 13X21', robotron, color565(255, 255, 255), background=color565(128, 128, 128)) display.draw_text(0, 190, 'Unispace', unispace, color565(255, 128, 0), background=color565(0, 128, 255)) display.draw_text(0, 220, 'Wendy 7x8', wendy, color565(255, 0, 128), background=color565(255, 255, 255)) sleep(9) display.cleanup()
import math import time import sys import os root = os.path.dirname(os.path.realpath(__file__)) from xglcd_font import XglcdFont if os.environ.get('MOCK_RPI') == 'true': from soft_display import mock_gpio, Glcd mock_gpio() else: from st7565 import Glcd neato = XglcdFont(root + '/fonts/Neato5x7.c', 5, 7) glcd = Glcd(rgb=[21, 20, 16]) glcd.init() x0, y0 = 63, 31 def get_face_xy(angle, radius): """ Get x,y coordinates on face at specified angle and radius """ theta = math.radians(angle) x = int(x0 + radius * math.cos(theta)) y = int(y0 + radius * math.sin(theta)) return x, y def draw_face():
import uasyncio as asyncio import time PIN_DISPLAY_MOSI = 27 PIN_DISPLAY_CLK = 25 PIN_DISPLAY_CS = 32 PIN_DISPLAY_RST = 21 PIN_DISPLAY_DC = 17 PIN_KNOB_CLK = 18 PIN_KNOB_DT = 23 PIN_KNOB_SWITCH = 19 FONT_UNISPACE = XglcdFont("fonts/Unispace12x24.c", 12, 24) FONT_FIXED = XglcdFont("fonts/FixedFont5x8.c", 5, 7) class RotaryEncoder(object): def __init__(self, pin_clk, pin_dt, delay=100, cw=None, ccw=None): self._rotary = RotaryIRQ(pin_clk, pin_dt) self._delay = delay self._cb_cw = cw self._cb_ccw = ccw loop = asyncio.get_event_loop() loop.create_task(self.check()) async def check(self):
from microWebSrv import MicroWebSrv import gc t = time.time() #oled spi = SPI(2, baudrate=14500000, sck=Pin(26), mosi=Pin(27)) display = Display(spi, dc=Pin(33), cs=Pin(25), rst=Pin(32), width=128, height=128) #font导入 robotron = XglcdFont('Robotron13x21.c', 13, 21) robotronm = XglcdFont('Robotron7x11.c', 7, 11) espressodolc = XglcdFont('EspressoDolce18x24.c', 18, 24) fixedfont = XglcdFont('FixedFont5x8.c', 5, 8) def wjson(a, b, c, d, e, f): df = {} df['wifiname'] = a df['wifipassword'] = b df['set_password'] = c df['bli'] = d df['keys'] = e df['city'] = f f = open("config.json", 'wb') f.write(ujson.dumps(df))