Thread: Speedometer

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Speedometer


    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!

    Thanks,

    Martin.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Location
    39N 104.28W
    Posts
    158
    Rep Power
    3
    import datetime
    t1=datetime.datetime.now()
    #do some stuff; accumulate count
    t2=datetime.datetime.now()
    elapsed=t2.second-t1.second
    elapsed+=(t2.microsecond-t1.microsecond)/1000000.0
    frequency=count/elapsed

    Comments on this post

    • Erents agrees
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    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)?!
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    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]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    43
    Rep Power
    2
    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.

IMN logo majestic logo threadwatch logo seochat tools logo