"""
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Raspberry Pi Pico SSD1306 OLED Display (MicroPython) ┃
┃ ┃
┃ A program to display Raspberry Pi logo, text, and a ┃
┃ simple timer animation on an SSD1306 OLED display ┃
┃ connected to a Raspberry Pi Pico. ┃
┃ ┃
┃ Copyright (c) 2023 Anderson Costa ┃
┃ GitHub: github.com/arcostasi ┃
┃ License: MIT ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
"""
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import framebuf, sys
import utime
from machine import Pin
pix_res_x = 128
pix_res_y = 64
def init_i2c(scl_pin, sda_pin):
# Initialize I2C device
i2c_dev = I2C(1, scl=Pin(scl_pin), sda=Pin(sda_pin), freq=200000)
i2c_addr = [hex(ii) for ii in i2c_dev.scan()]
if not i2c_addr:
print('No I2C Display Found')
sys.exit()
else:
print("I2C Address : {}".format(i2c_addr[0]))
print("I2C Configuration: {}".format(i2c_dev))
return i2c_dev
def display_logo(oled):
# Display the Raspberry Pi logo on the OLED
buffer = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|?\x00\x01\x86@\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00~\xfc\x00\x00L'\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c \x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB)
oled.fill(0)
oled.blit(fb, 96, 0)
oled.show()
def display_text(oled):
# Display text on the OLED
oled.text("Raspberry Pi", 5, 5)
oled.text("Pico", 5, 15)
oled.show()
def display_anima(oled):
# Display a simple timer animation on the OLED
start_time = utime.ticks_ms()
while True:
elapsed_time = (utime.ticks_diff(utime.ticks_ms(), start_time) // 1000) + 1
# Clear the specific line by drawing a filled black rectangle
oled.fill_rect(5, 40, oled.width - 5, 8, 0)
oled.text("Timer:", 5, 30)
oled.text(str(elapsed_time) + " sec", 5, 40)
oled.show()
utime.sleep_ms(1000)
# Shortcut.py
def AddList(oled, array, x, y, d, c):
for i in range(len(array)):
oled.text(array[i],x ,y + i * d + 2, c)
from machine import Pin
# Config Btn
SelBtn = Pin(2, Pin.IN, Pin.PULL_UP)
ABtn = Pin(3, Pin.IN, Pin.PULL_UP)
# add mainCodes.py
#Countdown
# Need fix boot into multiple files
# megre into pri project bootcoder
def main():
i2c_dev = init_i2c(scl_pin=27, sda_pin=26)
oled = SSD1306_I2C(pix_res_x, pix_res_y, i2c_dev)
# in while
isBootM = True
indexS = 0
# ListText boot
ListBoot = [
"KMK",
"QuocraftOS",
"TesterOS",
]
# Requied import screen
#BootCoder Loader Screen
oled.text("BootCoder Menu", 2, 2, 1)
AddList(oled,ListBoot, 2, 16, 8, 1)
# Loop
while isBootM:
# show select box
# textrue any / text
# input up / down button (need make)
oled.text("<--", pix_res_x - 8 * 3, 16 + indexS * 8, 1)
# Single button Test
if not SelBtn.value():
if indexS < len(ListBoot):
indexS += 1
# clear Arrow Pri
oled.text("<--", pix_res_x - 8 * 3, 16 + indexS * 8 - 8, 0)
if indexS >= len(ListBoot):
indexS = 0
print(indexS)
# Loop number
oled.text(str(5) + " sec left", 2, pix_res_y - 8, 1)
# Waiting user appcet
if not ABtn.value():
# if else many
isBootM = False
oled.fill(0)
if indexS == ListBoot[0]:
# this default in this code / main.py
main()
elif indexS == ListBoot[1]:
import TESTER
TESTER.Main1()
elif indexS == ListBoot[2]:
import QUOCOS
QUOCOS.Main1() # any file.py must be same main
oled.show()
def thisMainPy():
print("Hello World!!")
print("Hello World!!")
print("Hello World!!")
print("Hello World!!")
def cudurison(oled):
oled.fill_rect(0,0,3,3,1)
oled.line(3,1, 2,3, 0)
if __name__ == '__main__':
main()