I’ve been trying to write a library for my project, and every time that I thought that I have fixed the issue, and see absolutely no difference between other working libraries and mine, beside the obvious, this error pops right back up! If anyone can help me I would be super thankful.
Here is my .cpp
#include <building_pressure.h> //Library's description file
#include <Wire.h> //Arduino's I2C wire library
#include <SFE_BMP180.h> //SparkFun's library for the BMP180 pressure sensor
SFE_BMP180 pressure;
Building::Building()
{
}
/*
Begin shifts all the variable values into the private variables
as well as begins the usb serial communications
*/
char Building::begin(int8_t NUMBER_OF_SENSORS, int8_t NUMBER_OF_LIGHTS)
{
SerialUSB.begin(115200);
NumberOfRelaysUsed = NUMBER_OF_LIGHTS;
NumberOfSensorsUsed = NUMBER_OF_SENSORS;
}
/*
Initializes the inputs and outputs on the board,
and it initializes the pressure sensors as well.
*/
void Building::InitPuts()
{
for (int8_t i = 0; i < NumberOfRelaysUsed; i++)
{
pinMode(light[i], OUTPUT);
digitalWrite(light[i], HIGH);
}
for (int8_t x = 0; x < NumberOfSensorsUsed; x++){
enableMuxPort(x); //Tell mux to connect to port X
if (pressure.begin()) SerialUSB.println("BMP180 init success");
else
{
// Oops, something went wrong, this is usually a connection problem,
// see the comments at the top of this sketch for the proper connections.
SerialUSB.println("BMP180 init fail\n\n");
while (1)// Pause forever and flash pin 13 rapidly
{
digitalWrite(13, !digitalRead(13));
delay(250);
}
}
disableMuxPort(x);
}
}
/* Can't figure out if this function will work or not so I'm leaving it incomplete for now.
Building::WaitMillis(int time)
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > interval)
{
}
}
*/
void Building::ToggleLights()
{
for (int8_t i = 0; i < NumberOfRelaysUsed; i++)
{
digitalWrite(light[i], !digitalRead(light[i]));
}
}
void Building::LightsOff()
{
for (int8_t i = 0; i < NumberOfRelaysUsed; i++)
{
digitalWrite(light[i], HIGH);
}
}
double Building::Average(double Diff)
{
total -= readings[readIndex];
// read from the differential:
readings[readIndex] = (int) Diff;
// add the reading to the total:
total += readings[readIndex];
// advance to the next position in the array:
readIndex++;
// if we're at the end of the array...
if (readIndex >= numReadings)
{
// ...wrap around to the beginning:
readIndex = 0;
}
// calculate the average:
AveDiff = (double)total / (double)numReadings;
// send it to the computer as ASCII digits
//Serial.println(AveDiff);
delay(1); // delay in between reads for stability
return AveDiff;
}
double ReadPressure(double &OutsidePres, double &InsidePres)
{
for (int8_t x = 0 ; x < NumberOfSensorsUsed; x++)
{
enableMuxPort(x);
status = pressure.startTemperature();
if (status != 0)
{
delay(status);
status = pressure.getTemperature(T);
if (status != 0)
{
status = pressure.startPressure(3);
if (status != 0)
{
delay(status);
status = pressure.getPressure(P, T);
if (status != 0)
{
if(x==0)
{
OutsidePres = P;
OutsidePres *= 100;
}
else if (x==1)
{
InsidePres = P;
InsidePres *= 100;
InsidePres -= 3350;
}
}
else SerialUSB.println("error retrieving pressure measurement\n");
}
else SerialUSB.println("error starting pressure measurement\n");
}
else SerialUSB.println("error retrieving temperature measurement\n");
}
else SerialUSB.println("error starting temperature measurement\n");
disableMuxPort(x);
}
}
double Building::PDiff(double outside, double inside)
{
double delta;
delta = inside - outside;
return delta;
}
bool Building::enableMuxPort(int8_t portNumber)
{
if(portNumber > 7) portNumber = 7;
//Read the current mux settings
Wire.requestFrom(MUX_ADDR, 1);
if(!Wire.available()) return(false); //Error
int8_t settings = Wire.read();
//Set the wanted bit to enable the port
settings |= (1 << portNumber);
Wire.beginTransmission(MUX_ADDR);
Wire.write(settings);
Wire.endTransmission();
return(true);
}
bool Building::disableMuxPort(int8_t portNumber)
{
if(portNumber > 7) portNumber = 7;
//Read the current mux settings
Wire.requestFrom(MUX_ADDR, 1);
if(!Wire.available()) return(false); //Error
int8_t settings = Wire.read();
//Clear the wanted bit to disable the port
settings &= ~(1 << portNumber);
Wire.beginTransmission(MUX_ADDR);
Wire.write(settings);
Wire.endTransmission();
return(true);
}
and here is the .h for it
#ifndef building_pressure_h
#define building_pressure_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#define MUX_ADDR 0x70
#define ALTITUDE 205.13 // Altitude in meters
class Building
{
public:
Building();
char begin(int8_t NUMBER_OF_SENSORS, int8_t NUMBER_OF_LIGHTS);
void InitPuts(); //Initializes the pins for inputs and outputs
//boolean WaitMillis(int time);
void ToggleLights();
void LightsOff();
double Average(double Diff);
double ReadPressure(double &OutsidePres, double &InsidePres); //Reads the pressure off of the sensor and returns the value
//char displayPressure(void);
double PDiff(double outside, double inside);
const double MaxDeltaP = 12.442; //Constant Value for maximum difference in pressure
private:
bool enableMuxPort(int8_t portNumber);
bool disableMuxPort(int8_t portNumber);
int8_t NumberOfSensorsUsed;
int8_t NumberOfRelaysUsed;
char status;
double T,P,OutsidePressure,InsidePressure,DeltaP,DeltaPAve;
/*----------Averaging---------*/
int numReadings = 25;
double AveDiff = 0; //This smooths the readings so that it the alarm doesn't trigger every two seconds from noise
double readings[25]; // the readings from the Pressure sensors
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
/*----------------------------*/
int8_t light[8] = {13, 12, 11, 10, 9, 8, 7, 6};
//int PDiff(double outside, double inside);
};
#endif