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 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.')
class Score(object): """Score.""" 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 draw(self): """Draw score value.""" self.display.draw_text(self.x, self.y, str(self.value), self.xfont, color565(255, 255, 255)) def game_over(self): """Display game over.""" game_over_width = self.xfont.measure_text('GAME OVER') self.display.draw_text((self.display.width // 2) - (game_over_width // 2), int(self.display.height / 1.5), 'GAME OVER', self.xfont, color565(255, 255, 255)) def increment(self, points): """Increase score by specified points.""" self.value += points self.draw() def reset(self): """Reset score.""" self.value = 0 self.display.fill_hrect(self.x, self.y, self.display.width - self.x, 7, 0)
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()