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 #75 background imageLoading...
Page #75 background image
75
Chapter 3 LEDBar Graph
ā–ˆ www.freenove.com
support@freenove.com ā–ˆ
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
for pin in ledPins:
GPIO.setup(pin, GPIO. OUT) # Set all ledPins' mode is output
GPIO.output(pin, GPIO. HIGH) # Set all ledPins to high(+3.3V) to off led
def loop():
w hile Tr ue:
for pin in ledPins: #make led on from left to right
GPIO.output(pin, GPIO.LOW)
time.sleep(0.1)
GPIO.output(pin, GPIO.HIGH)
for pin in ledPins[::-1]: #make led on from right to left
GPIO.output(pin, GPIO.LOW)
time.sleep(0.1)
GPIO.output(pin, GPIO.HIGH)
def destroy():
for pin in ledPins:
GPIO.output(pin, GPIO. HIGH) # turn off all leds
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 the program, first define 10 pins connected to LED, and set them to output mode in subfunction setup().
Then in the loop() function, use two ā€œforā€ cycles to realize flowing water light from right to left and from left
to right. Among them, ledPins[::-1] is used to traverse elements of ledPins in reverse order.
def loop():
w hile Tr ue:
for pin in ledPins: #make led on from left to right
GPIO.output(pin, GPIO.LOW)
time.sleep(0.1)
GPIO.output(pin, GPIO.HIGH)
for pin in ledPins[::-1]: #make led on from right to left
GPIO.output(pin, GPIO.LOW)
time.sleep(0.1)
GPIO.output(pin, GPIO.HIGH)

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