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