Skip to content

Commit ff3d6fa

Browse files
committed
www-emu/pyboard_demos.py: Add and improve pyboard demos.
1 parent 26eb525 commit ff3d6fa

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

www-emu/pyboard_demos.py

+45-8
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,70 @@
11
# Hello World!
22
# hello world!
3+
34
print('hello world')
45
#####
56
# Big Integer
67
# bignum
8+
79
print(1 << 1000)
810
#####
911
# Assembly
1012
# inline assembler
13+
1114
@micropython.asm_thumb
1215
def asm_add(r0, r1):
1316
add(r0, r0, r1)
1417
print(asm_add(1, 2))
1518
#####
1619
# Switch
17-
# push the USR button on the pyboard to turn the switch on!
20+
# push the USR button on the pyboard to flash the LEDs!
1821
# try using the reset button on the pyboard to quit this script!
1922
# switch callback not yet supported.
23+
24+
import time
2025
import pyb
21-
sw = pyb.Switch()
22-
b = sw()
26+
2327
while True:
24-
s = sw()
25-
if b != s:
26-
print(s)
27-
b = s
28+
if pyb.Switch().value():
29+
pyb.LED(1).on()
30+
else:
31+
pyb.LED(1).off()
32+
time.sleep_ms(50)
33+
2834
#####
2935
# LEDs
30-
# there are four LEDS numbered 1 to 4
36+
# four LEDS numbered 1 to 4
37+
38+
import time
3139
import pyb
40+
3241
for i in range(1000):
3342
pyb.LED((i%4) + 1).toggle()
43+
time.sleep_ms(100)
44+
#####
45+
# Time
46+
# the time module is utime, a specialized MicroPython library
47+
# sleep will break the clock speed
48+
# dates not yet supported
49+
50+
import time
51+
52+
print(time.ticks_ms())
53+
54+
time.sleep_ms(1000)
55+
56+
print(time.ticks_us())
57+
58+
time.sleep_us(1000000)
59+
#####
60+
# Math
61+
# a subset of the Python Math library
62+
63+
import math
64+
import cmath
65+
66+
print(math.sqrt(5))
67+
print(math.log10(100))
68+
print(math.sin(12345) ** 2 + math.cos(12345) ** 2)
69+
print(math.cosh(1) ** 2 - math.sinh(1) ** 2)
70+
print(cmath.polar(1 + 1j))

0 commit comments

Comments
 (0)