File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111import utime as time
1212from 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
1717beeper = Pin (("beep" , PIN_BEEPER ), Pin .OUT_PP )
Original file line number Diff line number Diff line change 1111import utime as time
1212from 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
1717led = Pin (("led_red" , PIN_LED_R ), Pin .OUT_PP )
Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 1010
1111from 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
1515KEY_PRESSED = 0
1616
1717# create led object from pin PIN_LED_R, Set pin PIN_LED_R to output mode
Original file line number Diff line number Diff line change 1111import utime as time
1212from 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
1818LED_ON = 0
1919LED_OFF = 1
You can’t perform that action at this time.
0 commit comments