Can anyone explain this?
Posted: Fri Sep 04, 2015 10:34 am
The behaviour of the following script varies depending on the delay in the last but one line. With a delay of 10mS or above it runs as expected with the LED coming on for one second, then going off for five seconds. With a 1mS delay the LED stays on for 55 secs and goes off for 5. With the delay commented out the LED stays on continuously but the current consumption of the board spikes to 22mA every 6 seconds indicating that the RTC low power delay code is running as expected.
Code: Select all
import pyb
rtc = pyb.RTC()
rtc.datetime((2015, 8, 6, 4, 13, 0, 0, 0)) # ensure it's initialised (?)
usb_connected = pyb.Pin.board.USB_VBUS.value() == 1
def lpdelay(ms):
rtc.wakeup(ms)
pyb.stop()
rtc.wakeup(None)
if not usb_connected:
led = pyb.LED(4)
while True:
led.on()
pyb.delay(1000) # use pyb version to keep weirdness in one place
led.off()
# pyb.delay(1)
lpdelay(5000)