I am getting this message while compiling "Global variables use 1995 bytes (97%) of dynamic memory, leaving 53 bytes for local variables"
The following code is part of my Gassensors library (ie Gassensors.cpp) and i have 9 other cases similar to case 2. when i comment out the whole case i am using just 284 bytes of dynamic memory.
void Gassensors::printallgases(uint8_t type)
{
switch (_type) {
case 2:
{int mq2gases[]={0,1,2,3,4,5,6};
Serial.print("HYDROGEN:");
Serial.print(gasppm(_pin, _type, mq2gases[0]));
Serial.print( "ppm" );
Serial.print(" ");
Serial.print("LPG:");
Serial.print(gasppm(_pin, _type, mq2gases[1]));
Serial.print( "ppm" );
Serial.print(" ");
Serial.print("METHANE:");
Serial.print(gasppm(_pin, _type, mq2gases[2]));
Serial.print( "ppm" );
Serial.print(" ");
Serial.print("CARBON_MONOXIDE:");
Serial.print(gasppm(_pin, _type, mq2gases[3]));
Serial.print( "ppm" );
Serial.print(" ");
Serial.print("ALCOHOL:");
Serial.print(gasppm(_pin, _type, mq2gases[4]));
Serial.print( "ppm" );
Serial.print(" ");
Serial.print("SMOKE:");
Serial.print(gasppm(_pin, _type, mq2gases[5]));
Serial.print( "ppm" );
Serial.print(" ");
Serial.print("PROPANE:");
Serial.print(gasppm(_pin, _type, mq2gases[6]));
Serial.print( "ppm" );
Serial.print("\n");}
break;
//nine other cases here
}
}
int Gassensors::gasppm(uint8_t pin, uint8_t type, int mqgases_id, uint8_t Gas_Name)
{
return (MQGetGasPercentage(rs_ro_ratio(pin), mqgases_id ));
}
int Gassensors::MQGetGasPercentage(float rs_ro_ratio, int gas_id )
{
switch (_type) {
case 2:
//Serial.print("calculating mq2 gases: xxxxxx ");
// Serial.print(gas_id);
//Serial.print("gas_id ");
if ( accuracy == 0 ) {
if ( gas_id == GAS_HYDROGEN ) {
// Serial.print("calculating mq2 GAS_HYDROGEN");
return (pow(10, ((-2.109 * (log10(rs_ro_ratio))) + 2.983)));
} else if ( gas_id == GAS_LPG ) {
// Serial.print("calculating mq2 GAS_LPG");
return (pow(10, ((-2.123 * (log10(rs_ro_ratio))) + 2.758)));
} else if ( gas_id == GAS_METHANE ) {
//Serial.print("calculating mq2 GAS_METHANE");
return (pow(10, ((-2.622 * (log10(rs_ro_ratio))) + 3.635)));
} else if ( gas_id == GAS_CARBON_MONOXIDE ) {
// Serial.print("calculating mq2 GAS_CARBON_MONOXIDE");
return (pow(10, ((-2.955 * (log10(rs_ro_ratio))) + 4.457)));
} else if ( gas_id == GAS_ALCOHOL ) {
// Serial.print("calculating mq2 GAS_ALCOHOL");
return (pow(10, ((-2.692 * (log10(rs_ro_ratio))) + 3.545)));
} else if ( gas_id == GAS_SMOKE ) {
//Serial.print("calculating mq2 GAS_SMOKE");
return (pow(10, ((-2.331 * (log10(rs_ro_ratio))) + 3.596)));
} else if ( gas_id == GAS_PROPANE ) {
//Serial.print("calculating mq2 GAS_PROPANE");
return (pow(10, ((-2.174 * (log10(rs_ro_ratio))) + 2.799)));
}
}
else if ( accuracy == 1 ) {
if ( gas_id == GAS_HYDROGEN ) {
return (pow(10, ((-2.109 * (log10(rs_ro_ratio))) + 2.983)));
} else if ( gas_id == GAS_LPG ) {
return (pow(10, ((-2.123 * (log10(rs_ro_ratio))) + 2.758)));
} else if ( gas_id == GAS_METHANE ) {
return (pow(10, ((-2.622 * (log10(rs_ro_ratio))) + 3.635)));
} else if ( gas_id == GAS_CARBON_MONOXIDE ) {
return (pow(10, ((-2.955 * (log10(rs_ro_ratio))) + 4.457)));
} else if ( gas_id == GAS_ALCOHOL ) {
return (pow(10, ((-2.692 * (log10(rs_ro_ratio))) + 3.545)));
} else if ( gas_id == GAS_SMOKE ) {
return (pow(10, (-0.976 * pow((log10(rs_ro_ratio)), 2) - 2.018 * (log10(rs_ro_ratio)) + 3.617)));
} else if ( gas_id == GAS_PROPANE ) {
return (pow(10, ((-2.174 * (log10(rs_ro_ratio))) + 2.799)));
}
}
break;
//nine other cases here
}
Can someone please help me understand what is using up the dynamic memory.