Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import board
- import busio
- import sdcardio
- import storage
- import os
- import audiocore
- import audiobusio
- import audiomixer
- from lcd.lcd import LCD, CursorMode
- from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
- # Setup SD card and MP3
- sck = board.GP18
- si = board.GP19
- so = board.GP20
- cs = board.GP21
- spi = busio.SPI(sck, si, so)
- sdcard = sdcardio.SDCard(spi, cs)
- vfs = storage.VfsFat(sdcard)
- storage.mount(vfs, "/sd")
- # Initialize I2S for audio output
- audio = audiobusio.I2SOut(board.GP10, board.GP11, board.GP9)
- # Print files on SD card for debugging
- print("Files on SD card:")
- for filename in os.listdir("/sd"):
- print(filename)
- # Setup LCD display
- i2c_scl = board.GP17
- i2c_sda = board.GP16
- i2c_address = 0x27 # I2C address of the LCD
- i2c = busio.I2C(scl=i2c_scl, sda=i2c_sda)
- interface = I2CPCF8574Interface(i2c, i2c_address)
- lcd = LCD(interface, num_rows=2, num_cols=16)
- lcd.set_cursor_mode(CursorMode.HIDE)
- # Load and play WAV files
- wav_files = ("poucher1.wav", "poucher2.wav")
- wavs = [None] * len(wav_files) # holds the loaded WAVs
- mixer = audiomixer.Mixer(voice_count=len(wav_files), sample_rate=22050, channel_count=2,
- bits_per_sample=16, samples_signed=True, buffer_size=2048)
- audio.play(mixer) # attach mixer to audio playback
- for i, wav_file in enumerate(wav_files):
- print(f"Loading: {wav_file}")
- with open(f"/sd/{wav_file}", "rb") as file:
- wavs[i] = audiocore.WaveFile(file)
- mixer.voice[i].play(wavs[i], loop=True) # start each one playing
- while True:
- print("Loops are playing, doing other tasks...")
- time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement