Modifications

Sauter à la navigation Sauter à la recherche
34 octets ajoutés ,  28 janvier 2025 à 00:10
Ligne 51 : Ligne 51 :  
Le code ci-dessous peut être saisi dans une session REPL ou dans Thonny IDE.
 
Le code ci-dessous peut être saisi dans une session REPL ou dans Thonny IDE.
   −
Cet exemple est également disponible dans le dépôt [https://github.com/mchobby/pico-2-explorer/tree/main/buzzer pwm-buzzer.py] .
+
Cet exemple est également disponible dans le dépôt [https://github.com/mchobby/pico-2-explorer/tree/main/music music1.py] et [https://github.com/mchobby/pico-2-explorer/tree/main/music music2.py] .
   −
<syntaxhighlight lang="python" line highlight="2,6,9,10,13,14">
+
<syntaxhighlight lang="python" line highlight="2,4,6">
−
from machine import Pin, ADC, PWM
+
from machine import Pin
−
from maps import map
+
from rtplay import *
−
import time
     −
# Désactive PowerSafe (lower ripple)
+
buzzer = RingTonePlayer( Pin.board.GP13 )
−
Pin( 23, Pin.OUT, value=True )
     −
a0 = ADC( Pin( Pin.board.GP26 ) )
+
buzzer.play_str( 'Monty Python:d=8,o=5,b=180:d#6,d6,4c6,b,4a#,a,4g#,g,f,g,g#,4g,f,2a#,p,a#,g,p,g,g,f#,g,d#6,p,a#,a#,p,g,g#,p,g#,g#,p,a#,2c6,p,g#,f,p,f,f,e,f,d6,p,c6,c6,p,g#,g,p,g,g,p,g#,2a#,p,a#,g,p,g,g,f#,g,g6,p,d#6,d#6,p,a#,a,p,f6,f6,p,f6,2f6,p,d#6,4d6,f6,f6,e6,f6,4c6,f6,f6,e6,f6,a#,p,a,a#,p,a,2a#' )
−
buzzer = PWM( Pin( Pin.board.GP13 ) )
  −
buzzer.duty_u16( 65535//3 )
  −
while True:
  −
    val = a0.read_u16()
  −
    hertz = int( map(val, 0, 65535, 100, 10000 ) )
  −
    buzzer.freq( hertz )
  −
    print( 'frequence = %5i Hz' % (hertz) )
  −
    time.sleep_ms( 100 )
   
</syntaxhighlight>
 
</syntaxhighlight>
32 920

modifications

Menu de navigation