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

On this mission you’ll discover ways to activate and off a LED
Issues you will want:
Raspberry Pi + SD Card
Keyboard + Mouse
Monitor + HDMI Cable
Energy Provide
Breadboard
1x Purple 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 led on script
contact 2_on.py
3. Then create a file for our led off script
contact 2_off.py
4. Edit the 2_on.py file utilizing nano 2_on.py and add the next code
#!/usr/bin/python
import RPi.GPIO as GPIO # import a library
GPIO.setmode(GPIO.BCM) # set the pin numbering system to BCM
GPIO.setup(17,GPIO.OUT) # set GPIO17 as an OUTPUT
GPIO.setup(27,GPIO.OUT) # set GPIO27 as am OUTPUT
print "Lights on" # print to the display so we all know what’s occurring
GPIO.output(17,GPIO.HIGH) # set GPIO17 excessive, 3v3 will now be energetic on that pin
GPIO.output(27,GPIO.HIGH) # set GPIO27 excessive, 3v3 will now be energetic on that pin
5. Exit and save the file, CTRL+x, Y, enter
6. Edit the 2_off.py file utilizing nano 2_off.py and add the next code
#!/usr/bin/python
import RPi.GPIO as GPIO # import a library
GPIO.setmode(GPIO.BCM) # set the pin numbering system to BCM
GPIO.setup(17,GPIO.OUT) # set GPIO17 as an OUTPUT
GPIO.setup(27,GPIO.OUT) # set GPIO27 as am OUTPUT
print "Lights off" # print to the display so we all know what’s occurring
GPIO.output(17,GPIO.LOW) # set GPIO17 low, 3v3 will now be de-active on that pin
GPIO.output(27,GPIO.LOW) # set GPIO27 low, 3v3 will now be de-active on that pin
7. Exit and save the file, CTRL+x, Y, enter
8. To show your LEDs on, execute your 2_on.py script:
sudo python 2_on.py
You may see some warnings, for the sake if this tutorial you possibly can ignore these.
They're simply letting that the GPIO pins used within the script, might have already
been configured.
8. To show your LEDs off, execute your 2_off.py script:
sudo python 2_off.py
You’ll in all probability see some warnings, for the sake if this tutorial you possibly can ignore these.
They're simply letting that the GPIO pins used within the script, might have already
been configured.
Read the full article
Satoshi Nakamoto
Keine Verbindung
Verbindung wird wiederhergestellt
Etwas ist schiefgelaufen
Wir sind gleich wieder da