Created
July 26, 2024 11:06
-
-
Save qbalsdon/7f66e9f214c96de874e3745c46335de5 to your computer and use it in GitHub Desktop.
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
# PicoBricks output to OLED | |
# Thonny IDE | |
# Useful links: | |
# https://picobricks.com/blogs/robotic-stem-projects/thermometer | |
# https://github.com/Robotistan/PicoBricks/blob/cc9fe87cbb75d4305b4175dd691fd09f3d90fdeb/Software/Pre-Installed%20Code/picobricks.py#L660 | |
import utime # time library | |
from machine import Pin, I2C # to access the hardware | |
from picobricks import SSD1306_I2C # oled library on picobricks | |
# define the width and height picobricks screen | |
WIDTH=128 | |
HEIGHT=64 | |
LETTER_WIDTH_PX = 8 # experimental guess | |
# would need a proper fn to calc text width / height | |
# we define sda and scl pins for inter-path communication | |
sda=machine.Pin(4) | |
scl=machine.Pin(5) | |
i2c=machine.I2C(id=0, sda=sda, scl=scl, freq=2000000)#determine the frequency values | |
oled=SSD1306_I2C(width=WIDTH, height=HEIGHT, i2c=i2c, addr=0x3C, external_vcc=False) | |
display_text = "Hello world!" | |
current_x = 0 | |
direction_x = 1 | |
speed_x = 2 | |
current_y = 0 | |
print(i2c.scan()) # identify the device addresses connected | |
utime.sleep(1) | |
while True: | |
oled.fill(0) # clear OLED | |
oled.text(display_text, current_x, current_y) | |
oled.show() # show on OLED | |
current_x += speed_x * direction_x | |
if current_x >= (WIDTH - (LETTER_WIDTH_PX * len(display_text))): | |
direction_x = -1 | |
if current_x <= 0: | |
direction_x = 1 | |
current_y += 1 | |
if current_y > HEIGHT - 8: | |
current_y = 0 | |
utime.sleep(0.06) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment