-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
95 lines (82 loc) · 2.77 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Basic example of using framebuf capabilities on a SSD1306 OLED display.
# This example and library is meant to work with Adafruit CircuitPython API.
# Author: Tony DiCola
# This example modified to work with XBee3 MicroPython
# Edited by: Steve Dowey
# License: Public Domain
# Import all board pins.
import time
from machine import I2C
# Import the SSD1306 module.
import xbee3_ssd1306
# create an I2C peripheral.
i2c = I2C(1)
# note we need to use writeto as there is only one i2c allowed
# A reset line may be required if there is no auto-reset circuitry
reset_pin = None
# Create the SSD1306 OLED class.
# The first two parameters are the pixel width and pixel height. Change these
# to the right size for your display!
# The I2C address for these displays is 0x3d or 0x3c, change to match
# A reset line may be required if there is no auto-reset circuitry
display = xbee3_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3C, reset=reset_pin)
print(
"Framebuf capability test - these are slow and minimal but don't require"
"a special graphics management library, only `xbee3_framebuf.py`"
)
print("Pixel test")
# Clear the display. Always call show after changing pixels to make the display
# update visible!
display.fill(0)
display.show()
# Set a pixel in the origin 0,0 position.
display.pixel(0, 0, 1)
# Set a pixel in the middle position.
display.pixel(display.width // 2, display.height // 2, 1)
# Set a pixel in the opposite corner position.
display.pixel(display.width - 1, display.height - 1, 1)
display.show()
time.sleep(0.1)
print("Lines test")
# we'll draw from corner to corner, lets define all the pair coordinates here
corners = (
(0, 0),
(0, display.height - 1),
(display.width - 1, 0),
(display.width - 1, display.height - 1),
)
display.fill(0)
for corner_from in corners:
for corner_to in corners:
display.line(corner_from[0], corner_from[1], corner_to[0], corner_to[1], 1)
display.show()
time.sleep(0.1)
print("Rectangle test")
display.fill(0)
w_delta = display.width / 10
h_delta = display.height / 10
for i in range(11):
display.rect(0, 0, int(w_delta * i), int(h_delta * i), 1)
display.show()
time.sleep(0.1)
print("Text test")
display.fill(0)
try:
display.text("hello world", 0, 0, 1)
display.show()
time.sleep(1)
display.fill(0)
char_width = 6
char_height = 8
chars_per_line = display.width // 6
for i in range(255):
x = char_width * (i % chars_per_line)
y = char_height * (i // chars_per_line)
display.text(chr(i), x, y, 1)
display.show()
except OSError:
print(
"To test the framebuf font setup, you'll need the font5x8.bin file from "
+ "https://github.com/adafruit/Adafruit_CircuitPython_framebuf/tree/master/examples"
+ " in the same directory as this script"
)