Parcourir la source

Add 'CARDPUTER CircuitPython/oslike_boilerplate/code.py'

cube il y a 1 mois
Parent
révision
03f2cf5f4b
1 fichiers modifiés avec 64 ajouts et 0 suppressions
  1. 64
    0
      CARDPUTER CircuitPython/oslike_boilerplate/code.py

+ 64
- 0
CARDPUTER CircuitPython/oslike_boilerplate/code.py Voir le fichier

@@ -0,0 +1,64 @@
1
+from keyb import Keyboard # type: ignore
2
+import time, os, rtc, json # type: ignore
3
+import board, busio, sdcardio, storage, terminalio, displayio # type: ignore
4
+from adafruit_display_text import label # type: ignore
5
+from adafruit_display_shapes.rect import Rect # type: ignore
6
+
7
+### DEFAULT HOME PAGE # # # # # # # # # #
8
+def home():
9
+    title_label.text = "Home"
10
+    title_label.x = 95
11
+    title_label.y = 14
12
+
13
+    page_label.text = """
14
+hello :) 
15
+    """
16
+    page_label.x = 5
17
+    page_label.y = 30
18
+
19
+# # # # # # # # # # # # # # # # # # 
20
+
21
+
22
+# SET UP SD CARD
23
+spi = busio.SPI(board.SD_SCK, MOSI=board.SD_MOSI, MISO=board.SD_MISO)
24
+cs = board.SD_CS
25
+
26
+try:
27
+    sdcard = sdcardio.SDCard(spi, cs)
28
+    vfs = storage.VfsFat(sdcard)
29
+
30
+    storage.mount(vfs, "/sd") # access files on sd card here
31
+except OSError:
32
+    pass # SD card not inserted/found
33
+
34
+
35
+# SET UP DISPLAY
36
+display = board.DISPLAY
37
+display_group = displayio.Group()
38
+display.root_group = display_group
39
+
40
+# Header Bar
41
+rect = Rect(0, 0, 238, 30, fill=0x1f4476)
42
+display.root_group.append(rect)
43
+
44
+# Page Title
45
+title_font = terminalio.FONT
46
+title_color = 0xffffff
47
+title_label = label.Label(title_font, text="Home", color=title_color, scale=2)
48
+display.root_group.append(title_label)
49
+
50
+
51
+# Page Text
52
+page_font = terminalio.FONT
53
+page_color = 0xffffff
54
+page_label = label.Label(page_font, text="page_text", color=page_color, scale=1)
55
+display.root_group.append(page_label)
56
+
57
+home()
58
+
59
+keyb = Keyboard()
60
+
61
+
62
+## PROGRAM MAIN LOOP (WORKS FROM HOME PAGE IF OTHER PAGES HAVE THEIR OWN LOOPS)
63
+while True:
64
+    key = keyb.scan()