examples, SDdatalogger: Add more comments; reduce power consumption.

This commit is contained in:
Damien George 2014-05-05 14:09:23 +01:00
parent 2a5b3cdf82
commit fa2e701e23
2 changed files with 12 additions and 7 deletions

View File

@ -8,17 +8,18 @@
import pyb import pyb
pyb.LED(3).on() pyb.LED(3).on() # indicate we are waiting for switch press
pyb.delay(2000) pyb.delay(2000) # wait for user to maybe press the switch
pyb.LED(4).on() switch_value = pyb.Switch()() # sample the switch at end of delay
pyb.LED(3).off() pyb.LED(3).off() # indicate that we finished waiting for the switch
switch = pyb.Switch() # check if switch was pressed decision phase
if switch(): pyb.LED(4).on() # indicate that we are selecting the mode
if switch_value:
pyb.usb_mode('CDC+MSC') pyb.usb_mode('CDC+MSC')
pyb.main('cardreader.py') # if switch was pressed, run this pyb.main('cardreader.py') # if switch was pressed, run this
else: else:
pyb.usb_mode('CDC+HID') pyb.usb_mode('CDC+HID')
pyb.main('datalogger.py') # if switch wasn't pressed, run this 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

View File

@ -11,6 +11,10 @@ switch = pyb.Switch()
# loop # loop
while True: while True:
# wait for interrupt
# this reduces power consumption while waiting for switch press
pyb.wfi()
# start if switch is pressed # start if switch is pressed
if switch(): if switch():
pyb.delay(200) # delay avoids detection of multiple presses pyb.delay(200) # delay avoids detection of multiple presses