Modifications

Sauter à la navigation Sauter à la recherche
477 octets ajoutés ,  21 février 2022 à 02:35
Ligne 70 : Ligne 70 :     
== Analog Reading ==
 
== Analog Reading ==
The onboard LED is tied to the GPIO 25. Here how to control it.
+
Lets read some voltage from the ADC1 (attached to GPIO 27).
 +
 
 +
The value is read on the ADC via the common {{fname|read_u16()}} method.
 +
 
 +
That method returns a 16 bits value, so a number between 0 and 65535.
 +
 
 +
{{ambox|text=Even if the {{fname|read_u16()}} returns a 16 bits values, the effective ADC resolution is still 12 bits. The MicroPython internal will just upscale the ADC value from 0..4095 to returned value 0..65535 by applying a multiplier.}}
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
from machine import Pin
+
from machine import Pin, ADC
x
+
p = Pin( 27 )
 +
analog = ADC( p )
 +
value = analog.read_u16()
 +
print( 'value: %i' % value )
 
x
 
x
 
x
 
x
29 918

modifications

Menu de navigation