Modifications

Sauter à la navigation Sauter à la recherche
475 octets ajoutés ,  16 janvier 2025 à 20:40
Ligne 62 : Ligne 62 :     
<syntaxhighlight lang="python" line highlight="4,7,9,10,13,19,21">
 
<syntaxhighlight lang="python" line highlight="4,7,9,10,13,19,21">
−
xxx
+
from machine import Pin, ADC
 +
import time
 +
 
 +
TURN_ON = 32000 # 0 - 65535
 +
 
 +
# Désactive PowerSafe (lower ripple)
 +
Pin( 23, Pin.OUT, value=True )
 +
a1 = ADC( Pin( Pin.board.GP27 ) )
 +
red = Pin( Pin.board.GP20, Pin.OUT )
 +
green = Pin( Pin.board.GP21, Pin.OUT )
 +
 
 +
def calc_temp( millivolts ):
 +
    return (millivolts-500)/10
 +
 
 +
while True:
 +
    val = 0
 +
    for i in range( 10 ):
 +
        val += a1.read_u16()
 +
    val = val/10
 +
 
 +
    mv = 3300*val/65535
 +
    temp = calc_temp( mv )
 +
    print( 'adc=%5i , mv=%5i, temp=%2.2f °C' % (val, mv, temp) )
 +
   
 +
    green.value( 19<=temp<25 )
 +
    red.value( temp>= 25 )
 +
           
 +
    time.sleep_ms( 300 )
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
Il ne reste plus qu'à placer un objet (ex: votre main) entre la source de lumière et la photo-résistance pour constater l'impact sur le convertisseur analogique (dans la sessions REPL).  
+
Il ne reste plus qu'a tester la capteur.  
    
[[Fichier:P2E-TMP36-25.png]]
 
[[Fichier:P2E-TMP36-25.png]]
32 920

modifications

Menu de navigation