You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/micropython/01.basics/08.reference/reference.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -107,6 +107,9 @@ For example:
107
107
-[float()](#float)
108
108
-[int()](#int)
109
109
-[Local / Global Variables](#local--global-variables)
110
+
-[Sketch](#sketch)
111
+
-[loop()](#loop)
112
+
-[setup()](#setup)
110
113
111
114
## Digital I/O
112
115
@@ -1421,3 +1424,50 @@ because it is not declared globally.
1421
1424
'''
1422
1425
#print(local_var)
1423
1426
```
1427
+
1428
+
## Sketch
1429
+
1430
+
MicroPython uses scripts as opposed to traditional sketches that require the `void loop()` and `void setup()` functions.
1431
+
1432
+
A script can be as simple as a single line that prints "Hello World!"
1433
+
1434
+
```python
1435
+
print("Hello World!")
1436
+
```
1437
+
1438
+
### loop()
1439
+
1440
+
`while True:`
1441
+
1442
+
A loop is not required in a MicroPython script, but is required in order to run a script continuously on the board. To have a loop in a program, we need to use a [while loop]().
1443
+
1444
+
**Example:**
1445
+
1446
+
The example below runs a loop that increases the `value` variable by `1` each time the loop is run. It then prints the value to the REPL, and waits for a second.
1447
+
1448
+
```python
1449
+
import time
1450
+
value =0
1451
+
1452
+
whileTrue:
1453
+
value +=1
1454
+
print(value)
1455
+
time.sleep(1)
1456
+
```
1457
+
1458
+
### setup()
1459
+
1460
+
In MicroPython, there's no equalivent of the `setup()` function. Configurations that are traditionally done in this function can simply be declared at the top of the program.
1461
+
1462
+
**Example:**
1463
+
1464
+
This script simply declares a pin's pin mode (see [pinMode()](#pinmode)).
0 commit comments