From ea9aa04022e0e8aed3abb769a3e47d96c443f2b7 Mon Sep 17 00:00:00 2001 From: Thomas Schmid Date: Sun, 19 Jun 2022 12:28:09 +0200 Subject: [PATCH] beat_detect: use get_sample() Signed-off-by: Thomas Schmid --- firmware/src/beat_detect.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/firmware/src/beat_detect.cpp b/firmware/src/beat_detect.cpp index 48f1f35..97f15c2 100644 --- a/firmware/src/beat_detect.cpp +++ b/firmware/src/beat_detect.cpp @@ -35,8 +35,6 @@ static float angle2; static float pos_target = NUM_LEDS / 2; static float pos_target_filtered = NUM_LEDS / 2; - -static float microphone_offset = 1900; static long initial_time; static int active = 15; @@ -85,17 +83,13 @@ void setup() } void loop() { - - int sample = int(analogRead(MIC_PIN) - microphone_offset); - energy += abs(sample) * abs(sample); + float sample = get_sample(); + energy += std::abs(sample) * std::abs(sample); n_samples++; if (micros() - last_us_bp > sampling_period_bp) { - Serial.println(n_samples); n_samples = 0; - - microphone_offset += (analogRead(MIC_PIN) - microphone_offset) * 0.001; last_us_bp += sampling_period_bp; //energy_fil += (energy - energy_fil) * 0.01;