I've tried to build a library (file.cpp + file.h) to Arduino but I got this error:
In file included from EXAMPLE_MPL3115A2.ino:2: /Applications/Arduino.app/Contents/Resources/Java/libraries/MPL3115A2/MPL3115A2.h:8: error: ISO C++ forbids declaration of 'getPressure' with no type EXAMPLE_MPL3115A2.ino: In function 'void loop()': EXAMPLE_MPL3115A2:18: error: expected unqualified-id before '.' token
Can you explain me where is the error?? (I don't know very well C++)
Here are my MPL3115A2.h
#ifndef MPL3115A2_h
#define MPL3115A2_h
#include "Arduino.h"
class MPL3115A2{
public:
getPressure();
private:
int m_i2c_address;
byte _p_msb, _p_csb, _plsb;
byte _tempp, _tempa, _tempt, _decimalPress, _decimalAlt, _decimalTemp;
unsigned long _ptot;
};
#endif
my MPL3115A2.cpp
#include "Arduino.h"
#include "MPL3115A2.h"
#include "I2C.h"
MPL3115A2::MPL3115A2()
{
m_i2c_address = 0x60;
p_msb = _p_msb;
p_csb = _p_csb;
p_lsb = _p_lsb;
tempp = _tempp;
tempa = _tempa;
tempt = _tempt;
decimalPress = _decimalPress;
decimalAlt = _decimalAlt;
decimalTemp = _decimalTemp;
ptot = _ptot;
}
float MPL3115A2::getPressure()
{
I2c.write(m_i2c_address,0x26,0x00);
I2c.write(m_i2c_address,0x26,0x01);
delay(100);
I2c.read(m_i2c_address,0x1,3);
I2c.end();
while(I2c.available()){
p_msb=I2c.receive();
p_csb=I2c.receive();
p_lsb=I2c.receive();}
ptot=p_msb;
ptot=(ptot<<8)+p_csb;
ptot=(ptot<<2)+(p_lsb>>6);
tempp=(p_lsb<<2);
if(tempp==192){
decimalPress=75;
}else if(tempp==128){
decimalPress=25;
}else if(tempp==64){
decimalPress=5;
}else{tempp=0;}
Serial.print(ptot);
Serial.print(".");
Serial.println(decimalPress);
}
#endif
and my example.pde
#include <Arduino.h>
#include <MPL3115A2.h>
#include <I2C.h>
void setup(){
Serial.begin(9600);
I2c.begin();
}
//LOOP
void loop(){
Serial.print("Pressure is: ");
MPL3115A2.getPressure(); //Expressed in Pa
Serial.print("Altimetry is: ");
//MPL3115A2.getAltimetry(); //Expressed in m
Serial.print("Temperature is: ");
// MPL3115A2.getTemperature(); //Expressed in C
delay(2000);
}
Sorry for the long post! Thank you all for your help!