Badge picture plus sound in micropython

Last Updated or created 2022-08-14

python mch2022-tools/webusb_fat_dir.py /flash/apps/python/easy
for f in easy.mp3 easy.png icon.png __init__.py ; do python  mch2022-tools/webusb_fat_push.py $f /flash/apps/python/easy/$f ; done

Micropython code __init__.py

mport display
import mch22
from audio import play
import buttons
from time import sleep
from machine import Pin
from neopixel import NeoPixel

powerPin = Pin(19, Pin.OUT)
dataPin = Pin(5, Pin.OUT)
np = NeoPixel(dataPin, 5)
powerPin.on()


def on_home_btn(pressed):
  if pressed:
    mch22.exit_python()


display.drawPng(0,0,"/apps/python/easy/easy.png")
display.flush()



# Led setup
#   2   3    
#      1
#     0     4

np[0] = (23,5,15)
np[1] = (3,15,22)
np[2] = (25,24,1)
np[3] = (25,24,1)
np[4] = (23,4,15)
np.write()


buttons.attach(buttons.BTN_HOME, on_home_btn)
# playing with volume 0 to wakeup sound device, else it is going to clip
play('/apps/python/easy/easy.mp3', volume=0)
sleep(7)
while True:
    play('/apps/python/easy/easy.mp3', volume=100)
    sleep(30)
Spread the love