I let the program run for a few loops then press the switch. The lights change indicating the loop is terminating. it then just hangs for a bit, terminates my repl session on my laptop, continues to hang eventually the lights switch off, but my file probably will be corrupted.
Here's a minimium example
Code: Select all
import pyb
import os
pressed = False
def switch_cb():
global pressed
pressed = True
def timer_cb(timer):
pyb.LED(1).toggle()
def main():
pyb.LED(2).on()
os.mount(pyb.SDCard(), '/sd')
os.chdir('/sd')
try:
with open("boot_file.txt","r") as f:
info=f.readline()
except OSError:
info=None
if "boot_file.txt" in os.listdir():
os.remove("boot_file.txt")
blue=pyb.LED(4)
blue.off()
yellow=pyb.LED(3)
yellow.on()
print("")
with open("data_file.txt","a") as f:
while not pressed:
f.write("hello world.\n")
print(".",end="")
for _ in range(60):
if pressed:
break
pyb.delay(1000)
yellow.toggle()
blue.toggle()
print("")
blue.off()
yellow.off()
with open("boot_file.txt", "w") as f:
f.write("saved state for next time\n")
os.umount('/sd')
pyb.LED(2).off()
if __name__ == "__main__":
switch = pyb.Switch()
switch.callback(switch_cb)
timer = pyb.Timer(14, freq=3)
timer.callback(timer_cb)
pyb.delay(5000)
timer.callback(None)
main()
1) a previously used timer
2) a boot file which is deleted on boot and re written on exit
3) writing of data in a sleepy loop
This is a bug and i haven't done some thing wrong?
update:
if i re start repl whilst there are LEDs still on I get the message unable to open `/dev/ttyACM0`
if i wait until they extinguish the repl session is totally un responsive except to pressing CTRL+D (soft reboot). This just causes the pyboard to flash the red and green lights (error?), no message printed.