diff --git a/examples/SDdatalogger/boot.py b/examples/SDdatalogger/boot.py index f5006df932..aa943fde93 100644 --- a/examples/SDdatalogger/boot.py +++ b/examples/SDdatalogger/boot.py @@ -8,17 +8,18 @@ import pyb -pyb.LED(3).on() -pyb.delay(2000) -pyb.LED(4).on() -pyb.LED(3).off() -switch = pyb.Switch() # check if switch was pressed decision phase +pyb.LED(3).on() # indicate we are waiting for switch press +pyb.delay(2000) # wait for user to maybe press the switch +switch_value = pyb.Switch()() # sample the switch at end of delay +pyb.LED(3).off() # indicate that we finished waiting for the switch -if switch(): +pyb.LED(4).on() # indicate that we are selecting the mode + +if switch_value: pyb.usb_mode('CDC+MSC') pyb.main('cardreader.py') # if switch was pressed, run this else: pyb.usb_mode('CDC+HID') pyb.main('datalogger.py') # if switch wasn't pressed, run this -pyb.LED(4).off() +pyb.LED(4).off() # indicate that we finished selecting the mode diff --git a/examples/SDdatalogger/datalogger.py b/examples/SDdatalogger/datalogger.py index dcac0091e8..6123db7d27 100644 --- a/examples/SDdatalogger/datalogger.py +++ b/examples/SDdatalogger/datalogger.py @@ -11,6 +11,10 @@ switch = pyb.Switch() # loop while True: + # wait for interrupt + # this reduces power consumption while waiting for switch press + pyb.wfi() + # start if switch is pressed if switch(): pyb.delay(200) # delay avoids detection of multiple presses