examples/heartbeat/heartbeat.py
def sample():
    """Function to thread heartbeat values separately to
 OLED drawing"""
    global bpm, bpm_avg, beat_detected, beat_status

    average_over = 5
    bpm_vals = [0 for x in range(average_over)]
    last_beat = time.time()

    while running:
        t = time.time()
        samples = max30105.get_samples()
        if samples is not None:
            for i in range(0, len(samples), 2):
                ir = samples[i + 1]
                beat_detected = hr.check_for_beat(ir)
                if beat_detected:
                    beat_status = True
                    delta = t - last_beat
                    last_beat = t
                    bpm = 60 / delta
                    bpm_vals = bpm_vals[1:] + [bpm]
                    bpm_avg = sum(bpm_vals) / average_over
                d = hr.low_pass_fir(ir & 0xff)
                data.append(d)
                if len(data) > 128:
                    data.pop(0)

        time.sleep(0.05)
Function to thread heartbeat values separately to
 OLED drawing
Function to thread heartbeat values separately to
OLED drawing
Function to thread heartbeat values separately to OLED drawing
def sample():
    global bpm, bpm_avg, beat_detected, beat_status
    average_over = 5
    bpm_vals = [0 for x in range(average_over)]
    last_beat = time.time()
    while running:
        t = time.time()
        samples = max30105.get_samples()
        if samples is not None:
            for i in range(0, len(samples), 2):
                ir = samples[i + 1]
                beat_detected = hr.check_for_beat(ir)
                if beat_detected:
                    beat_status = True
                    delta = t - last_beat
                    last_beat = t
                    bpm = 60 / delta
                    bpm_vals = bpm_vals[1:] + [bpm]
                    bpm_avg = sum(bpm_vals) / average_over
                d = hr.low_pass_fir(ir & 0xff)
                data.append(d)
                if len(data) > 128:
                    data.pop(0)
        time.sleep(0.05)
def sample ( ) : global bpm , bpm_avg , beat_detected , beat_status average_over = 5 bpm_vals = [ 0 for x in range ( average_over ) ] last_beat = time . time ( ) while running : t = time . time ( ) samples = max30105 . get_samples ( ) if samples is not None : for i in range ( 0 , len ( samples ) , 2 ) : ir = samples [ i + 1 ] beat_detected = hr . check_for_beat ( ir ) if beat_detected : beat_status = True delta = t - last_beat last_beat = t bpm = 60 / delta bpm_vals = bpm_vals [ 1 : ] + [ bpm ] bpm_avg = sum ( bpm_vals ) / average_over d = hr . low_pass_fir ( ir & 0xff ) data . append ( d ) if len ( data ) > 128 : data . pop ( 0 ) time . sleep ( 0.05 )
Function to thread heartbeat values separately to
OLED drawing
Function to thread heartbeat values separately to OLED drawing
"""Function to thread heartbeat values separately to
 OLED drawing"""