EasyManuals Logo

Freenove Ultimate Starter Kit User Manual

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #58 background imageLoading...
Page #58 background image
Chapter 1 LED
58
www.freenove.com
support@freenove.com
mode (output low level).
ledPin = 11 # RPi Board pin11
def setup():
GPIO. setmode(GPIO.BOARD) # Numbers GPIOs by physical location
GPIO. setup(ledPin, GPIO. OUT) # Set ledPin to output mode
GPIO. output(ledPin, GPIO. LOW) # Set ledPin to low level to turn off led
p rint ('using pin%d'%ledPin)
In loop(), there is a while cycle, which is an endless loop. That is, the program will always be executed in this
cycle, unless it is ended outside. In this cycle, set ledPin output high level, then LED is turned on. After a period
of time delay, set ledPin output low level, then LED is turned off, which is followed by a delay. Repeat the
cycle, then LED will start blinking.
def loop():
w hile Tr ue:
GPIO.output(ledPin, GPIO. HIGH) # led on
print ('...led on')
time.sleep(1)
GPIO.output(ledPin, GPIO. LOW) # led off
print ('led off...')
time.sleep(1)
Finally, when the program is terminated, subfunction will be executed, the LED will be turned off and then the
IO port will be released. If close the program terminal directly, the program will be terminated too, but destroy()
function will not be executed. So, GPIO resources won’t be released, in the warning message may appear next
time you use GPIO. So, it is not a good habit to close the program terminal directly.
def destroy():
GPIO. output(ledPin, GPIO. LOW) # led is turned off
GPIO. cleanup() # Release resource
About RPi.GPIO
RPi.GPIO
This is a Python module to control the GPIO on a Raspberry Pi. It includes basic output function and input
function of GPIO, and function used to generate PWM.
GP IO.setmode(mode)
Set the mode for pin serial number of GPIO.
mode=GPIO.BOARD, which represents the GPIO pin serial number is based on physical location of RPi.
mode=GPIO.BCM, which represents the pin serial number is based on CPU of BCM chip.
GP IO.setup(pin,mode)
Set pin to input mode or output mode. “pin for the GPIO pin, mode for INPUT or OUTPUT.
GPIO.output(pin,mode)
Set pin to output mode. “pin for the GPIO pin, mode for HIGH (high level) or LOW (low level).
For more functions related to RPi.GPIO, please refer to:
https://sourceforge.net/p/raspberry-gpio-python/wiki/Examples/
“import time” time is a module of python.
https://docs.python.org/2/library/time.html?highlight=time%20time#module-time

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove Ultimate Starter Kit and is the answer not in the manual?

Freenove Ultimate Starter Kit Specifications

General IconGeneral
BrandFreenove
ModelUltimate Starter Kit
CategorySingle board computers
LanguageEnglish