ソースを参照

Update 'CARDPUTER CircuitPython/text_editor.py'

cube 9 ヶ月 前
コミット
e247568aa8
共有1 個のファイルを変更した29 個の追加6 個の削除を含む
  1. 29
    6
      CARDPUTER CircuitPython/text_editor.py

CARDPUTER CircuitPython/full_display_test.py → CARDPUTER CircuitPython/text_editor.py ファイルの表示

1
-import board
2
-import terminalio
3
-from adafruit_display_text import label
4
-from keyboard import Keyboard
5
-
6
 # GUIDE
1
 # GUIDE
7
 # type freely! CTRL+D clears the text.
2
 # type freely! CTRL+D clears the text.
8
 # backspace, space, and return function as expected.
3
 # backspace, space, and return function as expected.
9
 # keys not recognised WILL print "UNKNOWN 0x??", but this is useful for extra key scans
4
 # keys not recognised WILL print "UNKNOWN 0x??", but this is useful for extra key scans
5
+#
6
+# WORK IN PROGRESS
7
+# CTRL + S to save text to the SD Card
10
 ######
8
 ######
11
 
9
 
10
+import board
11
+import terminalio
12
+from adafruit_display_text import label
13
+from keyboard import Keyboard
14
+
15
+import busio
16
+import sdcardio
17
+import storage
18
+import os
19
+
20
+## SD Card set up for saving text to SD card
21
+spi = busio.SPI(board.SD_SCK, MOSI=board.SD_MOSI, MISO=board.SD_MISO)
22
+cs = board.SD_CS
23
+
24
+try:
25
+    sdcard = sdcardio.SDCard(spi, cs)
26
+    vfs = storage.VfsFat(sdcard)
27
+
28
+    storage.mount(vfs, "/sd") # access files on sd card here
29
+    SD_status = "SD Card Mounted"
30
+except OSError:
31
+    SD_status = "No SD card found"
32
+    pass # SD card not inserted/found
33
+#########################################
34
+
12
 keyb = Keyboard()
35
 keyb = Keyboard()
13
 
36
 
14
-text = "Press CTRL+D to clear text\n\n"
37
+text = "Press CTRL+D to clear text\n"+SD_status+"\n\n"
15
 text_area = label.Label(terminalio.FONT, text=text)
38
 text_area = label.Label(terminalio.FONT, text=text)
16
 text_area.x = 10
39
 text_area.x = 10
17
 text_area.y = 10
40
 text_area.y = 10