sonar.ino 850 Bytes
#include "sonar.h"

void setup_sonar() {
  /* pinMode(1, FUNCTION_3); */
  /* pinMode(3, FUNCTION_3); */
  /* bmp.begin(); */
}

void loop_sonar(int counter) {
  liquidLevel = liquid_level();
  measurements[counter % 5] = liquidLevel;
}

double liquid_level() {
  /* temperature = bmp.readTemperature(); */
  /* V (m/s) = 331.3 + (0.606 × T) */
  /* double speedOfSound = 331.3 + ( 0.606 * temperature ); */
  double speedOfSound = 331.3 + ( 0.606 * 20 );

  double liquidLevel =
    containerBase
    - ((
        dubugLiquid /* sonar.ping_median(5) */
        * speedOfSound
        / 2 )
       / 1000
       );
  return liquidLevel;
}

double liquid_level_avg() {
  int liquidLevelAvg =
    ( measurements[0]
      + measurements[1]
      + measurements[2]
      + measurements[3]
      + measurements[4]
      ) / 5;
  return liquidLevelAvg;
}