iv built an adjustable altimeter (thanks to those who helped with some code issues)
its working great but the altitude jumps around quite a bit so id like to smooth it out a bit.
Id prefer rounding this function
"float Af = Am * 3.28084 + 40;" so the altitude is closest 5 feet.
but I guess smoothing out the "event.pressure" reading from the BMP-180 sensor itself could work and make the altimeter more accurate but I couldnt figure out how to do that with sensor data coming in on I2C. 1 foot accuracy would be nice but 5' would be plenty as this will be used for experimental aviation.
What is the most simple way to do this with keeping the sketch size and variable use to a minimum as i want to have this on a pro mini with lcd and Attiny85 sending data via BT to an android app.
Currently Sketch uses 14150 bytes, Global variables use 1119 bytes
and could you please show me where in my code to put it and how to write it as i have had issues in the past transposing code without causing issues in my sketch.
heres the full code
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
#include <ClickEncoder.h>
#include <TimerOne.h>
#include <LCD5110_Graph.h>
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
LCD5110 lcd(8, 9, 10, 12, 11);
extern unsigned char SmallFont[];
extern unsigned char TinyFont[];
ClickEncoder *encoder;
int16_t last, value = 11968;
void timerIsr()
{
encoder->service();
}
void setup(void)
{
encoder = new ClickEncoder(A1, A0, A2);
Timer1.initialize(1000);
Timer1.attachInterrupt(timerIsr);
last = -1;
Serial.begin(9600);
if (!bmp.begin())
{
Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
while (1);
}
lcd.InitLCD();
lcd.setFont(SmallFont);
lcd.print("ALTIMETER", CENTER, 2);
lcd.print("PROTOTYPE", CENTER, 12);
lcd.update();
delay(2000);
}
void loop(void)
{
float q = value / 4 * 0.01;
value += encoder->getValue();
sensors_event_t event;
bmp.getEvent(&event);
if (event.pressure)
{
Serial.print(event.pressure);
Serial.println(" hPa");
float temperature;
bmp.getTemperature(&temperature);
float seaLevelPressure = (q * 33.8638870320855);
float Am = (bmp.pressureToAltitude(seaLevelPressure, event.pressure));
float Af = Am * 3.28084 + 40;
lcd.clrScr();
char qnh[6];
char Alt[6];
dtostrf(q, 3, 2, qnh);
dtostrf(Af, 3, 0, Alt);
lcd.print(Alt, RIGHT, 13);
lcd.print(qnh, LEFT, 13);
lcd.update();
}
}