Modifications
Sauter à la navigation
Sauter à la recherche
← Modification précédente
Modification suivante →
P2E-MELODIC-BELL
(voir la source)
Version du 1 avril 2025 à 15:15
988 octets ajoutés
,
1 avril 2025 à 15:15
→Code
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>
Admin
Bureaucrates
,
Administrateurs
32 920
modifications
Menu de navigation
Outils personnels
Se connecter
Espaces de noms
Page
Discussion
Variantes
Affichages
Lire
Voir le texte source
Voir l’historique
Plus
Rechercher
Navigation
ARDUINO
RASPBERRY-PI
[:: PI Hacking ::]
Particle.IO
Micro Python
Imprimante 3D
Actualités
Modifications récentes
Page au hasard
Aide
Outils
Pages spéciales
Version imprimable