Skip to content

Instantly share code, notes, and snippets.

@TURBULENTE
Created June 29, 2016 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TURBULENTE/94fd5adcd9b548f2cecb43eb53346f73 to your computer and use it in GitHub Desktop.
Save TURBULENTE/94fd5adcd9b548f2cecb43eb53346f73 to your computer and use it in GitHub Desktop.
DATA_SMOOTH
//Bend/Pressure fabric sensor test and smoothing values
int sensorPin=A1;
int sensorValue=0;
int mapped;
//Smoothing values
const int numReadings = 10;
int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
// - - - - - - - - - - S E T U P - - - - - - - - - -
void setup() {
Serial.begin(9600);
//For reading smoothing values array
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
}
// - - - - - - - - - - L O O P - - - - - - - - - -
void loop() {
sensorValue=analogRead(sensorPin);
delay(150);
//smoothing process
// subtract the last reading:
total = total - readings[readIndex];
// read from the sensor:
/*readings[readIndex] = analogRead(inputPin);*/
readings[readIndex] = sensorValue;
// add the reading to the total:
total = total + readings[readIndex];
// advance to the next position in the array:
readIndex = readIndex + 1;
if (readIndex >= numReadings) {
readIndex = 0;
}
//average:
average = total / numReadings;
// send it to the computer as ASCII digits
/*Serial.println(("promedio")average);*/
/* Serial.println("promedio");*/
Serial.println(average);
delay(1); //
//WORKS PRETTY FINE!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment