Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include coeficient tables to library #66

Open
Nic30 opened this issue Jul 16, 2023 · 1 comment
Open

Include coeficient tables to library #66

Nic30 opened this issue Jul 16, 2023 · 1 comment

Comments

@Nic30
Copy link

Nic30 commented Jul 16, 2023

I would like to avoid duplication of constant in my project. What I did is to copy A,B interpolation coefficients from examples.

There are 2 things which can be done. 1st is to include some array which will contain coefficients or there could be class for every gas sensor with a proper method. Second variant seems to me as better because it is faster and intuitive.

class MQ2GasSensor: public MQGasSensor {
public:
  static const float CLEAN_AIR_PPM = 9.83; // RS / R0
  using MQGasSensor::MQGasSensor;
  
  float getPpmH2() {
     return getInterpolation(987.99, -2.162);
  }
  float getPpmLPG() {
     return getInterpolation(574.25, -2.222);
  }
// ...
}
@miguel5612
Copy link
Owner

it could be like:

`class MQ2GasSensor : public MQUnifiedsensor {
public:
MQ2GasSensor(const char* board, float voltageResolution, int bitResolution, int pin, const char* type)
: MQUnifiedsensor(board, voltageResolution, bitResolution, pin, type) {}

float getPpmH2() {
    setA(987.99);
    setB(-2.162);
    return readSensor();
}

float getPpmLPG() {
    setA(574.25);
    setB(-2.222);
    return readSensor();
}

float getPpmCO() {
    setA(36974);
    setB(-3.109);
    return readSensor();
}

float getPpmAlcohol() {
    setA(3616.1);
    setB(-2.675);
    return readSensor();
}

float getPpmPropane() {
    setA(658.71);
    setB(-2.168);
    return readSensor();
}

};`

Could you reply to all examples, and send us the pull or merge request? @Nic30
Thanks ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants