Hey guys, we're going to learn how to program the Raspberry Pi's GPIO ( General Purpose Input Output ) Header pins using Python.
The pins can be programmed using Scratch, but, we won't get into that today.
To actually have access to the Raspberry Pi's pins, you need to open Python as a root user, or an admin.
The way that we do this in Linux (which is what the Raspbian is based off of), is by clicking Menu > Accessories > Terminal then, typing sudo idle3 &
That will open the Python IDE as a root user, allowing you control over the Raspberry Pi's GPIO pins.
Step 1: Python Code
Here is the Python code, in case you need it:
import RPi.GPIO as GPIO
led = 4
button = 14
GPIO.setup(led, GPIO.OUT) //Setting pin 4 as output
GPIO.setup(button, GPIO.IN, GPIO.PUD_UP) //Setting pin 14 as input
if GPIO.input(button) == True:
GPIO.output(led, 1) //Turns led on (1 = on, 0 = off)
GPIO.cleanup() //Cleans up used ports and makes them ready to be used again.
Step 2: GPIO Reference
You can use that picture, to reference your GPIO pins.