Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleTaster einlesencollapsetrueSmoothing
/*
  Weighted Moving Point Average  
  Luke Franzke 
  ZHdK
  2019
*/
#define analogInPin A0  // our sensor input pin 
int weightedAverage = 0; // where we we stored our average values
void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
}

void loop() {
 // read the analog in value:
  int sensorValue = analogRead(analogInPin);
// calculate the weighted moving point average 
// our scaling factor should add up to 1, but this ratio can be adjusted depending on the amount of noise 
  weightedAverage = weightedAverage*0.7;
  weightedAverage += sensorValue*0.3;
  // print both results to the Serial Monitor:
  Serial.print("sensor: ");
  Serial.print(sensorValue);
  Serial.print(",");
  Serial.println(weightedAverage);
  delay(1);  // delay in between reads for stability
}

...