Browse Source

Update 'CARDPUTER CircuitPython/text_editor.py'

cube 9 months ago
parent
commit
e247568aa8
1 changed files with 29 additions and 6 deletions
  1. 29
    6
      CARDPUTER CircuitPython/text_editor.py

CARDPUTER CircuitPython/full_display_test.py → CARDPUTER CircuitPython/text_editor.py View File

@@ -1,17 +1,40 @@
1
-import board
2
-import terminalio
3
-from adafruit_display_text import label
4
-from keyboard import Keyboard
5
-
6 1
 # GUIDE
7 2
 # type freely! CTRL+D clears the text.
8 3
 # backspace, space, and return function as expected.
9 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 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 38
 text_area = label.Label(terminalio.FONT, text=text)
16 39
 text_area.x = 10
17 40
 text_area.y = 10