Modifications

Sauter à la navigation Sauter à la recherche
657 octets ajoutés ,  13 décembre 2024 à 17:13
Ligne 63 : Ligne 63 :     
<syntaxhighlight lang="python" line highlight="1,8,9,12">
 
<syntaxhighlight lang="python" line highlight="1,8,9,12">
−
Du code pour le peuple</syntaxhighlight>
+
from machine import Pin, ADC, PWM
 +
from maps import map
 +
import time
 +
 
 +
# Désactive PowerSafe (lower ripple)
 +
Pin( 23, Pin.OUT, value=True )
 +
 
 +
a0 = ADC( Pin( Pin.board.GP26 ) )
 +
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>
    
Il ne reste plus qu'à tourner le potentiomètre pour modifier la luminosité de la LED.
 
Il ne reste plus qu'à tourner le potentiomètre pour modifier la luminosité de la LED.
    
Voici quelques explications:
 
Voici quelques explications:
−
* '''Ligne x''': bla {{fname|PWM}} cla.
+
* '''Ligne 2''': import de la fonction {{fname|map}} similaire à son homologue Arduino. La fonction bibliothèque {{fname|maps}} est déjà installée sur votre carte MicroPython et est disponible dans le dépôt [https://github.com/mchobby/esp8266-upy/tree/master/LIBRARIAN esp8266-upy/LIBRARIAN].
 
* '''Lignes x à x''': xxx
 
* '''Lignes x à x''': xxx
  
32 920

modifications

Menu de navigation