Skip to content

Commit 7468551

Browse files
committed
【完善】修改 pin 相关的 mpy 示例程序
1 parent 94786f8 commit 7468551

File tree

5 files changed

+53
-7
lines changed

5 files changed

+53
-7
lines changed

examples/stm32l4_pandora/beeper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import utime as time
1212
from machine import Pin
1313

14-
PIN_BEEPER = 37
14+
PIN_BEEPER = 18 # PB2, get the pin number from get_pin_number.py
1515

1616
# create beeper object from pin PIN_BEEPER, Set pin PIN_BEEPER to output mode
1717
beeper = Pin(("beep", PIN_BEEPER), Pin.OUT_PP)

examples/stm32l4_pandora/blink.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import utime as time
1212
from machine import Pin
1313

14-
PIN_LED_R = 38
14+
PIN_LED_R = 71 # PE7, get the pin number from get_pin_number.py
1515

1616
# create led object from pin PIN_LED_R, Set pin PIN_LED_R to output mode
1717
led = Pin(("led_red", PIN_LED_R), Pin.OUT_PP)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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-28 SummerGift first version
9+
#
10+
11+
def get_pin_num(pin_index):
12+
"""
13+
Get the GPIO pin number through the GPIO index, format must be "P + <A~K> + number", such as PE11
14+
"""
15+
16+
if pin_index[0] != 'P':
17+
print("ERROR : Please pass in the correct parameters")
18+
return
19+
20+
if pin_index[1] == 'A':
21+
pin_num = pin_index[2:]
22+
elif pin_index[1] == 'B':
23+
pin_num = (16 + int(pin_index[2:]))
24+
elif pin_index[1] == 'C':
25+
pin_num = (32 + int(pin_index[2:]))
26+
elif pin_index[1] == 'D':
27+
pin_num = (48 + int(pin_index[2:]))
28+
elif pin_index[1] == 'E':
29+
pin_num = (64 + int(pin_index[2:]))
30+
elif pin_index[1] == 'F':
31+
pin_num = (80 + int(pin_index[2:]))
32+
elif pin_index[1] == 'G':
33+
pin_num = (96 + int(pin_index[2:]))
34+
elif pin_index[1] == 'H':
35+
pin_num = (112 + int(pin_index[2:]))
36+
elif pin_index[1] == 'I':
37+
pin_num = (128 + int(pin_index[2:]))
38+
elif pin_index[1] == 'J':
39+
pin_num = (144 + int(pin_index[2:]))
40+
elif pin_index[1] == 'K':
41+
pin_num = (160 + int(pin_index[2:]))
42+
43+
return pin_num
44+
45+
pin_num = get_pin_num("PE11") # Get the pin number for PE11
46+
print(pin_num)

examples/stm32l4_pandora/key.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
from machine import Pin
1212

13-
PIN_LED_R = 38
14-
PIN_KEY0 = 57
13+
PIN_LED_R = 71 # PE7, get the pin number from get_pin_number.py
14+
PIN_KEY0 = 58 # PD10, get the pin number from get_pin_number.py
1515
KEY_PRESSED = 0
1616

1717
# create led object from pin PIN_LED_R, Set pin PIN_LED_R to output mode

examples/stm32l4_pandora/rgb_led.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import utime as time
1212
from machine import Pin
1313

14-
PIN_LED_R = 38
15-
PIN_LED_G = 39
16-
PIN_LED_B = 40
14+
PIN_LED_R = 71 # PE7, get the pin number from get_pin_number.py
15+
PIN_LED_G = 72 # PE8
16+
PIN_LED_B = 73 # PE9
1717

1818
LED_ON = 0
1919
LED_OFF = 1

0 commit comments

Comments
 (0)