Télécharger Imprimer la page

Raspberry PICO Mode D'emploi page 110

Publicité

18.1 Python
Le programme positionne le potentiomètre 0 au minimum et le potentiomètre 1 au maximum. Il fait
ensuite varier les valeurs de min vers max puis inversement (l'inverse pour le potentiomètre 1).
from
machine
import
import
time
compteur
=
0
sens
=
True
A0
= ADC(26)
A1
= ADC(27)
cs
= Pin(17, mode=Pin.OUT, value=1)
spi
= SPI(0, baudrate=14_000_000, sck=Pin(18), mosi=Pin(19), miso=Pin(16))
# Potentiomètre 0 à min
cs(0)
spi.write(bytearray([0b00000000, 0b00000000]))
cs(1)
# Potentiomètre 1 à max
cs(0)
spi.write(bytearray([0b00010001, 0b00000000]))
cs(1)
time.sleep_ms(10)
while
True:
print("Valeur broche A0:
if
sens:
cs(0)
spi.write(bytearray([0b00000100]))
cs(1)
cs(0)
spi.write(bytearray([0b00011000]))
cs(1)
else:
cs(0)
spi.write(bytearray([0b00001000]))
cs(1)
cs(0)
spi.write(bytearray([0b00010100]))
cs(1)
compteur
=
compteur
if(compteur
== 257):
compteur
=
0
sens
=
not
sens
print("Changement
time.sleep_ms(40)
Pin, ADC,
SPI
", A0.read_u16(),
+
1
sens")
" - Valeur broche A1:
", A1.read_u16())

Publicité

loading

Ce manuel est également adapté pour:

Pico w