Instant reading of one sensor whilst averaging another simultaneously

I'm trying to figure out a way if it is possible to have 2 different sensors displayed with one of them showing instant results and the second an average of results.

I have been using a "for loo"p for the averaging with an SHT75 sensor, putting the readings into an array etc. The problem is, is that the time taken to read the sensor 10 times is many many seconds which means that my other sensor which is a pressure sensor is not being polled..

Is there anyway to continuously display the pressure sensor reading and average the SHT75 in the background?

MAny thanks

ps I'm quite new to programming!

Poll your real time sensor and display both its result and the average result continuously, but use timer interrupt to trigger the other sensor and code that calculates the average only when needed (in intervals).

Why wait 10 times? You could read each sensor continuously. Display the current read only during the first 9 reads. After the 10th read, then start displaying the average along with the current. At the next read, throw out the first read thus leaving the last 10 values read. On each 'read', continue throwing out the earliest value read and adding the latest value read to the 10 'reads'. - Scotty

Thanks scotty.

Is there any sample code you have for the average readings, namely the rolling average. Is it a particular function which I haven't found yet?

Thanks

Peter

use blink without delay with few boolean statements...

ouh you could always use something like

if (Count <=10)
Something1=analogRead(A1);
Something2=analogRead(A2);
Total1=Something1+Total1;
Total2=Something2+Total2;
count++;
else
{
  Average1=Total1/Count;
  Average2=Total2/Count;
  Serial.println(Average1);
  Serial.println(Average2);
  Count=0;
}
a = b;
b = c;
c = d;
...
j = analogRead(sensor);
someDisplayFunctionOrOther ((a + b + c + ... + j) / 10);

partial code with 2 sensors using a running average (TODO add 2 functions to read the sensors)

int average;

void setup()
{
  Serial.begin(115200);
  average = readSensor2(); // initial value
}

void loop()
{
  int direct = readSensor1();
  int average = average*0.6 + readSensor2()*0.4;  // weighted running average;  60% old/40% new  other weights possible of course;

  Serial.print(direct);
  Serial.print("\t");
  Serial.println(average);
}

for 1 sensor both the last value an

int average;

void setup()
{
  Serial.begin(115200);
  average = readSensor2(); // initial value
}

void loop()
{
  int direct = readSensor1();
  average = average*0.6 + direct*0.4;

  Serial.print(direct);
  Serial.print("\t");
  Serial.println(average);
}

Thanks everybody. Will try a few of the suggestions and see which works out best for this sensor. As teh temperatures could fluctuate wildly (intentionally). I reckon the a=b etc option is best as it will clear the buffers out reasonably quickly when I take the probe from room temperature into a hot air duct. But the other principle may well be useful for another project I'm doing.

Thanks again.

As teh temperatures could fluctuate wildly (intentionally).

Really? Any real sensor is going to have some lag time between when the sensed condition changes and when the reported value changes. If you read frequently, you will not get wild fluctuations.

Unless you are using a torch and a bucket of ice water to heat and cool the sensor directly, wild temperature fluctuations are unlikely.