Repository navigation
Expand file tree
/
Copy pathleft_rect.py
More file actions
114 lines (88 loc) · 3.03 KB
/
Copy pathleft_rect.py
File metadata and controls
114 lines (88 loc) · 3.03 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
This test will initialize the display using displayio and draw a solid white
background, a smaller black rectangle, and some white text.
"""
import board
import displayio
import analogio
import time
from adafruit_display_shapes.circle import Circle
from adafruit_display_shapes.rect import Rect
adc = analogio.AnalogIn(board.A1)
# Compatibility with both CircuitPython 8.x.x and 9.x.x.
# Remove after 8.x.x is no longer a supported release.
try:
from i2cdisplaybus import I2CDisplayBus
# from fourwire import FourWire
except ImportError:
from displayio import I2CDisplay as I2CDisplayBus
# from displayio import FourWire
import terminalio
from adafruit_display_text import label
import adafruit_displayio_ssd1306
displayio.release_displays()
oled_reset = board.D9
# Use for I2C
i2c = board.I2C() # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
display_bus = I2CDisplayBus(i2c, device_address=0x3C, reset=oled_reset)
# Use for SPI
# spi = board.SPI()
# oled_cs = board.D5
# oled_dc = board.D6
# display_bus = FourWire(spi, command=oled_dc, chip_select=oled_cs,
# reset=oled_reset, baudrate=1000000)
WIDTH = 128
HEIGHT = 64 # Change to 64 if needed
BORDER = 5
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=WIDTH, height=HEIGHT)
# Make the display context
splash = displayio.Group()
display.root_group = splash
color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFFFFFF # White
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
#splash.append(bg_sprite)
# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x000000 # Black
inner_sprite = displayio.TileGrid(
inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
)
#splash.append(inner_sprite)
# Draw a label
text = "Booting up..."
directions = label.Label(
terminalio.FONT, text=text, scale=1, color=0xFFFFFF, x=5, y=5
)
#splash.append(directions)
text = "BLANK: "
blank = label.Label(
#terminalio.FONT, text=text, scale=2, color=0xFFFFFF, x=5, y=HEIGHT // 2
terminalio.FONT, text=text, scale=2, color=0xFFFFFF, x=7, y=10
)
splash.append(blank)
text = "SUT: "
SUT = label.Label(
terminalio.FONT, text=text, scale=2, color=0xFFFFFF, x=7, y = 30
)
splash.append(SUT)
text = "ABS: "
ABS = label.Label(
terminalio.FONT, text=text, scale=2, color=0xFFFFFF, x=7, y = 50
)
splash.append(ABS)
#circle = Circle(5, 10, 5, fill=0x00FF00, outline=0xFF00FF)
#splash.append(circle)
rect = Rect(0, 1, 3 , 19, outline=0xFFFFFF, fill=0xFFFFFF,stroke=1)
splash.append(rect)
#adc.reference_voltage=3.3
while True:
time.sleep(1)
voltage=adc.value / 65535 * adc.reference_voltage
volts_str='{:03.2f}'.format(voltage)
blank.text="BLANK:"+volts_str