Skip to content

Commit 2559d28

Browse files
authored
Merge pull request #86 from SummerGGift/optimize_example
【完善】修改 pin 相关的 mpy 示例程序
2 parents 94786f8 + a35edf5 commit 2559d28

5 files changed

Lines changed: 47 additions & 7 deletions

File tree

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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 PE7
14+
"""
15+
16+
if pin_index[0] != 'P':
17+
print("ERROR : Please pass in the correct parameters P + <A~K> + number, such as PE7")
18+
return
19+
20+
if not pin_index[1].isupper():
21+
print("ERROR : Please pass in the correct parameters P + <A~K> + number, such as PE7")
22+
return
23+
24+
return (ord(pin_index[1]) - ord('A')) * 16 + int(pin_index[2:])
25+
26+
print("The pin number of PE7 is %d, then blink the red led."%get_pin_num("PE7")) # Get the pin number for PE7
27+
28+
# then you can use the pin num to control the device, such as led:
29+
30+
import utime as time
31+
from machine import Pin
32+
33+
# create led object from get_pin_num("PE7") and set pin to output mode
34+
led = Pin(("led_red", get_pin_num("PE7")), Pin.OUT_PP)
35+
36+
while True:
37+
led.value(0) # Set led turn on
38+
time.sleep(0.5)
39+
led.value(1) # Set led turn off
40+
time.sleep(0.5)

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)