def test(): """Bouncing box.""" display=Display(spi,SPI_CS,SPI_DC) try: display.clear() colors = [color565(255, 0, 0), color565(0, 255, 0), color565(0, 0, 255), color565(255, 255, 0), color565(0, 255, 255), color565(255, 0, 255)] sizes = [12, 11, 10, 9, 8, 7] boxes = [Box(128, 128, sizes[i], display, colors[i]) for i in range(6)] while True: timer = ticks_us() for b in boxes: b.update_pos() b.draw() # Attempt to set framerate to 30 FPS timer_dif = 33333 - ticks_diff(ticks_us(), timer) if timer_dif > 0: sleep_us(timer_dif) except KeyboardInterrupt: display.cleanup()
def test(): """Test code.""" display=Display(spi,SPI_CS,SPI_DC) display.clear() x, y = 0, 0 angle = 0.0 # Loop all angles from 0 to 2 * PI radians while angle < PI2: # Calculate x, y from a vector with known length and angle x = int(CENTER_X * sin(angle) + HALF_WIDTH) y = int(CENTER_Y * cos(angle) + HALF_HEIGHT) color = color565(*hsv_to_rgb(angle / PI2, 1, 1)) c0 = color & 0xff c1 = color >> 8 # print("color: {:02x} {:02x}".format(c1,c0)) display.draw_line(x, y, CENTER_X, CENTER_Y, color) angle += ANGLE_STEP_SIZE sleep(5) display.clear() for r in range(CENTER_X, 0, -1): color = color565(*hsv_to_rgb(r / HALF_WIDTH, 1, 1)) display.draw_filledCircle(CENTER_X, CENTER_Y, r, color) sleep(9) display.cleanup()
def test(): """Test code.""" display = Display(spi, SPI_CS, SPI_DC) display.clear() display.draw_text(0, 0, 'Hello World!', sysfont, color565(255, 0, 0)) display.text(20, 20, 'Good bye World!', color565(255, 0, 0)) display.draw_text(10, 100, 'Hello World!', sysfont, color565(255, 0, 0), landscape=True) sleep(9) display.cleanup()
def test(): """Bouncing sprite.""" display=Display(spi,SPI_CS,SPI_DC) try: display.clear() # Load sprite logo = BouncingSprite('images/Python41x49.raw', 41, 49, 128, 128, 1, display) while True: timer = ticks_us() logo.update_pos() logo.draw() # Attempt to set framerate to 30 FPS timer_dif = 33333 - ticks_diff(ticks_us(), timer) if timer_dif > 0: sleep_us(timer_dif) except KeyboardInterrupt: display.cleanup()
def drawSin(color): oled.draw_hline(0, hSize // 2, wSize - 1, color) oled.draw_vline(0, 0, hSize - 1, color) for i in range(0, wSize): oled.draw_pixel( i, round(-sin(2 * pi * i / wSize) * hSize // 2) + hSize // 2, color) oled.draw_text(wSize // 4, hSize // 5, "sin(x)", sysfont, color) spi = SPI(2, baudrate=32000000, sck=sck, mosi=mosi, miso=miso) oled = Display(spi, SPI_CS, SPI_DC) oled.clear() print("Draw line test") oled.clear() testDrawLine(oled.YELLOW) sleep(1) oled.clear() print("Draw rectangle test") testDrawRect(oled.BLUE) time.sleep(1) oled.clear() print("Draw filled rectangle test") testFillRect(oled.DARKGREEN, oled.GREEN) time.sleep(1) oled.clear() print("Draw circle test") testDrawCircles()
def test(): """Test code.""" display=Display(spi,SPI_CS,SPI_DC) print('display started') display.clear(color565(64, 0, 255)) sleep(1) display.clear() display.draw_hline(10, 127, 63, color565(255, 0, 255)) sleep(1) display.draw_vline(10, 0, 127, color565(0, 255, 255)) sleep(1) display.draw_filledRectangle(23, 50, 30, 75, color565(255, 255, 255)) sleep(1) display.draw_hline(0, 0, 127, color565(255, 0, 0)) sleep(1) display.draw_line(127, 0, 64, 127, color565(255, 255, 0)) sleep(2) display.clear() coords = [[0, 63], [78, 80], [122, 92], [50, 50], [78, 15], [0, 63]] display.draw_lines(coords, color565(0, 255, 255)) sleep(1) display.clear() display.draw_filledPolygon(7, 63, 63, 50, color565(0, 255, 0)) sleep(1) display.draw_filledRectangle(0, 0, 15, 127, color565(255, 0, 0)) sleep(1) display.clear() display.draw_filledRectangle(0, 0, 63, 63, color565(128, 128, 255)) sleep(1) display.draw_rectangle(0, 64, 63, 63, color565(255, 0, 255)) sleep(1) display.draw_filledRectangle(64, 0, 63, 63, color565(128, 0, 255)) sleep(1) display.draw_polygon(3, 96, 96, 30, color565(0, 64, 255), rotate=15) sleep(3) display.clear() display.draw_filledCircle(32, 32, 30, color565(0, 255, 0)) sleep(1) display.draw_circle(32, 96, 30, color565(0, 0, 255)) sleep(1) display.draw_filledEllipse(96, 32, 30, 16, color565(255, 0, 0)) sleep(1) display.draw_ellipse(96, 96, 16, 30, color565(255, 255, 0)) sleep(5) display.cleanup()
def test(): """Test code.""" display = Display(spi, SPI_CS, SPI_DC) display.clear() display.text(0, 0, 'Arcade Pix 9x11', color565(255, 0, 0), ArcadePix9x11) display.text(0, 12, 'Bally 7x9', color565(0, 255, 0), Bally7x9) display.text(0, 23, 'Broadway', color565(0, 0, 255), Broadway17x15) display.text(0, 36, 'Espresso', color565(0, 255, 255), EspressoDolce18x24) display.text(0, 64, 'Fixed Font 5x8', color565(255, 0, 255), FixedFont5x8) display.text(0, 76, 'Neato 5x7', color565(255, 255, 0), Neato5x7) display.text(0, 85, 'Robotron 7x11', color565(255, 255, 255), Robotron7x11) display.text(0, 96, 'Unispace', color565(255, 128, 0), Unispace12x24) display.text(0, 120, 'Wendy 7x8', color565(255, 0, 128), Wendy7x8) display.show() sleep(5) display.fill(0) display.text(0, 127, 'Arcade Pix 9x11', color565(255, 0, 0), ArcadePix9x11, landscape=True) display.text(12, 127, 'Bally 7x9', color565(0, 255, 0), Bally7x9, landscape=True) display.text(23, 127, 'Broadway', color565(0, 0, 255), Broadway17x15, landscape=True) display.text(36, 127, 'Espresso', color565(0, 255, 255), EspressoDolce18x24, landscape=True) display.text(63, 127, 'Fixed Font 5x8', color565(255, 0, 255), FixedFont5x8, landscape=True) display.text(76, 127, 'Neato 5x7', color565(255, 255, 0), Neato5x7, landscape=True) display.text(85, 127, 'Robotron 7x11', color565(255, 255, 255), Robotron7x11, landscape=True) display.text(96, 127, 'Unispace', color565(255, 128, 0), Unispace12x24, landscape=True) display.text(120, 127, 'Wendy 7x8', color565(255, 0, 128), Wendy7x8, landscape=True) display.show() sleep(5) display.fill(0) display.text(0, 0, 'Arcade Pix 9x11', color565(255, 0, 0), ArcadePix9x11, background=color565(0, 255, 255)) display.text(0, 12, 'Bally 7x9', color565(0, 255, 0), Bally7x9, background=color565(0, 0, 128)) display.text(0, 23, 'Broadway', color565(0, 0, 255), Broadway17x15, background=color565(255, 255, 0)) display.text(0, 36, 'Espresso', color565(0, 255, 255), EspressoDolce18x24, background=color565(255, 0, 0)) display.text(0, 64, 'Fixed Font 5x8', color565(255, 0, 255), FixedFont5x8, background=color565(0, 128, 0)) display.text(0, 76, 'Neato 5x7', color565(255, 255, 0), Neato5x7, background=color565(0, 0, 255)) display.text(0, 85, 'Robotron 7x11', color565(255, 255, 255), Robotron7x11, background=color565(128, 128, 128)) display.text(0, 96, 'Unispace', color565(255, 128, 0), Unispace12x24, background=color565(0, 128, 255)) display.text(0, 120, 'Wendy 7x8', color565(255, 0, 128), Wendy7x8, background=color565(255, 255, 255)) display.show() sleep(5) display.fill(0) display.text(0, 127, 'Arcade Pix 9x11', color565(255, 0, 0), ArcadePix9x11, background=color565(0, 255, 255), landscape=True) display.text(12, 127, 'Bally 7x9', color565(0, 255, 0), Bally7x9, background=color565(0, 0, 128), landscape=True) display.text(23, 127, 'Broadway', color565(0, 0, 255), Broadway17x15, background=color565(255, 255, 0), landscape=True) display.text(36, 127, 'Espresso', color565(0, 255, 255), EspressoDolce18x24, background=color565(255, 0, 0), landscape=True) display.text(64, 127, 'Fixed Font 5x8', color565(255, 0, 255), FixedFont5x8, background=color565(0, 128, 0), landscape=True) display.text(76, 127, 'Neato 5x7', color565(255, 255, 0), Neato5x7, background=color565(0, 0, 255), landscape=True) display.text(85, 127, 'Robotron 7x11', color565(255, 255, 255), Robotron7x11, background=color565(128, 128, 128), landscape=True) display.text(96, 127, 'Unispace', color565(255, 128, 0), Unispace12x24, background=color565(0, 128, 255), landscape=True) display.text(120, 127, 'Wendy 7x8', color565(255, 0, 128), Wendy7x8, background=color565(255, 255, 255), landscape=True) display.show() sleep(5) display.cleanup()
c = color565(red, green, blue) display.draw_circle(x0, y0, radius, c) if sys.platform == 'esp8266': print('1.4 inch TFT screen test on ESP8266') SPI_CS = 16 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) display = Display(spi, SPI_CS, SPI_DC) test_lines() time.sleep(5) display.clear() test_rectangles() time.sleep(5) display.clear() test_circles() time.sleep(5) display.clear() display.cleanup()