Principle introduction
Demo show
Demo 01 Light up
import PikaStdLib
import machine
mem = PikaStdLib.MemChecker()
io1 = machine.GPIO()
time = machine.Time()
io1.setPin('PA8')
io1.setMode('out')
io1.enable()
io1.low()
print('hello pikascript')
print('mem.max:')
mem.max()
print('mem.now:')
mem.now()
while True:
io1.low()
time.sleep_ms(500)
io1.high()
time.sleep_ms(500)
Look at the script, it’s all Python3 standard syntax.
Demo 02 Serial port test
import PikaStdLib
import machine
time = machine.Time()
uart = machine.UART()
uart.setId(1)
uart.setBaudRate(115200)
uart.enable()
while True:
time.sleep_ms(500)
readBuff = uart.read(2)
print('read 2 char:')
print(readBuff)
Open a serial port and try to read two characters
This is the output result.
Syntax support
Support for a subset of python3 standard syntax.
object support
Syntax | Runtime | Shell |
---|---|---|
Module Definition | - | - |
Module import | √ | √ |
Class Definition | √ | √ |
class inheritance | √ | √ |
method definition | √ | √ |
method overloading | √ | √ |
method invocation | √ | √ |
parameter definition | √ | √ |
parameter assignment | √ | √ |
object creation | √ | √ |
object destruction | √ | √ |
object nesting | √ | √ |
control flow | √ | √ |
Operator
+ | - | * | / | == | > | < | >= | <= | % | ** | // | != | & | » | « | and | or | not | in | += | -= | *= | /= |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
√ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ |
Control flow
Syntax | State |
---|---|
if | √ |
while | √ |
for in [list] | √ |
for in range(a, b) | √ |
for in [dict] | √ |
if elif else | √ |
for break/continue | √ |
while break/continue | √ |
Module
Syntax | Python Module |
---|---|
import [module] | √ |
import [module] as | √ |
from [module] import [class/function>] | √ |
from [module] import [class/function>] as | √ |
from [module] import * | - |
List/Dict
Syntax | State |
---|---|
l = list() | √ |
l = [a, b, c] | √ |
d = dict() | √ |
d = {‘a’:x, ‘b’:y, ‘c’:z} | √ |
Exception
Syntax | State |
---|---|
try: | √ |
except: | √ |
except [Exception]: | - |
except [Exception] as [err]: | - |
except: … | |
raise: | √ |
raise [Exception]: | - |
finally: | - |
Slice
Syntax | str | bytes | list |
---|---|---|---|
test[i] | √ | √ | √ |
test[a : b] | √ | √ | √ |
test[a :] | √ | √ | √ |
Other keywords/Syntax
yield | is | comprehensions |
---|---|---|
- - | √ | - |