Skip to content

Commit a35edf5

Browse files
committed
【完善】get_pin_num 例程
1 parent 827d003 commit a35edf5

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

examples/stm32l4_pandora/get_pin_num.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,31 @@
1010

1111
def get_pin_num(pin_index):
1212
"""
13-
Get the GPIO pin number through the GPIO index, format must be "P + <A~K> + number", such as PE11
13+
Get the GPIO pin number through the GPIO index, format must be "P + <A~K> + number", such as PE7
1414
"""
1515

1616
if pin_index[0] != 'P':
17-
print("ERROR : Please pass in the correct parameters P + <A~K> + number, such as PE11")
17+
print("ERROR : Please pass in the correct parameters P + <A~K> + number, such as PE7")
1818
return
1919

2020
if not pin_index[1].isupper():
21-
print("ERROR : Please pass in the correct parameters P + <A~K> + number, such as PE11")
21+
print("ERROR : Please pass in the correct parameters P + <A~K> + number, such as PE7")
2222
return
2323

2424
return (ord(pin_index[1]) - ord('A')) * 16 + int(pin_index[2:])
2525

26-
print(get_pin_num("PE11")) # Get the pin number for PE11
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)

0 commit comments

Comments
 (0)