def euclidean_distance(reference, measured):
    """Calculate the Euclidean distance between reference and measured points
    in a universe. The point position tuples can be colors, compass,
    accelerometer, absolute position, or almost any other multiple value data
    set.
    reference: A tuple or list of reference point position values.
    measured: A tuple or list of measured point position values."""

    # Create list of deltas using list comprehension
    deltas = [(reference[idx] - count) for idx, count in enumerate(measured)]
    # Resolve squared deltas to a Euclidean difference and return the result
    return math.sqrt(sum([d ** 2 for d in deltas]))

# Set the BNo055 tap detector parameters and initialize tap event history list
TAP_THRESHOLD = 6  # Tap sensitivity threshold; depends on the physical sensor mount
TAP_DEBOUNCE = 0.1  # Time for accelerometer to settle after tap (seconds)
TAP_TIMEOUT = 1500  # Remove tap event from history timeout (milliseconds)
tap_events = []  # Initialize the tap event history list

# The project's main while looop
while True:
    # Detect a tap on any axis of the BNo055 accelerometer
    accel_sample_1 = sensor.acceleration  # Read one sample
    accel_sample_2 = sensor.acceleration  # Read the next sample
    if euclidean_distance(accel_sample_1, accel_sample_2) >= TAP_THRESHOLD:
        # The difference between two consecutive samples exceeded the threshold
        # (equivalent to a high-pass filter)
        print(f"SINGLE tap detected {ticks_ms()}")
        tap_events.append(ticks_ms() + TAP_TIMEOUT)  # save tap expiration time in event stack
        time.sleep(TAP_DEBOUNCE)  # Debounce delay

    # Clean up tap event history after timeout period expires
    if len(tap_events) > 0:
        # Check for expired events
        if tap_events[0] <= ticks_ms():
            # The oldest event has expired
            tap_events = tap_events[1:]  # Remove the oldest event

    # Check see if two taps are in the event history list
    if len(tap_events) == 2:
        # Double-tap: execute the task and clear event history
        print(f"DOUBLE tap detected {ticks_ms()}")
        # 
        # Perform the double-tap task here
        # 
        tap_events = []  # Clear event history