Python Forum
Getting error in finding time.time() value in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting error in finding time.time() value in python
#1
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?
Reply
#2
Both time1 and time2 are in if condition block of code. If the condition is False they will not be created.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Schedule exit a program at a specific time 4 am every day. chubbychub 3 304 May-17-2024, 03:45 PM
Last Post: chubbychub
  Filer and sort files by modification time in a directory tester_V 5 449 May-02-2024, 05:39 PM
Last Post: tester_V
Question Convert UTC now() to local time to compare to a strptime() Calab 2 323 Apr-29-2024, 07:24 PM
Last Post: deanhystad
  Date Time Series Help...Please spra8560 2 457 Feb-01-2024, 01:38 PM
Last Post: spra8560
  Python date format changes to date & time 1418 4 764 Jan-20-2024, 04:45 AM
Last Post: 1418
  time difference bettwenn logs enkliy 14 1,193 Nov-21-2023, 04:51 PM
Last Post: rob101
Question Need Help with Vehicle Routing Problem with Time Windows (VRPTW) in Python kasper321421312 1 676 Nov-10-2023, 08:19 PM
Last Post: snippsat
  How do I stream and record at the same time with arducam? traderjoe 0 522 Oct-23-2023, 12:01 AM
Last Post: traderjoe
  i tried to install python for the first time today and pretty certain im being remote brianlj 2 618 Oct-03-2023, 11:15 AM
Last Post: snippsat
  Error is finding mean of a list PythonBoy 4 995 Sep-11-2023, 02:38 PM
Last Post: PythonBoy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020