Add initial files for the HH Hacking 101 - code and infos about board will follow soon

This commit is contained in:
2023-01-17 01:51:29 +01:00
parent a0f4013f75
commit f723aecc9d
9 changed files with 711 additions and 2 deletions

View File

@@ -0,0 +1,51 @@
from machine import Pin, SPI
import machine, sdcard, os, esp32
spi = SPI(2, baudrate=10000000, polarity=0, phase=0, sck=machine.Pin(18), mosi=machine.Pin(23), miso=machine.Pin(19))
sd = sdcard.SDCard(spi, machine.Pin(5))
os.mount(sd, '/sd')
def print_directory(path, tabs = 0):
for file in os.listdir(path):
stats = os.stat(path+"/"+file)
filesize = stats[6]
isdir = stats[0] & 0x4000
if filesize < 1000:
sizestr = str(filesize) + " byte"
elif filesize < 1000000:
sizestr = "%0.1f KB" % (filesize/1000)
else:
sizestr = "%0.1f MB" % (filesize/1000000)
prettyprintname = ""
for i in range(tabs):
prettyprintname += " "
prettyprintname += file
if isdir:
prettyprintname += "/"
print('{0:<40} Size: {1:>10}'.format(prettyprintname, sizestr))
# recursively print directory contents
if isdir:
print_directory(path+"/"+file, tabs+1)
#with open("/sd/test1.txt", "w") as f:
# f.write("Hello world!\r\n")
print("Files on filesystem:")
print("====================")
print_directory("/sd")
#
#print("Files on filesystem:")
#print("====================")
#print_directory("/sd")
#
#with open("/sd/test/test1.txt", "w") as f:
# f.write("Hello world!\r\n")
#
#print("Files on filesystem:")
#print("====================")
#print_directory("/sd/test")