Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
materiel:rpi:gpio:accueil [2016/12/05 19:15] resonance |
materiel:rpi:gpio:accueil [2018/05/15 16:16] (Version actuelle) resonance |
||
---|---|---|---|
Ligne 2: | Ligne 2: | ||
Utilisations : entrées, sorties, ... | Utilisations : entrées, sorties, ... | ||
+ | |||
+ | |||
+ | ===== Ligne de commande ===== | ||
+ | | ||
+ | |||
+ | |||
+ | sudo -i | ||
+ | |||
+ | Setup to control pin as output | ||
+ | |||
+ | Substitute 23 in the following commands for your GPIO number (GPIO, not pin number) | ||
+ | |||
+ | |||
+ | echo " | ||
+ | echo " | ||
+ | |||
+ | Control Output State | ||
+ | |||
+ | |||
+ | echo " | ||
+ | echo " | ||
+ | |||
+ | Setup to read pin as an input | ||
+ | |||
+ | Substitute 23 in the following commands for your GPIO number (GPIO, not pin number) | ||
+ | |||
+ | |||
+ | echo " | ||
+ | echo " | ||
+ | |||
+ | Read its state | ||
+ | |||
+ | |||
+ | cat / | ||
+ | |||
+ | To Release A Pin Afterwards | ||
+ | |||
+ | |||
+ | echo " | ||
+ | |||
+ | ===== Avec Python ===== | ||
+ | Avec la biblio RPI.gpio et la biblio gpiozero : | ||
+ | Here’s a list of devices which currently supported: | ||
+ | * LED (also PWM LED allowing change of brightness) | ||
+ | * RGB LED | ||
+ | * Buzzer | ||
+ | * Motor | ||
+ | * Button | ||
+ | * Motion Sensor | ||
+ | * Light Sensor | ||
+ | * Analogue-to-Digital converters MCP3004 and MCP3008 | ||
+ | * Robot | ||
Ligne 58: | Ligne 110: | ||
</ | </ | ||
</ | </ | ||
+ | |||
+ | |||
+ | **Lancer une fonction** | ||
+ | <code python> | ||
+ | from gpiozero import Button | ||
+ | from signal import pause | ||
+ | |||
+ | def say_hello(): | ||
+ | print(" | ||
+ | |||
+ | button = Button(2) | ||
+ | button.when_pressed = say_hello | ||
+ | | ||
+ | pause() | ||
+ | </ | ||
+ | |||
+ | **Lancer un programme** | ||
+ | <code python> | ||
+ | from gpiozero import Button | ||
+ | from signal import pause | ||
+ | import subprocess | ||
+ | |||
+ | button = Button(2) | ||
+ | button.wait_for_press() | ||
+ | subprocess.call([' | ||
+ | </ | ||
+ | |||
+ | **Déclencher deux sons avec deux boutons** | ||
+ | Avec Pygame : http:// | ||
+ | |||
+ | <WRAP center round info 60%> | ||
+ | * FORMATS MP3 POSSIBLES AVEC pygame.mixer.music.load(" | ||
+ | * FORMATS WAVE AVEC sound = pygame.mixer.Sound("/ | ||
+ | </ | ||
+ | |||
+ | <code python> | ||
+ | from gpiozero import Button | ||
+ | from signal import pause | ||
+ | import pygame | ||
+ | |||
+ | b1 = Button(2) | ||
+ | b2 = Button(3) | ||
+ | |||
+ | pygame.mixer.init() | ||
+ | son1 =pygame.mixer.Sound('/ | ||
+ | son2 =pygame.mixer.Sound('/ | ||
+ | |||
+ | def launch_sound1(): | ||
+ | son1.play() | ||
+ | |||
+ | def launch_sound2(): | ||
+ | son2.play() | ||
+ | |||
+ | b1.when_pressed = launch_sound1 | ||
+ | b2.when_pressed = launch_sound2 | ||
+ | |||
+ | pause() | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | **Même chose en plus souple** | ||
+ | <code java> | ||
+ | from gpiozero import LED, Button | ||
+ | from signal import pause | ||
+ | import pygame | ||
+ | |||
+ | |||
+ | button1 = Button(2) | ||
+ | button2 = Button(3) | ||
+ | led = LED(17) | ||
+ | pygame.mixer.init() | ||
+ | monson1 =pygame.mixer.Sound('/ | ||
+ | monson2 =pygame.mixer.Sound('/ | ||
+ | |||
+ | # dictionnaire clé/valeur pour lister les sons | ||
+ | sounds = {button1: monson1, | ||
+ | button2: monson2} | ||
+ | |||
+ | def stateON(button): | ||
+ | sounds[button].play() | ||
+ | led.on() | ||
+ | |||
+ | def stateOFF(button): | ||
+ | sounds[button].stop() | ||
+ | led.off() | ||
+ | |||
+ | def btntest(): | ||
+ | # parcours l' | ||
+ | for button in sounds.keys(): | ||
+ | # when_pressed envoie apr defaut le bouton en tant qu' | ||
+ | button.when_pressed = stateON | ||
+ | button.when_released = stateOFF | ||
+ | |||
+ | btntest() | ||
+ | pause() | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
===== Entrée / Sortie ===== | ===== Entrée / Sortie ===== | ||
Ligne 82: | Ligne 234: | ||
----- | ----- | ||
+ | |||
+ | |||
FIXME | FIXME | ||