File tree 1 file changed +45
-8
lines changed
1 file changed +45
-8
lines changed Original file line number Diff line number Diff line change 1
1
# Hello World!
2
2
# hello world!
3
+
3
4
print ('hello world' )
4
5
#####
5
6
# Big Integer
6
7
# bignum
8
+
7
9
print (1 << 1000 )
8
10
#####
9
11
# Assembly
10
12
# inline assembler
13
+
11
14
@micropython .asm_thumb
12
15
def asm_add (r0 , r1 ):
13
16
add (r0 , r0 , r1 )
14
17
print (asm_add (1 , 2 ))
15
18
#####
16
19
# 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 !
18
21
# try using the reset button on the pyboard to quit this script!
19
22
# switch callback not yet supported.
23
+
24
+ import time
20
25
import pyb
21
- sw = pyb .Switch ()
22
- b = sw ()
26
+
23
27
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
+
28
34
#####
29
35
# LEDs
30
- # there are four LEDS numbered 1 to 4
36
+ # four LEDS numbered 1 to 4
37
+
38
+ import time
31
39
import pyb
40
+
32
41
for i in range (1000 ):
33
42
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 ))
You can’t perform that action at this time.
0 commit comments