Dans ce projet, vous apprendrez à faire clignoter une LED!
Choses dont vous aurez besoin:
Carte SD Raspberry Pi +
Clavier + souris
Moniteur + câble HDMI
Source de courant
Planche à pain
1x LED rouge
1x LED bleue
2x 330? Résistance
3x fils de pontage M / F
Conditions préalables:
Dernière version de Rasbian installée sur votre carte SD
Configuration du Raspberry Pi avec un clavier, une souris et un moniteur

1. Changez le répertoire courant en notre répertoire gpio_python_code:
cd gpio_python_code

2. Commencez par créer un fichier pour notre script led clignotant
touch 3_blink.py

3. Créez un fichier pour notre script clignotant pour toujours
touch 3_blink_forever.py

4. Modifiez le script 3_blink.py à l’aide de nano 3_blink.py, ajoutez le code suivant:
#!/usr/bin/python from time import sleep # import the time function from the sleep library import RPi.GPIO as GPIO # import our GPIO library GPIO.setmode(GPIO.BCM) # set the board numbering system to BCM # setup our output pins GPIO.setup(17,GPIO.OUT) GPIO.setup(27,GPIO.OUT) # Turn LEDs on print “lights on” GPIO.output(17,GPIO.HIGH) GPIO.output(27,GPIO.HIGH) sleep(1) # sleep for 1 second # Turn LEDs off print “lights off” GPIO.output(17,GPIO.LOW) GPIO.output(27,GPIO.LOW) sleep(1) # Turn LEDs on print “lights on” GPIO.output(17,GPIO.HIGH) GPIO.output(27,GPIO.HIGH) sleep(1) # Turn LEDs off print “lights off” GPIO.output(17,GPIO.LOW) GPIO.output(27,GPIO.LOW) GPIO.cleanup() # the clean-up function will reset all the configurations made in this script. This will stop the warnings we got from the tutorial 2.

5. Modifiez le script 3_blink_forever.py à l’aide de nano 3_blink_forever.py, ajoutez le code suivant:
#!/usr/bin/python
# import libraries
from time import sleep
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # set pin numbering system to bcm
# setup our output pins
GPIO.setup(17,GPIO.OUT)
GPIO.setup(27,GPIO.OUT)
# create an infinite loop
while True:
# turn leds on
print “lights on”
GPIO.output(17,GPIO.HIGH)
GPIO.output(27,GPIO.HIGH)
sleep(1) # sleep 1 second
# turn leds off
print “lights off”
GPIO.output(17,GPIO.LOW)
GPIO.output(27,GPIO.LOW)
sleep(1) # sleep 1 second

6. Exécutez votre script 3_blink.py
sudo python 3_blink.py

7. Exécutez votre script 3_blink_forever.py
sudo python 3_blink_forever.py

8. Pour arrêter votre script 3_blink_forever.py, appuyez simplement sur ctrl + c
-
Xiuganpo Carte D'extension GPIO Compacte pour avec Port IO à 3 Broches, Sortie LED pour L'apprentissage de la Programmation des Enfants
-
Bnojjellol Carte contrôleur GPIO programmable avec fonctionnalité d'interruption et module d'entrée GPIO au design compact
