here is my sketch but the problem isnt in my sketch its in the TIME library.
// Pressure Sensor - Out of Bounds Technology
// ***************************************
#include "CommandHandler.h"
#include <TimeLib.h>
#include "MegunoLink.h"
#include <Wire.h>
#include <SparkFun_MS5803_I2C.h> // Click here to get the library: http://librarymanager/All#SparkFun_MS5803-14BA
XYPlot Myplot;
MS5803 sensor(ADDRESS_HIGH);
InterfacePanel MyPanel;
CommandHandler<> SerialCommandHandler;
// ***** USER CONROLLED VARIABLES ******
double Pressure_Bias = 1.03; // CHANGE THIS TO CALIBRATE THE PRESSURE SENSOR
double tplBIAS = .35; // Adjust this variable for leek detection sensitvity,(difference peek / max loss)
//***** SYSTEM VARIABLES *****
double PEEK_PRESSURE = 0;
double Pressure_Loss;
double Start_Pressure;
double stability_timer;
double temp_F, temp_c, Base_Pressure;
double pressure_abs = 0;
double pressure_psi = 0;
double Pressure_Average[3];
double timer = 0;
double avg_bar = 0;
double SET_TIMER = 30;
double Set_Time;
double tpLOSS = 0;
double stableDIFF = 0;
double TOTALDIFF = 0;
int start = 0;
int y = 0;
int x = 0;
int Y1 = 1;
int Y2 = 7;
void setup() {
// Start your preferred I2C object
Wire.begin();
//Initialize Serial Monitor
Serial.begin(9600);
//Retrieve calibration constants for conversion math.
sensor.reset();
sensor.begin();
READ_SETUP_PRESSURE();
SETUP_XYPLOT();
SETUP_DISPLAY();
}
void loop() {
SerialCommandHandler.Process();
READ_PRESSURE();
tpLOSS = (PEEK_PRESSURE - avg_bar);
// +++++++++++++UPDATED DISPLAY READINGS ++++++++++
Myplot.SendData("BAR", timer, avg_bar); // Display the graph
MyPanel.SetText(F("DynamicLabel11"), timer);
MyPanel.SetText(F("DynamicLabel2"), avg_bar); // Display BAR pressure
MyPanel.SetText(F("DynamicLabel4"), pressure_psi); // Display PSI pressure
MyPanel.SetText(F("DynamicLabel5"), temp_c);
MyPanel.SetText(F("DynamicLabel6"), temp_F);
MyPanel.SetText(F("DynamicLabel12"), tpLOSS );
if (x == 1){
TOTALDIFF = (tpLOSS - stableDIFF);
MyPanel.SetText(F("DynamicLabel15"), TOTALDIFF);
if (TOTALDIFF <= .03){
MyPanel.SetBackColor(F("DynamicLabel15"), F("Green"));
}
if (TOTALDIFF > .03){
MyPanel.SetBackColor(F("DynamicLabel15"), F("Orange"));
}
if (TOTALDIFF > .04){
MyPanel.SetBackColor(F("DynamicLabel15"), F("Red"));
}
}
// +++++++ Is there pressure ? ++++++++
if (avg_bar > 1)
{
if (start == 0){
setTime(0,0,0,0,0,0);
start = 1;
}
timer = (minute() + (second()*.01)); // start timer
// Is pressure rising? ++++++++++++++
if ((Pressure_Average[0] + .0005) < Pressure_Average[2])
{
MyPanel.SetBackColor(F("DynamicLabel7"), F("Orange"));
MyPanel.SetBackColor(F("DynamicLabel2"), F("Orange"));
MyPanel.SetBackColor(F("DynamicLabel4"), F("Orange"));
MyPanel.SetText(F("DynamicLabel7"), "PRESSURIZING");
}
// Is pressure stable? ++++++++++++++
if (Pressure_Average[0] == Pressure_Average[2])
{
MyPanel.SetBackColor(F("DynamicLabel7"), F("Green"));
MyPanel.SetText(F("DynamicLabel7"), "---PRESSURE STABLE---");
MyPanel.SetBackColor(F("DynamicLabel2"), F("Green")); //
MyPanel.SetBackColor(F("DynamicLabel4"), F("Green"));
stability_timer++;
if (x == 0){
if (stability_timer > .50)
{
Set_Time = timer;
Base_Pressure = ((sensor.getPressure(ADC_4096)*.001)- Pressure_Bias); // take pressure reading if stable for comparrison.
MyPanel.SetText(F("DynamicLabel9"), Base_Pressure);
stableDIFF = (PEEK_PRESSURE - Base_Pressure);
MyPanel.SetText(F("DynamicLabel10"),stableDIFF);
MyPanel.SetBackColor(F("DynamicLabel13"), F("Green"));
MyPanel.SetText(F("DynamicLabel13"),"TESTING..." );
x = 1;
}
}
}
// Is pressure going down? ++++++++++++++
if ((Pressure_Average[0]- .0005) > Pressure_Average[2])
{
if (y == 0)
{
PEEK_PRESSURE = ((sensor.getPressure(ADC_4096)*.001)- Pressure_Bias);
MyPanel.SetText(F("DynamicLabel14"),PEEK_PRESSURE);
y = 1;
}
if (timer < 1)
{
MyPanel.SetBackColor(F("DynamicLabel2"), F("yellow"));
MyPanel.SetBackColor(F("DynamicLabel4"), F("Yellow"));
MyPanel.SetBackColor(F("DynamicLabel7"), F("Yellow"));
MyPanel.SetText(F("DynamicLabel7"), "PRESSURE STABILIZING");
}
else
{
MyPanel.SetBackColor(F("DynamicLabel2"), F("Red"));
MyPanel.SetBackColor(F("DynamicLabel4"), F("Red"));
MyPanel.SetBackColor(F("DynamicLabel7"), F("Red"));
MyPanel.SetText(F("DynamicLabel7"), "PRESSURE DROPPING");
}
}
if (x == 2)
{
MyPanel.SetText(F("DynamicLabel12"), (Base_Pressure - avg_bar));
}
// ++++++++++++++++++ IS THERE A LEAK? ++++++++++++++++
if (stableDIFF > 0)
{
if (TOTALDIFF > .04)
{
MyPanel.SetBackColor(F("DynamicLabel8"), F("RED"));
MyPanel.SetText(F("DynamicLabel8"), "LEAK DETECTED");
MyPanel.SetBackColor(F("DynamicLabel13"), F("Red"));
MyPanel.SetText(F("DynamicLabel13"),"TESTING FAILED" );
}
}
}
}
// +++++++++++++++++++++++ FUNCTIONS +++++++++++++++++++++
void SETUP_DISPLAY()
{
MyPanel.SetBackColor(F("DynamicLabel5"), F("Control"));
// MyPanel.SetText(F("DynamicLabel7"), "");
MyPanel.SetBackColor(F("DynamicLabel7"), F("White"));
MyPanel.SetText(F("DynamicLabel7"), "");
MyPanel.SetBackColor(F("DynamicLabel8"), F("White"));
MyPanel.SetText(F("DynamicLabel8"), "");
MyPanel.SetBackColor(F("DynamicLabel2"), F("White"));
MyPanel.SetText(F("DynamicLabel12"), 0.00);
MyPanel.SetBackColor(F("DynamicLabel4"), F("White"));
MyPanel.SetText(F("DynamicLabel9"), 0.00);
MyPanel.SetText(F("DynamicLabel10"),0.00);
MyPanel.SetBackColor(F("DynamicLabel11"), F("Control"));
MyPanel.SetText(F("DynamicLabel11"), "");
MyPanel.SetBackColor(F("DynamicLabel13"), F("Cyan"));
MyPanel.SetText(F("DynamicLabel13"),"WAITING" );
MyPanel.SetText(F("DynamicLabel14"),PEEK_PRESSURE);
MyPanel.SetText(F("DynamicLabel12"), 0.00);
MyPanel.SetBackColor(F("DynamicLabel15"), F("Control"));
MyPanel.SetText(F("DynamicLabel15"), 0.00);
}
void SETUP_XYPLOT()
{
Myplot.Clear("BAR");
Myplot.SetTitle("P-TESTER - V2");
Myplot.SetXLabel("MINUTES");
Myplot.SetYLabel("BAR");
Myplot.SetSeriesProperties("BAR", Plot::Red, Plot::Solid, 2,Plot::NoMarker);
Myplot.SetYRange(Y1,Y2);
Myplot.SetY2Label("BAR");
Myplot.SetXRange(0,SET_TIMER);
}
double READ_PRESSURE()
{
// ++++++++++++PUT READINGS INTO AN ARRAY+++++++++++
for (byte i = 0; i < 3; i++)
{
Pressure_Average[i] = ((sensor.getPressure(ADC_4096)*.001) - Pressure_Bias);
if (Pressure_Average[i] <= 0 )
{
Pressure_Average[i] = 0;
}
delay(300);
}
// +++++++ Average the Pressure Readings ++++++++++++
avg_bar = ((Pressure_Average[0] + Pressure_Average[1] + Pressure_Average[2])/3);
// +++++++ Convert to PSI ++++++++++++
pressure_psi = (avg_bar * 14.5038);
// +++++++ GET TEMP READINGS ++++++++++++
temp_c = sensor.getTemperature(CELSIUS, ADC_512);
temp_F = sensor.getTemperature(FAHRENHEIT, ADC_512);
}
double READ_SETUP_PRESSURE()
{
Start_Pressure = ((sensor.getPressure(ADC_4096)*.001) - Pressure_Bias);
}