Skip to content

Commit 7b8b7fb

Browse files
committed
【添加】基本示例
1 parent 4ab8309 commit 7b8b7fb

File tree

6 files changed

+125
-0
lines changed

6 files changed

+125
-0
lines changed

examples/basic/array.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: MIT License
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-06-13 SummerGift first version
9+
*/
10+
11+
import array
12+
13+
a = array.array('i', [2, 4, 1, 5])
14+
b = array.array('f')
15+
print(a)
16+
print(b)
17+
18+
a = array.array('f', [3, 6])
19+
print(a)
20+
a.append(7.0)
21+
print(a)
22+
23+
a = array.array('i', [1, 2, 3])
24+
b = array.array('i', [4, 5])
25+
a.extend(b)
26+
print(a)

examples/basic/random.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: MIT License
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-06-13 SummerGift first version
9+
*/
10+
11+
import random
12+
13+
for j in range(0, 2):
14+
random.seed(13) #指定随机数种子
15+
for i in range(0, 10): #生成0到10范围内的随机序列
16+
print(random.randint(1, 10))
17+
print("end")

examples/basic/rtthread.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: MIT License
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-06-13 SummerGift first version
9+
*/
10+
11+
import rtthread
12+
13+
print(rtthread.is_preempt_thread()) # determine if code is running in a preemptible thread
14+
print(rtthread.current_tid() ) # current thread id
15+
rtthread.stacks_analyze() # show thread information

examples/basic/sys.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: MIT License
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-06-13 SummerGift first version
9+
*/
10+
11+
import sys
12+
13+
print(sys.version)
14+
print(sys.version_info)
15+
print(sys.path)
16+
print(sys.__name__)
17+
print(sys.platform)
18+
print(sys.byteorder)

examples/basic/ucollections.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: MIT License
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-06-13 SummerGift first version
9+
*/
10+
11+
from ucollections import namedtuple
12+
13+
MyTuple = namedtuple("MyTuple", ("id", "name"))
14+
t1 = MyTuple(1, "foo")
15+
t2 = MyTuple(2, "bar")
16+
print(t1.name)
17+
assert t2.name == t2[1]
18+
ucollections.OrderedDict(...)
19+
20+
from ucollections import OrderedDict
21+
22+
# To make benefit of ordered keys, OrderedDict should be initialized
23+
# from sequence of (key, value) pairs.
24+
d = OrderedDict([("z", 1), ("a", 2)])
25+
# More items can be added as usual
26+
d["w"] = 5
27+
d["b"] = 3
28+
for k, v in d.items():
29+
print(k, v)

examples/basic/utime.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: MIT License
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-06-13 SummerGift first version
9+
*/
10+
11+
import utime
12+
13+
utime.sleep(1) # sleep for 1 second
14+
utime.sleep_ms(500) # sleep for 500 milliseconds
15+
utime.sleep_us(10) # sleep for 10 microseconds
16+
start = utime.ticks_ms() # get value of millisecond counter
17+
delta = utime.ticks_diff(utime.ticks_ms(), start) # compute time difference
18+
print(utime.ticks_add(utime.ticks_ms(), -100))
19+
print(utime.ticks_add(0, -1))
20+

0 commit comments

Comments
 (0)