Skip to content

Commit e0610c2

Browse files
authored
Merge pull request adafruit#2196 from evaherrada/sdcardio-new
Updated daily cheer to use sdcardio
2 parents 169bb18 + eb87a4f commit e0610c2

File tree

1 file changed

+14
-14
lines changed
  • Daily_Cheer_Automaton/CircuitPython

1 file changed

+14
-14
lines changed

Daily_Cheer_Automaton/CircuitPython/code.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# REQUIREMENTS:
1313
# should use M4 (or higher)
14-
# use CircuitPython 5.3.0+
14+
# use CircuitPython 6.0.0+
1515
#
1616
#
1717
# HARDWARE:
@@ -39,15 +39,15 @@
3939
# Or for software I2C (ESP8266) use this line instead:
4040
# import bitbangio as io
4141

42-
#import adafruit_ds3231
42+
# import adafruit_ds3231
4343
import adafruit_pcf8523
4444

4545
# SD card
46-
import adafruit_sdcard
46+
import sdcardio
4747
import storage
4848

4949
# NeoPixel
50-
#import neopixel
50+
# import neopixel
5151

5252

5353
# Use any pin that is not taken by SPI
@@ -60,19 +60,19 @@
6060
# On Atmel M0, M4, 328p or 32u4 it's on GPIO 10
6161
# On Teensy 3.x it's on GPIO 10
6262

63-
SD_CS = board.D10 # for M4
63+
SD_CS = board.D10 # for M4
6464

6565
# Connect to the card and mount the filesystem.
6666
spi = io.SPI(board.SCK, board.MOSI, board.MISO)
67-
cs = digitalio.DigitalInOut(SD_CS)
68-
sdcard = adafruit_sdcard.SDCard(spi, cs)
67+
sdcard = sdcardio.SDCard(spi, SD_CS)
6968
vfs = storage.VfsFat(sdcard)
7069
storage.mount(vfs, "/sd")
7170

7271

7372
# Use the filesystem as normal! Our files are under /sd
7473
# This helper function will print the contents of the SD
7574

75+
7676
def print_directory(path, tabs=0):
7777
for file in os.listdir(path):
7878
stats = os.stat(path + "/" + file)
@@ -92,7 +92,7 @@ def print_directory(path, tabs=0):
9292
prettyprintname += file
9393
if isdir:
9494
prettyprintname += "/"
95-
print('{0:<40} Size: {1:>10}'.format(prettyprintname, sizestr))
95+
print("{0:<40} Size: {1:>10}".format(prettyprintname, sizestr))
9696

9797
# recursively print directory contents
9898
if isdir:
@@ -106,15 +106,15 @@ def print_directory(path, tabs=0):
106106

107107
data = open("/sd/cheer.mp3", "rb")
108108
mp3 = audiomp3.MP3Decoder(data)
109-
#a = audioio.AudioOut(board.A0) # mono
110-
a = audioio.AudioOut(board.A0, right_channel=board.A1) # stereo sound through A0 & A1
109+
# a = audioio.AudioOut(board.A0) # mono
110+
a = audioio.AudioOut(board.A0, right_channel=board.A1) # stereo sound through A0 & A1
111111

112112

113113
i2c = io.I2C(board.SCL, board.SDA) # Change to the appropriate I2C clock & data
114114
# pins here!
115115

116116
# Create the RTC instance:
117-
#rtc = adafruit_ds3231.DS3231(i2c)
117+
# rtc = adafruit_ds3231.DS3231(i2c)
118118
rtc = adafruit_pcf8523.PCF8523(i2c)
119119

120120
# Lookup table for names of days (nicer printing).
@@ -141,7 +141,7 @@ def print_directory(path, tabs=0):
141141
# pylint: enable-msg=bad-whitespace
142142

143143
# setup NeoPixel
144-
#pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
144+
# pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
145145

146146

147147
# Main loop:
@@ -159,14 +159,14 @@ def print_directory(path, tabs=0):
159159
if t.tm_hour == playhour and t.tm_min == playmin:
160160
print("it is time!")
161161
# turn NeoPixel green
162-
#pixel[0] = (0, 255, 0)
162+
# pixel[0] = (0, 255, 0)
163163
# play the file
164164
print("playing")
165165
a.play(mp3)
166166
while a.playing:
167167
pass
168168
print("stopped")
169169
# turn NeoPixel off
170-
#pixel[0] = (0, 0, 0)
170+
# pixel[0] = (0, 0, 0)
171171

172172
time.sleep(1) # wait a second

0 commit comments

Comments
 (0)