有一定时间停止内部无限循环的条件

时间:2013-07-25 13:03:24

标签: python

以下脚本有效。我试图评论正在发生的事情,以及我想要改变的事情。我没有依赖于在Raspberry Pi的PiFace输入/输出板上按下按钮,而是每次循环结束时都希望它是一定时间(即下午5:00)并继续写入文件。

之前我发布了类似的内容,但我不相信我很清楚我的意图。据我所知,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()

0 个答案:

没有答案