Modifications

Sauter à la navigation Sauter à la recherche
988 octets ajoutés ,  1 avril 2025 à 15:15
Ligne 48 : Ligne 48 :     
<syntaxhighlight lang="python" line>
 
<syntaxhighlight lang="python" line>
−
from micropython import const
+
import micropython, time
 +
from machine import Pin
 +
from rtplay import *
 +
micropython.alloc_emergency_exception_buf(100)
    +
counter = 0
 +
 +
def bouton_cb( obj ):
 +
    global counter
 +
    counter += 1
 +
   
 +
# https://docs.micropython.org/en/latest/library/machine.Pin.html
 +
# https://docs.micropython.org/en/latest/reference/isr_rules.html
 +
btn = Pin( Pin.board.GP16, Pin.IN, Pin.PULL_UP )
 +
btn.irq( handler=bouton_cb, trigger=Pin.IRQ_FALLING )
 +
 +
buzzer = RingTonePlayer( Pin.board.GP13 )
 +
buzzer.load_songs( 'songs.py' )
 +
song_names = buzzer.dir_songs()
 +
print( song_names )
 +
 +
index = 0
 +
while True:
 +
    if counter>0: # Button pressed?     
 +
        # Song name to play
 +
        song_name = song_names[index]
 +
        print( 'Ring the bell! %i %s' % (index,song_name) )
 +
       
 +
        # Play the song
 +
        buzzer.play_song( song_name )
 +
       
 +
        # Select next song
 +
        index += 1
 +
        if index >= len(song_names):
 +
            index = 0
 +
       
 +
        # Reset button detection
 +
        counter=0
 +
 +
    time.sleep_ms( 200 )
 
</syntaxhighlight>
 
</syntaxhighlight>
  
32 920

modifications

Menu de navigation