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
  Check time within specific time ranges basvdm 3 696 Jan-20-2025, 05:10 PM
Last Post: Gribouillis
Question [SOLVED] [datetime.strptime] ValueError: time data 'foo' does not match format 'bar' Winfried 1 1,397 Jan-02-2025, 02:09 AM
Last Post: lyly19
  Help about a specific time selection QJZ 0 451 Dec-01-2024, 11:25 AM
Last Post: QJZ
  How to move an object over time rather than instantly? temlotresid6 3 1,854 Oct-23-2024, 11:20 AM
Last Post: temlotresid6
  Is there a difference between Python’s time.sleep and win32api.Sleep? phpjunkie 4 1,185 Sep-21-2024, 05:17 PM
Last Post: aakritiintelligence
  How to insert text time - into video frames? oxidian 0 1,421 Aug-25-2024, 04:51 PM
Last Post: oxidian
  Using RTC time in Rasberry Pi Programs sab201 1 959 Aug-18-2024, 05:50 PM
Last Post: snippsat
  Having difficulty finding python.h on OS X catsonmars 2 936 Aug-11-2024, 06:18 AM
Last Post: Pedroski55
  Schedule exit a program at a specific time 4 am every day. chubbychub 3 1,565 May-17-2024, 03:45 PM
Last Post: chubbychub
  Filer and sort files by modification time in a directory tester_V 5 2,610 May-02-2024, 05:39 PM
Last Post: tester_V

Forum Jump:

User Panel Messages

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