2016-02-19

Pi2, irst Try on LED blinking

Reference line

Preparation
-1- LED *1
-2- Resistor 330 ohm *1
-3- Female jumper wires *2

Pin use
-1- Pin 6 / GROUND
-2- Pin 12 / GPIO 18
Step 1 of 3 Circuit
 

Step 2 of 3 Coding 

Step 3 of 3 Light LED

Code Description

import RPi.GPIO as GPIO
The first line tells the Python interpreter (the thing that runs the Python code) that it will be using a ‘library’ that will tell it how to work with the Raspberry Pi’s GPIO pins.  A ‘library’ gives a programming language extra commands that can be used to do something different that it previously did not know how to do.  This is like adding a new channel to your TV so you can watch something different.

import time
Imports the Time library so that we can pause the script later on.

GPIO.setmode(GPIO.BCM)
Each pin on the Pi has several different names, so you need to tell the program which naming convention is to be used.

GPIO.setwarnings(False)
This tells Python not to print GPIO warning messages to the screen.

GPIO.setup(18,GPIO.OUT)
This line tells the Python interpreter that pin 18 is going to be used for outputting information, which means you are going to be able to turn the pin ‘on’ and ‘off’.

print "LED on"
This line prints some information to the terminal.

GPIO.output(18,GPIO.HIGH)
This turns the GPIO pin ‘on’. What this actually means is that the pin is made to provide power of 3.3volts.  This is enough to turn the LED in our circuit on.

time.sleep(1)
Pauses the Python program for 1 second

print "LED off"
This line prints some information to the terminal.

GPIO.output(18,GPIO.LOW)
This turns the GPIO pin ‘off’, meaning that the pin is no longer supplying any power.

沒有留言:

張貼留言