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) colors.sort() c = 0 for x in range(1, 126, 25): for y in range(1, 126, 25): display.draw_filledRectangle(x, y, 25, 25, colors[c]) c += 1 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(): """Test code.""" display = Display(spi, SPI_CS, SPI_DC) display.draw_image('images/RaspberryPiWB128x128.raw', 0, 0, 128, 128) sleep(5) display.draw_image('images/MicroPython128x128.raw', 0, 0, 128, 128) sleep(5) display.draw_image('images/Tabby128x128.raw', 0, 0, 128, 128) sleep(5) display.draw_image('images/Tortie128x128.raw', 0, 0, 128, 128) sleep(10) 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()
'Damped Oscillator', fgcolor=Display.WHITE, bdcolor=Display.WHITE) refresh(st7735) 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) 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) cart() time.sleep(25) st7735.cleanup()
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()
def main(): """Initialize display.""" 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 # Baud rate of 14500000 seems about the max spi = SPI(2, baudrate=32000000, sck=sck, mosi=mosi, miso=miso) display = Display(spi, SPI_CS, SPI_DC) # spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) # Draw background image display.draw_image('images/Arkanoid_Border128x118.raw', 0, 10, 128, 118) # Initialize ADC on VP pin 36 adc = ADC(Pin(36)) # Set attenuation 0-3.3V adc.atten(ADC.ATTN_11DB) # Seed random numbers seed(ticks_us()) # Generate bricks MAX_LEVEL = const(9) level = 1 bricks = load_level(level, display) # Initialize paddle paddle = Paddle(display) # Initialize score score = Score(display) # Initialize balls balls = [] # Add first ball balls.append(Ball(59, 111, -2, -1, display, frozen=True)) # Initialize lives lives = [] for i in range(1, 3): lives.append(Life(i, display)) # Initialize power-ups powerups = [] try: while True: timer = ticks_us() # Set paddle position to ADC spinner (scale 6 - 98) paddle.h_position((4096 - adc.read()) // 44 + 5) # Handle balls score_points = 0 for ball in balls: # Position ball.set_position(paddle.x, paddle.y, paddle.x2, paddle.center) # Check for collision with bricks if not frozen if not ball.frozen: prior_collision = False ball_x = ball.x ball_y = ball.y ball_x2 = ball.x2 ball_y2 = ball.y2 ball_center_x = ball.x + ((ball.x2 + 1 - ball.x) // 2) ball_center_y = ball.y + ((ball.y2 + 1 - ball.y) // 2) # Check for hits for brick in bricks: if (ball_x2 >= brick.x and ball_x <= brick.x2 and ball_y2 >= brick.y and ball_y <= brick.y2): # Hit if not prior_collision: ball.x_speed, ball.y_speed = brick.bounce( ball.x, ball.y, ball.x2, ball.y2, ball.x_speed, ball.y_speed, ball_center_x, ball_center_y) prior_collision = True score_points += 1 brick.clear() bricks.remove(brick) # Generate random power-ups if score_points > 0 and randint(1, 20) == 7: powerups.append(Powerup(ball.x, 64, display)) # Check for missed if ball.y2 > display.height - 3: ball.clear_previous() balls.remove(ball) if not balls: # Clear powerups powerups.clear() # Lose life if last ball on screen if len(lives) == 0: score.game_over() else: # Subtract Life lives.pop().clear() # Add ball balls.append( Ball(59, 112, 2, -3, display, frozen=True)) else: # Draw ball ball.draw() # Update score if changed if score_points: score.increment(score_points) # Handle power-ups for powerup in powerups: powerup.set_position(paddle.x, paddle.y, paddle.x2, paddle.center) powerup.draw() if powerup.collected: # Power-up collected powerup.clear() # Add ball balls.append( Ball(powerup.x, 112, 2, -1, display, frozen=False)) powerups.remove(powerup) elif powerup.y2 > display.height - 3: # Power-up missed powerup.clear() powerups.remove(powerup) # Check for level completion if not bricks: for ball in balls: ball.clear() balls.clear() for powerup in powerups: powerup.clear() powerups.clear() level += 1 if level > MAX_LEVEL: level = 1 bricks = load_level(level, display) balls.append(Ball(59, 111, -2, -1, display, frozen=True)) # 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()
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()