Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import math
5import adafruit_framebuf
6
7print("framebuf test will draw to the REPL")
8
9WIDTH = 32
10HEIGHT = 8
11
12buffer = bytearray(round(WIDTH * math.ceil(HEIGHT / 8)))
13fb = adafruit_framebuf.FrameBuffer(
14 buffer, WIDTH, HEIGHT, buf_format=adafruit_framebuf.MVLSB
15)
16
17
18# Ascii printer for very small framebufs!
19def print_buffer(the_fb):
20 print("." * (the_fb.width + 2))
21 for y in range(the_fb.height):
22 print(".", end="")
23 for x in range(the_fb.width):
24 if fb.pixel(x, y):
25 print("*", end="")
26 else:
27 print(" ", end="")
28 print(".")
29 print("." * (the_fb.width + 2))
30
31
32# Small function to clear the buffer
33def clear_buffer():
34 for i, _ in enumerate(buffer):
35 buffer[i] = 0
36
37
38print("Shapes test: ")
39fb.pixel(3, 5, True)
40fb.rect(0, 0, fb.width, fb.height, True)
41fb.line(1, 1, fb.width - 2, fb.height - 2, True)
42fb.fill_rect(25, 2, 2, 2, True)
43print_buffer(fb)
44
45print("Text test: ")
46# empty
47fb.fill_rect(0, 0, WIDTH, HEIGHT, False)
48
49# write some text
50fb.text("hello", 0, 0, True)
51print_buffer(fb)
52clear_buffer()
53
54# write some larger text
55fb.text("hello", 8, 0, True, size=2)
56print_buffer(fb)