Add 'CARDPUTER CircuitPython/oslike_boilerplate/code.py'
This commit is contained in:
64
CARDPUTER CircuitPython/oslike_boilerplate/code.py
Normal file
64
CARDPUTER CircuitPython/oslike_boilerplate/code.py
Normal file
@@ -0,0 +1,64 @@
|
||||
from keyb import Keyboard # type: ignore
|
||||
import time, os, rtc, json # type: ignore
|
||||
import board, busio, sdcardio, storage, terminalio, displayio # type: ignore
|
||||
from adafruit_display_text import label # type: ignore
|
||||
from adafruit_display_shapes.rect import Rect # type: ignore
|
||||
|
||||
### DEFAULT HOME PAGE # # # # # # # # # #
|
||||
def home():
|
||||
title_label.text = "Home"
|
||||
title_label.x = 95
|
||||
title_label.y = 14
|
||||
|
||||
page_label.text = """
|
||||
hello :)
|
||||
"""
|
||||
page_label.x = 5
|
||||
page_label.y = 30
|
||||
|
||||
# # # # # # # # # # # # # # # # # #
|
||||
|
||||
|
||||
# SET UP SD CARD
|
||||
spi = busio.SPI(board.SD_SCK, MOSI=board.SD_MOSI, MISO=board.SD_MISO)
|
||||
cs = board.SD_CS
|
||||
|
||||
try:
|
||||
sdcard = sdcardio.SDCard(spi, cs)
|
||||
vfs = storage.VfsFat(sdcard)
|
||||
|
||||
storage.mount(vfs, "/sd") # access files on sd card here
|
||||
except OSError:
|
||||
pass # SD card not inserted/found
|
||||
|
||||
|
||||
# SET UP DISPLAY
|
||||
display = board.DISPLAY
|
||||
display_group = displayio.Group()
|
||||
display.root_group = display_group
|
||||
|
||||
# Header Bar
|
||||
rect = Rect(0, 0, 238, 30, fill=0x1f4476)
|
||||
display.root_group.append(rect)
|
||||
|
||||
# Page Title
|
||||
title_font = terminalio.FONT
|
||||
title_color = 0xffffff
|
||||
title_label = label.Label(title_font, text="Home", color=title_color, scale=2)
|
||||
display.root_group.append(title_label)
|
||||
|
||||
|
||||
# Page Text
|
||||
page_font = terminalio.FONT
|
||||
page_color = 0xffffff
|
||||
page_label = label.Label(page_font, text="page_text", color=page_color, scale=1)
|
||||
display.root_group.append(page_label)
|
||||
|
||||
home()
|
||||
|
||||
keyb = Keyboard()
|
||||
|
||||
|
||||
## PROGRAM MAIN LOOP (WORKS FROM HOME PAGE IF OTHER PAGES HAVE THEIR OWN LOOPS)
|
||||
while True:
|
||||
key = keyb.scan()
|
||||
Reference in New Issue
Block a user