Created
March 5, 2014 15:01
-
-
Save nst/9368896 to your computer and use it in GitHub Desktop.
Counts the number of heartbeats per minute.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
"""" | |
Counts the number of heartbeats per minute. | |
For example, you can use it to count your mp3's bpm or your number or heartbeats or breaths per minute. | |
$ python bpm.py | |
BPM - Calcule les bpm sur les 4 derniers beats. | |
Appuyer sur a chaque beat, 'q' pour quitter. | |
BPM : - | |
BPM : 83 | |
BPM : 82 | |
BPM : 85 | |
BPM : 87 | |
BPM : 86 | |
BPM : 87 | |
q | |
"""" | |
import time | |
t = [] | |
print "BPM - Calcule les bpm sur les 4 derniers beats." | |
print "Appuyer sur <enter> a chaque beat, 'q' pour quitter." | |
raw_input() | |
t0 = time.time() | |
print "BPM : -" | |
while(raw_input() != 'q'): | |
t1 = time.time() | |
t.append(60 / (t1 - t0)) | |
print "BPM : %d" % int(sum(t) / float(len(t))) | |
t0 = t1 | |
if len(t) >= 4: | |
t.pop(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment