The code has been posted. I need help trying to reduce the sram usage. I can't seem to add more menu items because it''ll use up more memory and crash so i deleted the menu that I had created last week. I need to figure out the proper way of using progmem for my program to optimize it so I can add in more menu and functions. I've read a couple of post and tried to mirror what they had but it did not work for me. I think something is missing somewhere. I was at about 19k bytes when it started to crash.
Goal: reduce memory usage by using progmem so more menu setups/items and functions can be added.
Purpose: read sensor and out put to the LCD screen.
If anyone can give me an idea of how to use progmem, I will test it out. I've tried it based on what others posted in the forums here but it did not work.
void sensorafr(){
//----------------------------sensor Section------------------------------------------
//sensor section input, calculations and output
float sst = analogRead(A0); // make variable sst equal to analog value from pin A0
float sstoutput = (sst-0)*(43.51508-(-10))/(1023+ (-10)); //converting analog input to sensor value
float sstoutput1 = sstoutput - aaa; //
float vacoutput = 0;
lcd.setCursor(0,1); // set cursor to first column row 2
vacoutput = sstoutput1 * 2.036021; // convert
if (vacoutput <= (-10)){ //if sstoutput1 is less than or equal to -10 value, then run the following
lcd.setCursor(0,1); // set cursor to column 0 row 2
lcd.print("SEN:"); //print to the LCD
lcd.print(vacoutput,1); // print the sensor value
delay(50); //set delay
}
else if ((vacoutput < 0 ) && (vacoutput > (-10))) { //set condition if value is less than 0 and more than or equal -9 then use VAC
lcd.setCursor(0,1); //set cursor to column 0 row 2
lcd.print("SEN: "); //print on LCD
lcd.print(vacoutput,1); // print the sensor value
delay(50); //set delay
}
else if ((sstoutput1 < 10) && (sstoutput1 >= 0)) { //set condition so if sensor if less than 10 and greater than 0, then the sst adds in an extra space so that it'll display correctly and not shift
lcd.print("SEN: "); //Print sst to LCD
lcd.print(sstoutput1,1); // print sensor value to LCD. the one means to print one decimal point only
delay(50); //delay for .1sec
}
else {
lcd.print("SEN: "); // print sst
lcd.print(sstoutput1,1); // print sensor output value
delay(50); // set delay
}
//---------------------------PEAK sensor------------------------------------------
if(sstoutput1 > peaksensor) { // check to see if sensor if higher than peak sensor
peaksensor = sstoutput1; // make peaksensor equal to current sensor if condition is true
}
if (peaksensor < 10 ) { // check the peak sensor value. If less than 10, then do the following statement
lcd.print(" "); //put a space after sensor value
lcd.print("PB"); // print PB for peak sensor
lcd.print(" "); // put a space after sensor value
lcd.print(peaksensor,1); // print peak sensor value
}
else {
lcd.print(" "); //put a space after sensor value
lcd.print("PB"); // print PB for peak sensor
lcd.print(peaksensor,1); // print peak sensor value
}
//-------------------------- Peaksensor Clear------------------------------------------
if ( digitalRead(clearPB) == HIGH) { // if button is pressed, then the peaksensor resets to zero
peaksensor = 0; // set peaksensor back to zero
}
//---------------------------------- LCD BAR ---------------------------------------
//sensor LCD Bar
//lcd.setCursor(10,1); //set bar graph to start on column 10 row 2
//lbg.drawValue(analogRead(sensorbar), 600);
// Sensor Ratio LCD Bar
lcd.setCursor(9,0); //set cursor to column 10 row 1
lbg.drawValue(analogRead(afrbar), 1023); //bar graph output
//------------------------------------------------------------------------------
// Input, Calculation and output
float afrValue = analogRead(A1); //Read input
float afroutput = (afrValue-0)*(22-8)/(1023-0) +8; // convert values
//Serial.println("AFR Output:");
//Serial.println(afroutput); // print out the value you read:
//Serial.println("AFR Value:");
//Serial.println(afrValue);
lcd.setCursor(0,0); // Print to LCD top Left
if (afroutput < 10) {
lcd.print("LVL: ");
lcd.print(afroutput,1);
//delay(50);
}
else {
lcd.print("LVL: ");
lcd.print(afroutput,1);
//delay(50);
}
//------------------------------sensor Warning--------------------------------
if (sstoutput1 >= sstwarn) {
lcd.noDisplay();// Turn off the display
delay(400);
lcd.display();// Turn on the display
delay(300);
}
}