User Manual
38
Code Explanation
#!/usr/bin/env python:
When the system detects this, it will search the installation path of python in the env
setting, then call the corresponding interpreter to complete the operation. It’s to
prevent the user not installing the python onto the /usr/bin default path.
import RPi.GPIO as GPIO # import RPI.GPIO package, thus python code control GPIO easily
with it.
import time # import time package, for time delay function in the following program.
LedPin = 17 # LED connects to the B17 of the T-shape extension board, namely, the
GPIO 0 of the Raspberry Pi.
# Define a setup function for some setup
def setup():
GPIO.setmode(GPIO.BCM) # Set the GPIO modes to BCM Numbering
# Set LedPin's mode to output, and initial level to High (3.3v)
GPIO.setup(LedPin, GPIO.OUT, initial=GPIO.HIGH)
# Define a main function for main process
def main():
# Print messages
print_message()
while True:
print '...LED ON'
# Turn on LED
GPIO.output(LEDPin, GPIO.LOW)
SunFounder