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 #57 background imageLoading...
Page #57 background image
57
Chapter 1 LED
www.freenove.com
support@freenove.com
Python Code 1.1.1 Blink
Net, we will use Python language to make LED blink.
First, observe the project result, and then analyze the code.
1. Use cd command to enter 01.1.1_Blink directory of Python code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/01.1.1_Blink
2. Use python command to execute python code blink.py.
python Blink.py
Now, LED start blinking.
You can press “Ctrl+C” to end the program. The following is the program code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
im port RPi. GPIO as GPIO
im port time
ledPin = 11 # RPI Board pin11
def setup():
GPIO. setmode(GPIO.BOARD) # Numbers GPIOs by physical location
GPIO. setup(ledPin, GPIO. OUT) # Set ledPin's mode is output
GPIO. output(ledPin, GPIO. LOW) # Set ledPin low to off led
p rint ('using pin%d'%ledPin)
def loop():
w hile Tr ue:
GPIO.output(ledPin, GPIO. HIGH) # led on
print ('...led on')
time.sleep(1) # delay 1 second
GPIO.output(ledPin, GPIO. LOW) # led off
print ('led off...')
time.sleep(1)
def destroy():
GPIO. output(ledPin, GPIO. LOW) # led off
GPIO. cleanup() # Release resource
if __name__ == '__main__': # Program start from here
setup()
try:
loop()
e xcept KeyboardInterrupt: # When 'Ctrl+C' is pressed, the subprogram destroy() will
be executed.
destroy()
In subfunction setup(), GPIO.setmode (GPIO.BOARD) is used to set the serial number for GPIO based on
physical location of the pin. GPIO17 use pin 11 of the board, so define ledPin as 11 and set ledPin to output

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