Skip to content

Commit fa2e701

Browse files
committed
examples, SDdatalogger: Add more comments; reduce power consumption.
1 parent 2a5b3cd commit fa2e701

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

examples/SDdatalogger/boot.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
88

99
import pyb
1010

11-
pyb.LED(3).on()
12-
pyb.delay(2000)
13-
pyb.LED(4).on()
14-
pyb.LED(3).off()
15-
switch = pyb.Switch() # check if switch was pressed decision phase
11+
pyb.LED(3).on() # indicate we are waiting for switch press
12+
pyb.delay(2000) # wait for user to maybe press the switch
13+
switch_value = pyb.Switch()() # sample the switch at end of delay
14+
pyb.LED(3).off() # indicate that we finished waiting for the switch
1615

17-
if switch():
16+
pyb.LED(4).on() # indicate that we are selecting the mode
17+
18+
if switch_value:
1819
pyb.usb_mode('CDC+MSC')
1920
pyb.main('cardreader.py') # if switch was pressed, run this
2021
else:
2122
pyb.usb_mode('CDC+HID')
2223
pyb.main('datalogger.py') # if switch wasn't pressed, run this
2324

24-
pyb.LED(4).off()
25+
pyb.LED(4).off() # indicate that we finished selecting the mode

examples/SDdatalogger/datalogger.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
# loop
1212
while True:
1313

14+
# wait for interrupt
15+
# this reduces power consumption while waiting for switch press
16+
pyb.wfi()
17+
1418
# start if switch is pressed
1519
if switch():
1620
pyb.delay(200) # delay avoids detection of multiple presses

0 commit comments

Comments
 (0)