Added set sensor characteristics fctn

This commit is contained in:
JhonatanRamirez 2019-05-23 15:17:39 -05:00
parent 15e436c309
commit 201d018055
4 changed files with 73 additions and 26 deletions

View File

@ -1,5 +1,5 @@
{
"board": "esp8266:esp8266:huzzah",
"configuration": "CpuFrequency=80,VTable=flash,FlashSize=4M1M,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,FlashErase=none,UploadSpeed=115200",
"configuration": "CpuFrequency=80,UploadSpeed=115200,FlashSize=4M1M",
"port": "COM8"
}

View File

@ -13,5 +13,5 @@
"cppStandard": "c++17"
}
],
"version": 4
"version": 3
}

View File

@ -2,34 +2,80 @@
void MQUnifiedsensor::MQSensor(int pin, int type) {
this->_pin = pin;
this->_type = type; //2,3,4,5,6,7,8,9,131,135,303,309
//Set _MQ variable with MQ sensor selected
if(_type == 2)
{
_MQ = MQ2;
}
else if(_type == 3)
{
_MQ = MQ3;
}
else if(_type == 4)
{
_MQ = MQ4;
}
else if(_type == 5)
{
_MQ = MQ5;
}
else if(_type == 6)
{
_MQ = MQ6;
}
else if(_type == 7)
{
_MQ = MQ7;
}
else if(_type == 8)
{
_MQ = MQ8;
}
else if(_type == 9)
{
_MQ = MQ9;
}
else if(_type == 131)
{
_MQ = MQ131;
}
else if(_type == 135)
{
_MQ = MQ135;
}
else if(_type == 303)
{
_MQ = MQ303A;
}
else if(_type == 309)
{
_MQ = MQ309;
}
}
void MQUnifiedsensor::setR0(double R0) {
this->_R0 = R0;
}
String MQUnifiedsensor::readSensor(String nameLectureReqeuired)
String MQUnifiedsensor::readSensor(String nameLectureRequeired = "")
{
switch (_type)
{
case 1:
break;
default:
break;
}
setSensorCharacteristics(nameLectureRequeired);
}
void MQUnifiedsensor::getSensorCharacteristics(int MQ[38], String nameLectureReqeuired)
void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired)
{
if(nameLectureReqeuired = nameLecture[0])
{
_m = MQ[indexSlopeLectures[0]];
_b = MQ[indexBPointLectures[0]];
int wantedpos = 0;
for (int i=0; i<lecturesAvailable; i++) {
if (nameLectureRequeired = nameLecture[i]) { //modified here
wantedpos = i;
break;
}
}
_m = MQ[indexSlopeLectures[i]];
_b = MQ[indexBPointLectures[i]];
}
double MQUnifiedsensor::calibrate() {

View File

@ -12,9 +12,9 @@ class MQUnifiedsensor
*/
void MQSensor(int pin, int type);
void setR0(double R0);
void setSensorTyp(int sensorNumber);
void getSensorCharacteristics(int MQ[38], String nameLectureReqeuired);
String readSensor(String nameLectureReqeuired);
void setSensorCharacteristics(int MQ[38], String nameLectureReqeuired);
String readSensor(String nameLectureReqeuired = "");
int readPPM(int m, int b);
/**
@ -44,12 +44,13 @@ class MQUnifiedsensor
MQ137 - Ammonia
MQ138 - Benzene, Toluene, Alcohol, Acetone, Propane, Formaldehyde gas, Hydrogen
*/
int lecturesAvailable = 19;
String nameLecture[lecturesAvailable] = {"H2","LPG","CH4","CO","Alcohol","Propane","Benzine","Hexane","Smoke","Nox","CL2","O3","CO2","Tolueno","NH4","Acetona","Iso-butano","Hydrogeno","Ethanol"};
int indexSlopeLectures[lecturesAvailable] ={0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36};
int indexBPointLectures[lecturesAvailable] ={1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37};
String nameLecture[19] = {"H2","LPG","CH4","CO","Alcohol","Propane","Benzine","Hexane","Smoke","Nox","CL2","O3","CO2","Tolueno","NH4","Acetona","Iso-butano","Hydrogeno","Ethanol"};
int indexSlopeLectures[19] ={0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36};
int indexBPointLectures[19] ={1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37};
String units[19] = {"ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm"};
String units[lecturesAvailable] = {"ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm", "ppm"};
int MQ2[38] = {-2.2459,2.9845,-2.2879,2.7901,-2.6208,3.6075,-3.1157,4.5134,-2.7028,3.5595,-2.2879,2.7901,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int MQ3[38] = {0,0,-3.1851,4.7048,-17.531,28.785,-4.339,6.4432,-1.435,0.4103,0,0,-2.7009,0.632,-2.7268,3.6299,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
@ -66,7 +67,7 @@ class MQUnifiedsensor
private:
int _pin, _type;
int _pin, _type, _MQ[38];
double _R0, _m, _b;
const float VOLT_RESOLUTION = 5.0; // if 3.3v use 3.3
const int ADC_RESOLUTION = 10; // for 10bit analog to digital converter.