ModMyPi LTD | GPIO & Python (3/9)
von Satoshi Nakamoto

On this challenge you’ll learn to make a LED blink!
Issues you will want:
Raspberry Pi + SD Card
Keyboard + Mouse
Monitor + HDMI Cable
Energy Provide
Breadboard
1x Pink LED
1x Blue LED
2x 330Ω Resistor
3x M/F Jumper Wire
Conditions:
Newest model of Rasbian put in in your SD Card
Raspberry Pi setup with a keyboard, mouse and monitor

1. Change the present listing to our gpio_python_code listing:
cd gpio_python_code
2. Begin by making a file for our blink led script
contact 3_blink.py
3. Create a file for our blink led perpetually script
contact 3_blink_forever.py
4 . Edit the 3_blink.py script utilizing nano 3_blink.py add the next code:
#!/usr/bin/python
from time import sleep # import the time perform 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)
# Flip LEDs on
print “lights on”
GPIO.output(17,GPIO.HIGH)
GPIO.output(27,GPIO.HIGH)
sleep(1) # sleep for 1 second
# Flip LEDs off
print “lights off”
GPIO.output(17,GPIO.LOW)
GPIO.output(27,GPIO.LOW)
sleep(1)
# Flip LEDs on
print “lights on”
GPIO.output(17,GPIO.HIGH)
GPIO.output(27,GPIO.HIGH)
sleep(1)
# Flip LEDs off
print “lights off”
GPIO.output(17,GPIO.LOW)
GPIO.output(27,GPIO.LOW)
GPIO.cleanup() # the clean-up perform will reset all of the configurations made on this script. It will cease the warnings we received from the tutorial 2.
5. Edit the 3_blink_forever.py script utilizing nano 3_blink_forever.py add the next code:
#!/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
whereas True:
# flip leds on
print “lights on”
GPIO.output(17,GPIO.HIGH)
GPIO.output(27,GPIO.HIGH)
sleep(1) # sleep 1 second
# flip leds off
print “lights off”
GPIO.output(17,GPIO.LOW)
GPIO.output(27,GPIO.LOW)
sleep(1) # sleep 1 second
6. Execute your 3_blink.py script
sudo python 3_blink.py
7. Execute your 3_blink_forever.py script
sudo python 3_blink_forever.py
8. To cease your 3_blink_forever.py script, merely press ctrl+c
Read the full article
Satoshi Nakamoto
Keine Verbindung
Verbindung wird wiederhergestellt
Etwas ist schiefgelaufen
Wir sind gleich wieder da