Skip to content

Commit fd09d3a

Browse files
committed
examples: rename and add python code
1. Rename the examples name 2. Add python code 3. Add examples path to code format
1 parent dabd7fd commit fd09d3a

File tree

7 files changed

+120
-0
lines changed

7 files changed

+120
-0
lines changed

examples/unit/angle/angle_core.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import os, sys, io
2+
import M5
3+
from M5 import *
4+
from unit import AngleUnit
5+
6+
7+
angle_0 = None
8+
9+
10+
def setup():
11+
global angle_0
12+
13+
angle_0 = AngleUnit((36, 26))
14+
M5.begin()
15+
Widgets.fillScreen(0x222222)
16+
17+
18+
def loop():
19+
global angle_0
20+
M5.update()
21+
print(angle_0.get_voltage())
22+
print(angle_0.get_value())
23+
24+
25+
if __name__ == "__main__":
26+
try:
27+
setup()
28+
while True:
29+
loop()
30+
except (Exception, KeyboardInterrupt) as e:
31+
try:
32+
from utility import print_error_msg
33+
34+
print_error_msg(e)
35+
except ImportError:
36+
print("please update to latest firmware")

examples/unit/env/env_cores2.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import os, sys, io
2+
import M5
3+
from M5 import *
4+
from hardware import *
5+
from unit import ENVUnit
6+
7+
8+
i2c0 = None
9+
env_0 = None
10+
env2_0 = None
11+
env3_0 = None
12+
13+
14+
def setup():
15+
global i2c0, env_0, env2_0, env3_0
16+
17+
M5.begin()
18+
Widgets.fillScreen(0x222222)
19+
20+
i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
21+
env_0 = ENVUnit(i2c=i2c0, type=1)
22+
env2_0 = ENVUnit(i2c=i2c0, type=2)
23+
env3_0 = ENVUnit(i2c=i2c0, type=3)
24+
print(env_0.read_temperature())
25+
print(env_0.read_humidity())
26+
print(env_0.read_pressure())
27+
28+
29+
def loop():
30+
global i2c0, env_0, env2_0, env3_0
31+
M5.update()
32+
33+
34+
if __name__ == "__main__":
35+
try:
36+
setup()
37+
while True:
38+
loop()
39+
except (Exception, KeyboardInterrupt) as e:
40+
try:
41+
from utility import print_error_msg
42+
43+
print_error_msg(e)
44+
except ImportError:
45+
print("please update to latest firmware")

examples/unit/rgb/rgb_core.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os, sys, io
2+
import M5
3+
from M5 import *
4+
from unit import RGBUnit
5+
6+
7+
rgb_0 = None
8+
9+
10+
def setup():
11+
global rgb_0
12+
13+
rgb_0 = RGBUnit((36, 26), 3)
14+
M5.begin()
15+
Widgets.fillScreen(0x222222)
16+
17+
rgb_0.set_brightness(80)
18+
rgb_0.fill_color(0xFF0000)
19+
rgb_0.set_color(0, 0x33FF33)
20+
21+
22+
def loop():
23+
global rgb_0
24+
M5.update()
25+
26+
27+
if __name__ == "__main__":
28+
try:
29+
setup()
30+
while True:
31+
loop()
32+
except (Exception, KeyboardInterrupt) as e:
33+
try:
34+
from utility import print_error_msg
35+
36+
print_error_msg(e)
37+
except ImportError:
38+
print("please update to latest firmware")

tools/codeformat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"m5stack/modules/**/*.py",
5050
"tools/*.py",
5151
"tests/**/*.py",
52+
"examples/**/*.py",
5253
]
5354

5455
# Path to repo top-level dir.

0 commit comments

Comments
 (0)