From e448ba427cfd518a0e702a6990258be8d92b3a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20Degerf=C3=A4lt?= Date: Sat, 2 Mar 2019 11:56:44 +0100 Subject: [PATCH 1/2] Loop for calibration --- NuEVI/NuEVI.ino | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/NuEVI/NuEVI.ino b/NuEVI/NuEVI.ino index 33b506b..0066b97 100644 --- a/NuEVI/NuEVI.ino +++ b/NuEVI/NuEVI.ino @@ -493,25 +493,21 @@ void setup() { initDisplay(); //Start up display and show logo //auto-calibrate the vibrato threshold while showing splash screen - int cv1=touchRead(vibratoPin); - int bc1=analogRead(breathSensorPin); - digitalWrite(statusLedPin,HIGH); - delay(250); - int cv2=touchRead(vibratoPin); - int bc2=analogRead(breathSensorPin); - digitalWrite(statusLedPin,LOW); - delay(250); - int cv3=touchRead(vibratoPin); - int bc3=analogRead(breathSensorPin); - digitalWrite(statusLedPin,HIGH); - delay(250); - digitalWrite(statusLedPin,LOW); - int cv4=touchRead(vibratoPin); - int bc4=analogRead(breathSensorPin); - vibZero=(cv1+cv2+cv3+cv4)/4; - vibThr=vibZero-vibSquelch; - vibThrLo=vibZero+vibSquelch; - breathCalZero=(bc1+bc2+bc3+bc4)/4; + vibZero = breathCalZero = 0; + const int sampleCount = 4; + for(int i =0 ; i < sampleCount; ++i) { + vibZero += touchRead(vibratoPin); + breathCalZero += analogRead(breathSensorPin); + digitalWrite( statusLedPin, 1-(i&1) ); + delay(250); + } + vibZero /= sampleCount; + breathCalZero /= sampleCount; + + vibThr = vibZero - vibSquelch; + vibThrLo = vibZero + vibSquelch; + + digitalWrite(statusLedPin, LOW); delay(250); digitalWrite(statusLedPin,HIGH); delay(250); From 82b0f3a47c3f1a6983856a6af47d2db0e6087d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20Degerf=C3=A4lt?= Date: Mon, 4 Mar 2019 21:49:34 +0100 Subject: [PATCH 2/2] Calibration code cleanup --- NuEVI/NuEVI.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NuEVI/NuEVI.ino b/NuEVI/NuEVI.ino index 0066b97..050d649 100644 --- a/NuEVI/NuEVI.ino +++ b/NuEVI/NuEVI.ino @@ -495,10 +495,10 @@ void setup() { //auto-calibrate the vibrato threshold while showing splash screen vibZero = breathCalZero = 0; const int sampleCount = 4; - for(int i =0 ; i < sampleCount; ++i) { + for(int i = 1 ; i <= sampleCount; ++i) { vibZero += touchRead(vibratoPin); breathCalZero += analogRead(breathSensorPin); - digitalWrite( statusLedPin, 1-(i&1) ); + digitalWrite( statusLedPin, i&1 ); delay(250); } vibZero /= sampleCount;