🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Atom S3R with Atomic SPK Base

    UiFlow 2.0
    1
    1
    43
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      adr1a
      last edited by

      I'm trying to develop a toy for my son that plays a wav every time the button is pressed, but it seams that base_spk.playWavFile is blocking the main thread.

      What can I do?

      import os, sys, io
      import M5
      from M5 import *
      from hardware import I2C
      from hardware import Pin
      from base import SpeakerBase
      from hardware import sdcard
      import time
      
      
      
      label0 = None
      label1 = None
      title0 = None
      label2 = None
      label3 = None
      i2c0 = None
      base_spk = None
      step16_0 = None
      
      
      def setup():
        global label0, label1, title0, label2, label3, i2c0, base_spk, step16_0
      
        M5.begin()
        Widgets.fillScreen(0x000000)
        label0 = Widgets.Label("Volume:", 3, 20, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
        label1 = Widgets.Label("label1", 61, 20, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
        title0 = Widgets.Title("Music", 3, 0xffffff, 0x0000FF, Widgets.FONTS.DejaVu18)
        label2 = Widgets.Label("Status:", 4, 38, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
        label3 = Widgets.Label("label3", 62, 38, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu12)
      
        i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
        base_spk = SpeakerBase(1, 5, 39, 38)
        try:
          print('Init SD Card')
          print(os.listdir('/sd/samples'))
        except:
          sdcard.SDCard(slot=3, width=1, sck=7, miso=8, mosi=6, cs=None, freq=20000000)
      
        print('Setting volume')
        base_spk.setVolumePercentage(0.25)
        print('playing wav')
        base_spk.playWavFile('/sd/samples/sample-3s.wav')
        print('wav played')
        print('hello M5')
      
      
      def loop():
        global label0, label1, title0, label2, label3, i2c0, base_spk, step16_0
        M5.update()
        print(os.getcwd())
        label1.setText(str(base_spk.getVolume()))
        label3.setText(str(base_spk.isPlaying()))
        time.sleep(1)
        if BtnA.isPressed():
          print('button pressed')
      
      
      if __name__ == '__main__':
        try:
          setup()
          while True:
            loop()
        except (Exception, KeyboardInterrupt) as e:
          try:
            from utility import print_error_msg
            print_error_msg(e)
          except ImportError:
            print("please update to latest firmware")
      
      1 Reply Last reply Reply Quote 0
      • First post
        Last post