0

The script below works. I have tried to comment what is going on, and also what I want to change. Instead of relying on pressing a button on the PiFace input/ouput board for the Raspberry Pi, I want it to be a certain time (i.e. 5:00 pm ) every time the loop ends and proceeds to write the file.

I've posted something similar to this before, but I don't believe I did a good job of being clear in my intentions. To my knowledge, cron would not work for something like this.

This will be running on a Raspberry Pi, so not a whole lot of computing power there, but it will be the ONLY thing running on it. I want to use this to collect data, once per day. The code follows:

EDIT: I will be adding a RTC to the Pi. Pretty sure all that does is just keep the correct time and not really change anything else..

# 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()
user2506445
  • 129
  • 1
  • 3
  • 12
  • You should look at http://stackoverflow.com/questions/492519/timeout-on-a-python-function-call – hivert Jul 25 '13 at 13:08
  • See: http://stackoverflow.com/questions/17352384/time-as-stopping-condition-of-infinite-loop?rq=1 – Dhara Jul 25 '13 at 13:58

0 Answers0