File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 1010
1111def 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 )
You can’t perform that action at this time.
0 commit comments