| Ligne 101 : |
Ligne 101 : |
| | | | |
| | [[Fichier:ESP8266-DEV-20.png]] | | [[Fichier:ESP8266-DEV-20.png]] |
| | + | |
| | + | <syntaxhighlight lang="python"> |
| | + | >>> from machine import Pin |
| | + | >>> relay = Pin(5, Pin.OUT) |
| | + | >>> relay.value( 1 ) # Relais activé |
| | + | >>> relay.value( 0 ) # Relais inactif |
| | + | >>> relay.value( 1 ) # Relais activé |
| | + | >>> relay.value( 0 ) # Relais inactif |
| | + | >>> relay.value( 1 ) # Relais activé |
| | + | >>> relay.value( 0 ) # Relais inactif |
| | + | </syntaxhighlight> |
| | + | |
| | + | == Utilisation de l'entrée == |
| | + | La lecture de l'entrée bouton se fait sur le GPIO 0. |
| | + | |
| | + | [[Fichier:ESP8266-DEV-21.png]] |
| | + | |
| | + | En pressant le bouton, l'entrée GPIO 0 est placée à la masse. Cela implique donc qu'il faut activer la résistance pull-up interne sur le GPIO 0. |
| | + | Par conséquent: |
| | + | |
| | + | Switch OUVERT : GPIO 0 = HIGH (3.3v) |
| | + | Switch FERME : GPIO 0 = LOW (0v) |
| | + | |
| | + | Le script suivant lit le GPIO 0 à interval régulier et affiche le résultat dans la session REPL. |
| | + | |
| | + | <syntaxhighlight lang="python"> |
| | + | >>> from machine import Pin |
| | + | >>> from time import sleep_ms |
| | + | >>> btn = Pin( 0, Pin.IN, pull=Pin.PULL_UP ) |
| | + | >>> while True: |
| | + | >>> print( '--' if btn.value()==1 else 'PRESSE' ) |
| | + | >>> sleep_ms( 300 ) |
| | + | </syntaxhighlight> |
| | + | |
| | + | Ce qui produit les résultats suivants sur la session REPL. |
| | + | |
| | + | <syntaxhighlight> |
| | + | -- |
| | + | PRESSE |
| | + | PRESSE |
| | + | PRESSE |
| | + | -- |
| | + | -- |
| | + | -- |
| | + | -- |
| | + | -- |
| | + | PRESSE |
| | + | -- |
| | + | -- |
| | + | PRESSE |
| | + | -- |
| | + | -- |
| | + | -- |
| | + | -- |
| | + | </syntaxhighlight> |