File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -13,18 +13,27 @@ Examples for micropython at NodeMCU
1313
1414led_on.py : light LED
1515 GPIO setting, OUT
16+ Pin:D0
1617
1718flash_key : pushing the flash button will light LED
1819 GPIO setting, IN , Timer w/ polling
20+ Pin:D3
1921
2022led_breath.py : make LED light and dim
2123 software PWM , Timer, w/ delay
2224 may cause reset w/ o correct setting
25+ Pin:D0
2326
2427led_breath_timer.py : make LED light and dim
2528 software PWM , Timer
2629 set each period w/ timer
30+ Pin:D0
2731
2832stepper.py : use 28BYJ - 48 5V DC stepper
33+ Pin:D1, D2, D3, D4
34+
35+ sonic.py : use HC - SR04 to measure distance
36+ Pin:D5, D6
37+
2938
3039```
Original file line number Diff line number Diff line change 1+ from pyb import Pin
2+ from time import sleep_ms , sleep_us , ticks_us
3+ from machine import Timer
4+
5+ D5 = Pin (14 , Pin .OUT )
6+ D6 = Pin (12 , Pin .IN )
7+ Trig = D5
8+ Echo = D6
9+
10+ def measure ():
11+ Trig .low ()
12+ sleep_us (15 )
13+ Trig .high ()
14+ sleep_us (15 )
15+ Trig .low ()
16+ while (Echo .value () == 0 ):
17+ start = ticks_us ()
18+ while (Echo .value () == 1 ):
19+ end = ticks_us ()
20+ duration = end - start
21+ dist = 0.03435 * 0.5 * duration
22+ print ("duration: " + str (duration ) + ", " + \
23+ "distance: " + str (dist ))
24+ return dist
25+
26+ tim = Timer (0 )
27+ tim .deinit ()
28+ tim .init (period = 200 , mode = Timer .PERIODIC , callback = lambda t :measure ())
29+ #
You can’t perform that action at this time.
0 commit comments