Saturday, February 6, 2016

Turning on an LED with your Raspberry Pi's GPIO Pins

http://thepihut.com/blogs/raspberry-pi-tutorials/27968772-turning-on-an-led-with-your-raspberry-pis-gpio-pins


The Code

You are now ready to write some code to switch the LED on.  Turn on your Pi and open the terminal window.
Create a new text file “LED.py” by typing the following:
nano LED.py
Type in the following code:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
print "LED on"
GPIO.output(18,GPIO.HIGH)
time.sleep(1)
print "LED off"
GPIO.output(18,GPIO.LOW)
Once you have typed all the code and checked it, save and exit the text editor with “Ctrl + x” then “y” then “enter”.

Running the Code

To run this code type:
sudo python LED.py

No comments:

Post a Comment

Learning MS Power APP and FLOW

https://powerapps.microsoft.com/ro-ro/blog/microsoft-powerapps-learning-resources/