-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathsd_image.py
More file actions
45 lines (34 loc) · 1.06 KB
/
sd_image.py
File metadata and controls
45 lines (34 loc) · 1.06 KB
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
import jpegdec
import machine
import sdcard
import uos
from presto import Presto
# Setup for the Presto display
presto = Presto()
display = presto.display
WIDTH, HEIGHT = display.get_bounds()
j = jpegdec.JPEG(display)
# Couple of pens for clearing the screen and text.
WHITE = display.create_pen(255, 255, 255)
BLACK = display.create_pen(0, 0, 0)
try:
# Setup for SD Card
sd_spi = machine.SPI(0, sck=machine.Pin(34, machine.Pin.OUT), mosi=machine.Pin(35, machine.Pin.OUT), miso=machine.Pin(36, machine.Pin.OUT))
sd = sdcard.SDCard(sd_spi, machine.Pin(39))
# Mount the SD to the directory 'sd'
uos.mount(sd, "/sd")
except OSError as e:
print(e)
while True:
# Clear the screen
display.set_pen(WHITE)
display.clear()
# Add some text
display.set_pen(BLACK)
display.text("Image loaded from SD:", 10, 10, WIDTH, 2)
# Open the JPEG file
j.open_file("sd/micro_sd.jpg")
# Decode the JPEG
j.decode(10, 40, jpegdec.JPEG_SCALE_FULL, dither=True)
# Finally we update the screen with our changes :)
presto.update()