فهرست منبع

【完善】get_pin_num 例程

SummerGift 6 سال پیش
والد
کامیت
a35edf54b4
1فایلهای تغییر یافته به همراه18 افزوده شده و 4 حذف شده
  1. 18 4
      examples/stm32l4_pandora/get_pin_num.py

+ 18 - 4
examples/stm32l4_pandora/get_pin_num.py

@@ -10,17 +10,31 @@
 
 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
+    Get the GPIO pin number through the GPIO index, format must be "P + <A~K> + number", such as PE7
     """
 
     if pin_index[0] != 'P':
-        print("ERROR : Please pass in the correct parameters P + <A~K> + number, such as PE11")
+        print("ERROR : Please pass in the correct parameters P + <A~K> + number, such as PE7")
         return
 
     if not pin_index[1].isupper():
-        print("ERROR : Please pass in the correct parameters P + <A~K> + number, such as PE11")
+        print("ERROR : Please pass in the correct parameters P + <A~K> + number, such as PE7")
         return
 
     return (ord(pin_index[1]) - ord('A')) * 16 + int(pin_index[2:])
 
-print(get_pin_num("PE11")) # Get the pin number for PE11
+print("The pin number of PE7 is %d, then blink the red led."%get_pin_num("PE7")) # Get the pin number for PE7
+
+# then you can use the pin num to control the device, such as led:
+
+import utime as time
+from machine import Pin
+
+# create led object from get_pin_num("PE7") and set pin to output mode
+led = Pin(("led_red", get_pin_num("PE7")), Pin.OUT_PP)
+
+while True:
+    led.value(0)  # Set led turn on
+    time.sleep(0.5)
+    led.value(1)  # Set led turn off
+    time.sleep(0.5)