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 sys
5import adafruit_miniqr
6
7# For drawing filled rectangles to the console:
8out = sys.stdout
9WHITE = "\x1b[1;47m \x1b[40m"
10BLACK = " "
11
12
13def prettyprint_QR(matrix):
14 # white 4-pixel border at top
15 for _ in range(4):
16 for _ in range(matrix.width + 8):
17 out.write(WHITE)
18 print()
19 for y in range(matrix.height):
20 out.write(WHITE * 4) # 4-pixel border to left
21 for x in range(matrix.width):
22 if matrix[x, y]:
23 out.write(BLACK)
24 else:
25 out.write(WHITE)
26 out.write(WHITE * 4) # 4-pixel bporder to right
27 print()
28 # white 4-pixel border at bottom
29 for _ in range(4):
30 for _ in range(matrix.width + 8):
31 out.write(WHITE)
32 print()
33
34
35qr = adafruit_miniqr.QRCode(qr_type=3, error_correct=adafruit_miniqr.L)
36qr.add_data(b"https://www.adafruit.com")
37qr.make()
38print(qr.matrix)
39prettyprint_QR(qr.matrix)