January 8th, 2013, 01:54 PM
Hi, I am a bit of a newbie and have a simple problem that I cannot solve so I have come here to get some help from the experts.
I am trying to count the number of gpio inputs per second. I have the simple code to count the number of inputs and I can count a second using time.time etc. I just cannot figure out the code required to count inputs per second?
Any help would be appreciated!
January 8th, 2013, 02:36 PM
#do some stuff; accumulate count
Comments on this post
January 10th, 2013, 03:15 PM
Thank you rrashkin, I have tried this code but it does not appear to give me the frequency per second. It just seems to be returning a lot of random numbers. The only difference to your code is that I have an if statement and count = count+1 to read the inputs?! Is there a way of doing this with time. Sleep (1)?!
January 10th, 2013, 10:37 PM
You might find a higher resolution timer on your sound card. Ha ha good luck. I don't understand any of this thread, especially "frequency per second". Almost an acceleration.
[/code] are essential for python code and Makefiles!
January 14th, 2013, 05:04 PM
I think you are looking for APM (actions per minute)? Or second/whatever. Well anyways, I had to do some digging but I found an old AutoHotkey script I wrote which did this (http://forums.ageofempiresonline.com/forums/permalink/158900/158183/ShowThread.aspx#158183) .. it's not in Python obviously. But it's a very short script and shows the concept.
rrashkin's approach is the best one and virtually identical to my approach in the AHK script. You simply need to find out the difference between the time before you started the script, and the time after it's completed. Then divide the input count by the time difference for your frequency.