SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
What more?
We can randomly generate colors and make a colorful flowing light.
import
machine
from
ws2812
import
WS2812
import
utime
import
urandom
ws
=
WS2812(machine
.
Pin(
0
),
8
)
def
flowing_light
():
for
i
in
range
(
7
,
0
,
-
1
):
ws[i]
=
ws[i
-
1
]
ws[
0
]
=
int
(urandom
.
uniform(
0
,
0xFFFFFF
))
ws
.
write()
utime
.
sleep_ms(
80
)
while
True
:
flowing_light()
(ws[
0
])
3.5 MicroPython Basic Syntax
3.5.1 Indentation
Indentation refers to the spaces at the beginning of a code line. Like standard Python programs, MicroPython programs
usually run from top to bottom: It traverses each line in turn, runs it in the interpreter, and then continues to the next
line, Just like you type them line by line in the Shell. A program that just browses the instruction list line by line is
not very smart, though – so MicroPython, just like Python, has its own method to control the sequence of its program
execution: indentation.
You must put at least one space before print(), otherwise an error message “Invalid syntax” will appear. It is usually
recommended to standardise spaces by pressing the Tab key uniformly.
if
8
>
5
:
(
"Eight is greater than Five!"
)
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "<stdin>", line 2
SyntaxError: invalid syntax
You must use the same number of spaces in the same block of code, or Python will give you an error.
if
8
>
5
:
(
"Eight is greater than Five!"
)
(
"Eight is greater than Five"
)
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "<stdin>", line 2
SyntaxError: invalid syntax
3.5. MicroPython Basic Syntax
109
Содержание Thales Kit
Страница 1: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 Jimmy SunFounder Jun 04 2021 ...
Страница 2: ......
Страница 4: ...ii ...
Страница 6: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 CONTENTS ...
Страница 10: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 6 Chapter 1 Introduction to Raspberry Pi Pico ...
Страница 12: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 8 Chapter 2 What is Included in This Kit ...
Страница 13: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 1 Components List 2 1 Components List 9 ...
Страница 42: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 38 Chapter 2 What is Included in This Kit ...
Страница 140: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 136 Chapter 3 For MicroPython User ...
Страница 164: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 160 Chapter 4 For Arduino User ...