mirror of
https://github.com/miguel5612/MQSensorsLib.git
synced 2025-03-15 05:17:30 +03:00
Implemented fctns
This commit is contained in:
parent
8ea9600d3c
commit
081f57beca
BIN
.vscode/ipch/3cd6c8ea04e31405/NONISO.ipch
vendored
Normal file
BIN
.vscode/ipch/3cd6c8ea04e31405/NONISO.ipch
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/3cd6c8ea04e31405/mmap_address.bin
vendored
Normal file
BIN
.vscode/ipch/3cd6c8ea04e31405/mmap_address.bin
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/5850c245ea8d5616/mmap_address.bin
vendored
Normal file
BIN
.vscode/ipch/5850c245ea8d5616/mmap_address.bin
vendored
Normal file
Binary file not shown.
@ -97,70 +97,21 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
|
||||
//Defaults index
|
||||
if(nameLectureRequeired == "")
|
||||
{
|
||||
Serial.println("Busqueda manual de los indices");
|
||||
if(_type == 2)
|
||||
{
|
||||
_lecturePosInArray = defaultMQ2;
|
||||
}
|
||||
else if(_type == 3)
|
||||
{
|
||||
_lecturePosInArray = defaultMQ3;
|
||||
}
|
||||
else if(_type == 4)
|
||||
{
|
||||
_lecturePosInArray = defaultMQ4;
|
||||
}
|
||||
else if(_type == 5)
|
||||
{
|
||||
_lecturePosInArray = defaultMQ5;
|
||||
}
|
||||
else if(_type == 6)
|
||||
{
|
||||
_lecturePosInArray = defaultMQ6;
|
||||
}
|
||||
else if(_type == 7)
|
||||
{
|
||||
_lecturePosInArray = defaultMQ7;
|
||||
}
|
||||
else if(_type == 8)
|
||||
{
|
||||
_lecturePosInArray = defaultMQ8;
|
||||
}
|
||||
else if(_type == 9)
|
||||
{
|
||||
_lecturePosInArray = defaultMQ9;
|
||||
}
|
||||
else if(_type == 131)
|
||||
{
|
||||
_lecturePosInArray = defaultMQ131;
|
||||
}
|
||||
else if(_type == 135)
|
||||
{
|
||||
_lecturePosInArray = defaultMQ135;
|
||||
}
|
||||
else if(_type == 303)
|
||||
{
|
||||
_lecturePosInArray = defaultMQ303;
|
||||
}
|
||||
else if(_type == 309)
|
||||
{
|
||||
_lecturePosInArray = defaultMQ309;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
|
||||
//Dinamic index search
|
||||
if(print)
|
||||
{
|
||||
//Dinamic index search
|
||||
if(print)
|
||||
{
|
||||
Serial.println("Busqueda dinamica de los indices");
|
||||
}
|
||||
for (int i=0; i<lecturesAvailable; i++) {
|
||||
if (nameLectureRequeired = nameLecture[i]) { //modified here
|
||||
_lecturePosInArray = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Serial.println("Busqueda dinamica de los indices");
|
||||
}
|
||||
for (int i=0; i<sizeof(_MQ); i++) {
|
||||
if (nameLectureRequeired = _MQ[i]) { //modified here
|
||||
_lecturePosInArray = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Serial debugging
|
||||
if(print)
|
||||
{
|
||||
@ -169,12 +120,12 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
|
||||
Serial.print("index in nameLectures: ");
|
||||
Serial.println(_lecturePosInArray);
|
||||
Serial.print("Slope index: ");
|
||||
Serial.println(indexSlopeLectures[_lecturePosInArray]);
|
||||
Serial.println(_lecturePosInArray+1);
|
||||
Serial.print("B point index: ");
|
||||
Serial.println(indexBPointLectures[_lecturePosInArray]);
|
||||
Serial.println(_lecturePosInArray+2);
|
||||
}
|
||||
_m = _MQ[indexSlopeLectures[_lecturePosInArray]];
|
||||
_b = _MQ[indexBPointLectures[_lecturePosInArray]];
|
||||
_m = stringToDouble(_MQ[_lecturePosInArray+1]);
|
||||
_b = stringToDouble(_MQ[_lecturePosInArray+2]);
|
||||
}
|
||||
int MQUnifiedsensor::readPPM(int m, int b) {
|
||||
/**
|
||||
@ -215,4 +166,60 @@ double MQUnifiedsensor::getVoltage() {
|
||||
}
|
||||
void MQUnifiedsensor::setR0(double R0) {
|
||||
this->_R0 = R0;
|
||||
}
|
||||
void MQUnifiedsensor::setDefaultGas()
|
||||
{
|
||||
Serial.println("Carga de los gases por defecto");
|
||||
if(_type == 2)
|
||||
{
|
||||
nameLectureRequeired = defaultMQ2;
|
||||
}
|
||||
else if(_type == 3)
|
||||
{
|
||||
nameLectureRequeired = defaultMQ3;
|
||||
}
|
||||
else if(_type == 4)
|
||||
{
|
||||
nameLectureRequeired = defaultMQ4;
|
||||
}
|
||||
else if(_type == 5)
|
||||
{
|
||||
nameLectureRequeired = defaultMQ5;
|
||||
}
|
||||
else if(_type == 6)
|
||||
{
|
||||
nameLectureRequeired = defaultMQ6;
|
||||
}
|
||||
else if(_type == 7)
|
||||
{
|
||||
nameLectureRequeired = defaultMQ7;
|
||||
}
|
||||
else if(_type == 8)
|
||||
{
|
||||
nameLectureRequeired = defaultMQ8;
|
||||
}
|
||||
else if(_type == 9)
|
||||
{
|
||||
nameLectureRequeired = defaultMQ9;
|
||||
}
|
||||
else if(_type == 131)
|
||||
{
|
||||
nameLectureRequeired = defaultMQ131;
|
||||
}
|
||||
else if(_type == 135)
|
||||
{
|
||||
nameLectureRequeired = defaultMQ135;
|
||||
}
|
||||
else if(_type == 303)
|
||||
{
|
||||
nameLectureRequeired = defaultMQ303;
|
||||
}
|
||||
else if(_type == 309)
|
||||
{
|
||||
nameLectureRequeired = defaultMQ309;
|
||||
}
|
||||
}
|
||||
double MQUnifiedsensor::stringToDouble(String & str) <-- notice the "&"
|
||||
{
|
||||
return atof( str.c_str() );
|
||||
}
|
@ -8,18 +8,18 @@
|
||||
#define lecturesAvailable 19
|
||||
|
||||
//Index in the nameLecture vector
|
||||
#define defaultMQ2 2 // LPG
|
||||
#define defaultMQ3 5 // Alcohol
|
||||
#define defaultMQ4 3 // CH4
|
||||
#define defaultMQ5 0 //H2
|
||||
#define defaultMQ6 3 // CH4
|
||||
#define defaultMQ7 4 //CO
|
||||
#define defaultMQ8 0 //H2
|
||||
#define defaultMQ9 2 // LPG
|
||||
#define defaultMQ131 12 //O3
|
||||
#define defaultMQ135 15 //NH4
|
||||
#define defaultMQ303 17 //Isobutano
|
||||
#define defaultMQ309 4 //CO
|
||||
#define defaultMQ2 "LPG" // LPG
|
||||
#define defaultMQ3 "Alcohol" // Alcohol
|
||||
#define defaultMQ4 "CH4" // CH4
|
||||
#define defaultMQ5 "H2" //H2
|
||||
#define defaultMQ6 "CH4" // CH4
|
||||
#define defaultMQ7 "CO" //CO
|
||||
#define defaultMQ8 "H2" //H2
|
||||
#define defaultMQ9 "LPG" // LPG
|
||||
#define defaultMQ131 "O3" //O3
|
||||
#define defaultMQ135 "NH4" //NH4
|
||||
#define defaultMQ303 "Isobutano" //Isobutano
|
||||
#define defaultMQ309 "CO" //CO
|
||||
|
||||
|
||||
class MQUnifiedsensor
|
||||
@ -29,12 +29,14 @@ class MQUnifiedsensor
|
||||
void inicializar();
|
||||
void setR0(double R0);
|
||||
void setSensorCharacteristics(String nameLectureReqeuired, bool print);
|
||||
void setDefaultGas();
|
||||
|
||||
int readSensor(String nameLectureRequeired = "", bool print = false);
|
||||
int readPPM(int m, int b);
|
||||
|
||||
double calibrate();
|
||||
double getVoltage();
|
||||
double stringToDouble(String & str);
|
||||
|
||||
String getnameLecture();
|
||||
|
||||
@ -56,7 +58,8 @@ class MQUnifiedsensor
|
||||
|
||||
private:
|
||||
int _pin, _type, _PPM, _lecturePosInArray;
|
||||
double _R0, _m, _b, _MQ[12];
|
||||
double _R0, _m, _b;
|
||||
String _MQ[19];
|
||||
const float VOLT_RESOLUTION = 5.0; // if 3.3v use 3.3
|
||||
const int ADC_RESOLUTION = 10; // for 10bit analog to digital converter.
|
||||
const int retries = 50;
|
||||
|
Loading…
x
Reference in New Issue
Block a user