When trying to write to a file called 'camera.txt' - it doesn't appear to be working. When connected to the REPL with screen /dev/ttyACM0 115600 I can see the count increment correctly.
Below is the main.py - I also have it posted as a Gist for easier reading: https://gist.github.com/anonymous/2b99e ... bd6106dc2d
from pyb import LED
from pyb import Pin
from pyb import Switch
import time
sw = Switch()
# 1 red, 2 green, 3 yellow, 4 blue
ledg = LED(2)
ledb = LED(4)
p_in = Pin('X2', Pin.IN, Pin.PULL_UP)
camera = 0
while True:
#if (p_in.value()):
if sw():
if camera < 5:
camera += 1
else:
camera = 0
ledg.on()
ledb.off()
f = open('camera.txt', 'w')
f.write(str(camera))
print(str(camera))
f.close()
else:
ledb.on()
ledg.off()
Writing to a file when a button is pushed
Re: Writing to a file when a button is pushed
How are you trying to detect that the count is increasing? If you're using the USB Mass Storage (i.e. the hard drive that the host uses) then that will be your problem. USB Mass Storage doesn't work properly when the pyboard writes to the file system. And worst yet, it can corrupt your file.
Re: Writing to a file when a button is pushed
I logged into the REPL over serial to see the count increasing. It is via USB Mass Storage.
So my other approach/idea is to detect a button press and send a keyboard command (CTRL+ALT+T). Then on the linux box I want to map the keyboard event of CTRL+ALT+T to send a message off to a queuing system.
Is this a logical approach? It seems better than writing to a file since you mentioned corruption.
So my other approach/idea is to detect a button press and send a keyboard command (CTRL+ALT+T). Then on the linux box I want to map the keyboard event of CTRL+ALT+T to send a message off to a queuing system.
Is this a logical approach? It seems better than writing to a file since you mentioned corruption.