Modifications

Sauter à la navigation Sauter à la recherche
51 octets supprimés ,  27 octobre 2024 à 16:41
Ligne 105 : Ligne 105 :  
=== Utiliser Signal ===
 
=== Utiliser Signal ===
   −
Il est très facile de connaître l'état actuel de la broche en appelant la méthode {{fname|value()}} sans paramètre.
+
{{fname|Signal}} est une classe qui permet d'inverser l'état d'un signal. Cela permet d'utiliser un bouton et de revenir dans une logique positive (obtenir état HAUT/vrai lorsque le bouton est pressé).
−
 
  −
La fonction retourne alors:
  −
* '''1''' pour un niveau HAUT (3V3)
  −
* '''0''' pour un niveau BAS (0V)
      
<syntaxhighlight lang="python" line highlight="9">
 
<syntaxhighlight lang="python" line highlight="9">
−
from machine import Pin
+
from machine import Pin, Signal
 
import time
 
import time
−
p = Pin( 2, Pin.OUT )
+
p_in = Pin( 10, Pin.IN, Pin.PULL_UP )
−
 
+
s_in = Signal( p_in, invert=True )
−
# Allumer la LED
  −
p.value( True )
     −
# Obtenir l'état de la broche
  −
val = p.value()
  −
print( val )
   
</syntaxhighlight>
 
</syntaxhighlight>
  
32 920

modifications

Menu de navigation