下面的脚本有效。我试图评论正在发生的事情,以及我想要更改的内容。而不是依赖于按下树莓派 PiFace 输入/输出板上的按钮,我希望它是每次循环结束并继续写入文件时的某个时间(即 5:00 pm )。
我以前发布过类似的东西,但我不相信我在明确自己的意图方面做得很好。据我所知,cron 不适用于这样的事情。
这将在 Raspberry Pi 上运行,因此那里没有很多计算能力,但它将是唯一在其上运行的东西。我想用它来收集数据,每天一次。代码如下:
编辑:我将在 Pi 中添加一个 RTC。很确定所做的只是保持正确的时间,而不是真正改变其他任何东西..
# run infinite
while(True):
# stopping condition, change to true to exit the next infinite loop
done = False;
#
# Main program
#
while(not done):
# go through the list of each button and see if each is pressed
for element in range(8) :
#Code
#Continuously check if a button is pressed on Piface
#Do things
#Count how long they were pressed
#stopping condition as of right now
#when the 7th input on Piface is hit it ends the loop
if (pfio.digital_read(7) == 1) :
done = True
#this works great, except for that I want it to automatically continue
#with the script and write the results to a file once every
#24 hours
#makes sure that my file doesnt overwrite itself if I hold the button down
while(pfio.digital_read(7)==1):
pass
outputFile = open('lights.csv', 'w')
for i in range(len(button_array)):
#Convert the button's time_on variable to a string and append a comma and newline.
outputFile.write(str(button_array[i].total_time_on) + ',\n')
outputFile.close()