Python Forum

Full Version: Getting error in finding time.time() value in python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
while True:

    Signal=mcp.read_adc(adc_number)  # The read_adc function will get the value of the specified channel and the Signal will hold the incoming raw digital data
    if(Signal>thresh) and (i<=5):
        if i==0:
            time1=int(time.time()*1000)
        c=c+1
        i=i+1
        time2=int(time.time()*1000)
    t=time2-time1
    rate=t/5
    rate=60000/rate
    print(rate) # BPM
    time.sleep(0.005)
I wrote this program for measuring the beats/minute(BPM) from a pulse sensor. This code shows an error like time2 and time1 not defined. Is this code correct for finding the BPM value from pulse sensor?
Both time1 and time2 are in if condition block of code. If the condition is False they will not be created.