/ examples / ra8875_simpletest.py
ra8875_simpletest.py
 1  # Quick test of RA8875 with Feather M4
 2  import time
 3  import busio
 4  import digitalio
 5  import board
 6  
 7  import adafruit_ra8875.ra8875 as ra8875
 8  from adafruit_ra8875.ra8875 import color565
 9  
10  BLACK = color565(0, 0, 0)
11  RED = color565(255, 0, 0)
12  BLUE = color565(0, 255, 0)
13  GREEN = color565(0, 0, 255)
14  YELLOW = color565(255, 255, 0)
15  CYAN = color565(0, 255, 255)
16  MAGENTA = color565(255, 0, 255)
17  WHITE = color565(255, 255, 255)
18  
19  # Configuration for CS and RST pins:
20  cs_pin = digitalio.DigitalInOut(board.D9)
21  rst_pin = digitalio.DigitalInOut(board.D10)
22  int_pin = digitalio.DigitalInOut(board.D11)
23  
24  # Config for display baudrate (default max is 6mhz):
25  BAUDRATE = 6000000
26  
27  # Setup SPI bus using hardware SPI:
28  spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
29  
30  # Create and setup the RA8875 display:
31  display = ra8875.RA8875(spi, cs=cs_pin, rst=rst_pin, baudrate=BAUDRATE)
32  display.init()
33  
34  display.fill(RED)
35  time.sleep(0.500)
36  display.fill(YELLOW)
37  time.sleep(0.500)
38  display.fill(BLUE)
39  time.sleep(0.500)
40  display.fill(CYAN)
41  time.sleep(0.500)
42  display.fill(MAGENTA)
43  time.sleep(0.500)
44  display.fill(BLACK)
45  display.circle(100, 100, 50, BLACK)
46  display.fill_circle(100, 100, 49, BLUE)
47  
48  display.fill_rect(10, 10, 400, 200, GREEN)
49  display.rect(10, 10, 400, 200, BLUE)
50  display.fill_round_rect(200, 10, 200, 100, 10, RED)
51  display.round_rect(200, 10, 200, 100, 10, BLUE)
52  display.pixel(10, 10, BLACK)
53  display.pixel(11, 11, BLACK)
54  display.line(10, 10, 200, 100, RED)
55  display.fill_triangle(200, 15, 250, 100, 150, 125, YELLOW)
56  display.triangle(200, 15, 250, 100, 150, 125, BLACK)
57  display.fill_ellipse(300, 100, 100, 40, BLUE)
58  display.ellipse(300, 100, 100, 40, RED)
59  display.curve(50, 100, 80, 40, 2, BLACK)
60  display.fill_curve(50, 100, 78, 38, 2, WHITE)
61  
62  display.txt_set_cursor(display.width // 2 - 200, display.height // 2 - 20)
63  display.txt_trans(WHITE)
64  display.txt_size(2)
65  testvar = 99
66  display.txt_write("Player Score: " + str(testvar))
67  
68  display.touch_init(int_pin)
69  display.touch_enable(True)
70  
71  x_scale = 1024 / display.width
72  y_scale = 1024 / display.height
73  
74  # Main loop:
75  while True:
76      if display.touched():
77          coords = display.touch_read()
78          display.fill_circle(
79              int(coords[0] / x_scale), int(coords[1] / y_scale), 4, MAGENTA
80          )
81          display.txt_color(WHITE, BLACK)
82          display.txt_set_cursor(display.width // 2 - 220, display.height // 2 - 20)
83          display.txt_size(2)
84          display.txt_write(
85              "Position ("
86              + str(int(coords[0] / x_scale))
87              + ", "
88              + str(int(coords[1] / y_scale))
89              + ")"
90          )