Last active
January 1, 2021 00:30
-
-
Save jfurcean/77d20ced1ccc896f9258c5ab75aaba08 to your computer and use it in GitHub Desktop.
Using a QT PY (Haxpress), Sensor, and OLED
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import board | |
import busio | |
import adafruit_tlv493d | |
import math | |
import displayio | |
import adafruit_displayio_ssd1306 | |
import terminalio | |
from adafruit_display_text import label | |
WIDTH = 128 | |
HEIGHT = 32 # Change to 64 if needed | |
displayio.release_displays() | |
i2c = board.I2C() | |
tlv = adafruit_tlv493d.TLV493D(i2c) | |
display_bus = displayio.I2CDisplay(i2c, device_address=0x3c) | |
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32) | |
splash = displayio.Group(max_size=10) | |
display.show(splash) | |
# Draw a labels | |
text = " " | |
x_label = label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=0, y=4) | |
y_label = label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=0, y=15) | |
z_label = label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=0, y=26) | |
splash.append(x_label) | |
splash.append(y_label) | |
splash.append(z_label) | |
while True: | |
x_label.text = (f"x: {tlv.magnetic[0]}") | |
y_label.text = (f"y: {tlv.magnetic[1]}") | |
z_label.text = (f"z: {tlv.magnetic[2]}") | |
print("X: %s, Y: %s, Z: %s mT" % tlv.magnetic) | |
#time.sleep(.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works. Then uncomment line 10, and