Hi!
I need some help to "translate" a filtered value (Exponential Filter) to a float or double (?) so I can proceed to use the value in an equation. Please see attached code.
I want to be able to use 'cltFilter' value inside the thermistor formula as 'clt' but the IDE won't let me
Also, I want to use oilpressFilter and voltFilter in the float conversion (mapping) equations.
How can I achieve this? Doesn't seem too hard to me, but I don't know where to find the info.
Sketch attached here:
#include "MegunoLink.h"
#include "Filter.h"
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display;Â Â Â // This display increases memory use from 17% - 72%.
// Create a new exponential filter with a weight of 30 and initial value of 0.
ExponentialFilter<long> cltFilter(30, 0);
ExponentialFilter<long> oilpressFilter(30, 0);
ExponentialFilter<long> voltFilter(30, 0);
int oilpressValue = 0;Â Â Â // value read from the oil press sender
int battvoltValue = 0;Â Â Â // value read from batt volt input
int oildispValue = 0;   // calculated output value for oil pressure
int voltdispValue = 0;Â Â Â // calculated output value for battery voltmeter
int clt = 0;
void setup()
{
 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x64)
 display.clearDisplay();
 // Startup splash screen
 display.setTextColor(WHITE);
 display.setTextSize(2); display.setCursor(5, 10); display.print(F("Meisal"));
 display.setTextSize(4); display.setCursor(79, 10); display.print(F("RX"));
 display.display(); delay(1000);
 display.setTextSize(1); display.setCursor(2,55); display.print(F("Display by Tharaldsen"));
 display.display(); delay(1000); display.clearDisplay();
Â
}
void loop()
{
 // filter each input value
 int cltraw = analogRead(0);         // CLT input at A0
 cltFilter.Filter(cltraw);          // Namining filtered CLT input 'cltFilter'
 int oilpressraw = analogRead(1);       // Oil Press input at A1
 oilpressFilter.Filter(oilpressraw);     // Naming filtered Oil Press 'oilpressFilter'
 int voltraw = analogRead(2);         // Voltmeter input at A2
 voltFilter.Filter(voltraw);         // Naming filtered volt input 'voltFilter'
 float oildispValue = oilpressValue * (8.61 / 1023.0) -0.86;
 float voltdispValue = battvoltValue * (15.0 / 1023.0);
 // Calculates Water temp displayed value
 int Vo;
 int R1 = 1100;
 float logR2, R2, T, cltdispValue, Tf;
 float c1 = 1.308061745e-03, c2 = 2.576124537e-04, c3 = 1.777597735e-07;
 Vo = clt;
 R2 = R1 * (1023.0 / (float)Vo - 1.0);
 logR2 = log(R2);
 T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
 cltdispValue = T - 273.15;
// Analog display values sends to OLED:
display.clearDisplay();
display.setTextWrap(false);Â Â Â Â // to avoid the decimals to continue on next line
display.setTextColor(WHITE);
 display.setTextSize(1); display.setCursor(1, 5); display.print(F("Water Temp:")); display.setTextSize(2); if (cltdispValue < 100) {display.setCursor(104, 5);} else {display.setCursor(92, 5);} display.print(cltdispValue, 0);
 display.setTextSize(1); display.setCursor(1, 25); display.print(F("Oil Press.:")); display.setTextSize(2);                               display.setCursor(92, 25); display.print(oildispValue, 1);
 display.setTextSize(1); display.setCursor(1, 45); display.print(F("Batt. Volt:")); display.setTextSize(2); if (voltdispValue < 10) {display.setCursor(92, 45);} else {display.setCursor(80, 45);} display.print(voltdispValue, 1);
display.display();
delay(100);
}