-
Notifications
You must be signed in to change notification settings - Fork 776
/
Copy pathcode.py
68 lines (58 loc) · 2.02 KB
/
code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import os
import board
import busio
import digitalio
import storage
import sdcardio
from adafruit_slideshow import PlayBackOrder, SlideShow, PlayBackDirection
# Default location to look is in internal memory
IMAGE_DIRECTORY = "/images"
switch = digitalio.DigitalInOut(board.D3)
switch.direction = digitalio.Direction.INPUT
switch.pull = digitalio.Pull.UP
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
try:
sdcard = sdcardio.SDCard(spi, board.SD_CS)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
IMAGE_DIRECTORY = "/sd/images"
except OSError as error:
print("No SD card, will only look on internal memory")
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) + " by"
elif filesize < 1000000:
sizestr = "%0.1f KB" % (filesize / 1000)
else:
sizestr = "%0.1f MB" % (filesize / 1000000)
prettyprintname = ""
for _ in range(tabs):
prettyprintname += " "
prettyprintname += file
if isdir:
prettyprintname += "/"
print('{0:<20} Size: {1:>6}'.format(prettyprintname, sizestr))
# recursively print directory contents
if isdir:
print_directory(path + "/" + file, tabs + 1)
try:
print_directory(IMAGE_DIRECTORY)
except OSError as error:
raise Exception("No images found on flash or SD Card")
# Create the slideshow object that plays through once alphabetically.
slideshow = SlideShow(board.DISPLAY, None, folder=IMAGE_DIRECTORY, loop=True,
order=PlayBackOrder.ALPHABETICAL, dwell=0)
while True:
if not switch.value:
print("Click!")
slideshow.direction = PlayBackDirection.FORWARD
slideshow.advance()
while not switch.value:
pass