Hello All,
I need some help grasping with the concept/example "several things happening at same time". Let's say I have multiple functions being called inside void loop(), one of the functions, is taking a temperature reading every 30 seconds. Because I am using the Nano ESP32, the ADC sucks and so I am using a digital smoothing filter (averaged out over 8 to 16 readings)...From my testing, it looks like the processor/MCU is only spending micro/milli seconds in that function and only passing through that function 1 once every 30 seconds.
And so therefore, the smoothing digital filter will take very long to gather enough readings to "average" out the noise properly.. And kind of useless? I should be taking readings as often/fast as possible instead of every 30seconds? Am i correct in this assumption?
OR
When a function is called... the processor passes hundred of thousands/millions of times through the function when its called every 30 seconds? and so the averaging/smoothing will work. I'm struggling with processor speed and what that means I think?? LOL, i'm sorry
int LED = 13;
int tempProbe = A0;
unsigned long lastPass = 0;
unsigned long startTemp = 0;
unsigned long elapsedTemp = 0;
unsigned int counterTemp = 0;
int reading;
unsigned int filteredReading;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, Nano ESP32!");
pinMode(LED, OUTPUT);
pinMode(tempProbe, INPUT);
}
void loop() {
ledFlash();
if (millis() - lastPass >= 30000) {
tempReading();
lastPass = millis();
}
}
void tempReading() {
startTemp = micros();
reading = analogRead(tempProbe);
reading = analogRead(tempProbe);
filteredReading = ( filteredReading*15 + reading)/16;
counterTemp ++;
elapsedTemp = micros() - startTemp;
Serial.println(filteredReading);
Serial.println(elapsedTemp);
Serial.println(counterTemp);
}
void ledFlash() {
digitalWrite(LED, !digitalRead(LED));
delay(1000);
}
This code is just a simple example i put together for my testing and curiosity.
Thanks