Просмотр исходного кода

【完善】修改 pin 相关的 mpy 示例程序

SummerGift 6 лет назад
Родитель
Сommit
74685519e7

+ 1 - 1
examples/stm32l4_pandora/beeper.py

@@ -11,7 +11,7 @@
 import utime as time
 from machine import Pin
 
-PIN_BEEPER = 37
+PIN_BEEPER = 18    # PB2, get the pin number from get_pin_number.py
 
 # create beeper object from pin PIN_BEEPER, Set pin PIN_BEEPER to output mode
 beeper = Pin(("beep", PIN_BEEPER), Pin.OUT_PP)

+ 1 - 1
examples/stm32l4_pandora/blink.py

@@ -11,7 +11,7 @@
 import utime as time
 from machine import Pin
 
-PIN_LED_R = 38
+PIN_LED_R = 71    # PE7, get the pin number from get_pin_number.py
 
 # create led object from pin PIN_LED_R, Set pin PIN_LED_R to output mode
 led = Pin(("led_red", PIN_LED_R), Pin.OUT_PP)

+ 46 - 0
examples/stm32l4_pandora/get_pin_num.py

@@ -0,0 +1,46 @@
+# 
+# Copyright (c) 2006-2019, RT-Thread Development Team
+# 
+# SPDX-License-Identifier: MIT License
+# 
+# Change Logs:
+# Date           Author       Notes
+# 2019-06-28     SummerGift   first version
+#
+
+def get_pin_num(pin_index):
+    """
+    Get the GPIO pin number through the GPIO index, format must be "P + <A~K> + number", such as PE11
+    """
+
+    if pin_index[0] != 'P':
+        print("ERROR : Please pass in the correct parameters")
+        return
+
+    if pin_index[1] == 'A':
+        pin_num = pin_index[2:]
+    elif pin_index[1] == 'B':
+        pin_num = (16 + int(pin_index[2:]))
+    elif pin_index[1] == 'C':
+        pin_num = (32 + int(pin_index[2:]))
+    elif pin_index[1] == 'D':
+        pin_num = (48 + int(pin_index[2:]))
+    elif pin_index[1] == 'E':
+        pin_num = (64 + int(pin_index[2:]))
+    elif pin_index[1] == 'F':
+        pin_num = (80 + int(pin_index[2:]))
+    elif pin_index[1] == 'G':
+        pin_num = (96 + int(pin_index[2:]))
+    elif pin_index[1] == 'H':
+        pin_num = (112 + int(pin_index[2:]))
+    elif pin_index[1] == 'I':
+        pin_num = (128 + int(pin_index[2:]))
+    elif pin_index[1] == 'J':
+        pin_num = (144 + int(pin_index[2:]))
+    elif pin_index[1] == 'K':
+        pin_num = (160 + int(pin_index[2:]))
+
+    return pin_num
+
+pin_num = get_pin_num("PE11")   # Get the pin number for PE11
+print(pin_num)

+ 2 - 2
examples/stm32l4_pandora/key.py

@@ -10,8 +10,8 @@
 
 from machine import Pin
 
-PIN_LED_R   = 38
-PIN_KEY0    = 57
+PIN_LED_R   = 71    # PE7, get the pin number from get_pin_number.py
+PIN_KEY0    = 58    # PD10, get the pin number from get_pin_number.py
 KEY_PRESSED = 0
 
 # create led object from pin PIN_LED_R, Set pin PIN_LED_R to output mode

+ 3 - 3
examples/stm32l4_pandora/rgb_led.py

@@ -11,9 +11,9 @@
 import utime as time
 from machine import Pin
 
-PIN_LED_R = 38
-PIN_LED_G = 39
-PIN_LED_B = 40
+PIN_LED_R = 71    # PE7, get the pin number from get_pin_number.py
+PIN_LED_G = 72    # PE8
+PIN_LED_B = 73    # PE9
 
 LED_ON  = 0
 LED_OFF = 1