Ciao Pitusso, ho applicato il range del valore AVERAGE dello sketch smoothing, però non vedo nessuna differenza da prima...
dove sto sbagliando ??
grazie
sketch smoothing con modifica:
const int numReadings = 10;
int ledPin = 9;
int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0;
int outPut = 0;// the average
int inputPin = 0;
void setup()
{
// initialize serial communication with computer:
Serial.begin(9600);
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;
}
void loop() {
// subtract the last reading:
total= total - readings[index];
// read from the sensor:
readings[index] = analogRead(inputPin);
// add the reading to the total:
total= total + readings[index];
// advance to the next position in the array:
index = index + 1;
// if we're at the end of the array...
if (index >= numReadings)
// ...wrap around to the beginning:
index = 0;
// calculate the average:
average = total / numReadings;
// send it to the computer as ASCII digits
outPut = map(average, 70, 900, 0, 255);
if (outPut<5)
analogWrite(ledPin, 0);
else
analogWrite(ledPin, outPut);
Serial.println(average);
delay(0); // delay in between reads for stability
}