2nd part
void loop()
{
while (sampleLow < 8000){
while (digitalRead (5)== LOW){
Serial.println("\n[memCheck]");
Serial.println(freeRam());
#define arraySize 23
#define limitLow 3700
#define limitHigh 29252
#define limitHold 25615
//read sensor
static int holdVal = 31000;
adc0 = ads1115.readADC_SingleEnded(0);
sensorReading = adc0;
int adjmilsOutput = map (sensorReading, sampleLow, sampleHigh, limitLow , limitHigh);
int mils[] = {
0, 12, 31, 61, 92, 120, 150, 180, 211, 241, 270, 300, 330, 360, 390, 420, 450, 480, 510, 539, 570, 600, 2850 }; //output required
int anlogin[] = {
3700, 4330, 6400, 9400, 11440, 13375, 15300, 16620, 17940, 19185, 20000, 20935, 21725, 22375, 23000, 23500, 24000, 24427, 24833, 25205, 25515, 25615, 29252 }; //sampled anlogread
int milsOutputA = multiMap(adjmilsOutput, anlogin, mils, arraySize);
// subtract the last reading:
total= total - readings[index];
// read from the sensor:
readings[index] = milsOutputA;
// add the reading to the total:
total= total + readings[index];
// advance to the next position in the array:
index = index + 1;
// Serial.println("total=");
// if we're at the end of the array...
if (index >= numReadings)
// ...wrap around to the beginning:
index = 0;
// calculate the average:
milsOutput = (total / numReadings)+offSet;
int swVal = analogRead(A1); // hold switch on A1
if(swVal <=250) { // hold position
holdVal = min(holdVal,milsOutput); // the smallest mil value is locked in
}
if (swVal >=250) { // toggled to unhold position
holdVal = 31000;
}
if (holdVal <= milsOutput) {
milsOutput = holdVal;
}
metricOutput = (milsOutput*25.4)/1000; // convert to milsOutput
if (adjmilsOutput > limitHold ) {
lcd.clear();
lcd.setCursor(0, 0);
range_msg.print(lcd);
lcd.setCursor(1, 0);
range_asterisk_msg.print(lcd);
range_msg_serial.print(Serial);
delay (200);
}
else {
lcd.setCursor(0, 0);
if (swVal <=250) {
lcd.clear();
delay(10);
lcd.print("H");
lcd.print(milsOutput);
lcd.print(" mil ");
lcd.setCursor(1, 0);
lcd.print(" ");
lcd.print(metricOutput);
lcd.print(" mm ");
Serial.print("H");
Serial.print("M");
Serial.print(metricOutput);
Serial.print("|");
Serial.print("I");
Serial.println(milsOutput);
//delay(150);
}
else {
lcd.clear();
delay(10);
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.print(milsOutput);
lcd.print(" mil ");
lcd.setCursor(1, 0);
lcd.print(" ");
lcd.print(metricOutput);
lcd.print(" mm ");
//delay(150);
Serial.print("M");
Serial.print(metricOutput);
Serial.print("|");
Serial.print("I");
Serial.println(milsOutput);
// delay(50);
}
}
}
fMenu();
}
while (sampleLow > 8000 ){
while (digitalRead (5)== LOW){
#define arraySize2 17
#define limitLow2 12800
#define limitHigh2 29252
#define limitHold2 25935
//Read Sensor
static int holdVal = 31000;
adc0 = ads1115.readADC_SingleEnded(0);
sensorReading = adc0;
int adjmilsOutput = map (sensorReading, sampleLow, sampleHigh, limitLow2 , limitHigh2);
int mils[] = {
0, 12, 31, 61, 92, 120, 150, 180, 211, 241, 270, 300, 330, 360, 390, 420, 2300 }; //output required
int anlogin[] = {
12800, 13740, 15690, 17350, 19028, 20175, 21175, 22083, 22810, 23540, 24000, 24540, 24950, 25320, 25650, 25935, 29252 }; //sampled anlogread
int milsOutputA = multiMap(adjmilsOutput, anlogin, mils, arraySize2);
// subtract the last reading:
total= total - readings[index];
// read from the sensor:
readings[index] = milsOutputA;
// add the reading to the total:
total= total + readings[index];
// advance to the next position in the array:
index = index + 1;
// if we're at the end of the array...
if (index >= numReadings)
// ...wrap around to the beginning:
index = 0;
// calculate the average:
milsOutput = (total / numReadings)+offSet;
int swVal = analogRead(A1); // hold switch on digital 7
if(swVal <=250) { // hold position
holdVal = min(holdVal,milsOutput); // the smallest mil value is locked in
}
if (swVal >=250) { // toggled to unhold position
holdVal = 31000;
}
if (holdVal <= milsOutput) {
milsOutput = holdVal;
}
metricOutput = (milsOutput*25.4)/1000; // convert to milsOutput
if (adjmilsOutput > limitHold2 ) {
lcd.clear();
delay(10);
lcd.setCursor(0, 0);
range_msg.print(lcd);
lcd.setCursor(1, 0);
range_asterisk_msg.print(lcd);
range_msg_serial.print(Serial);
delay (200);
}
else {
lcd.clear();
delay(10);
lcd.setCursor(0, 0);
if (swVal <=250) {
lcd.print("H");
lcd.print(milsOutput);
lcd.print(" mil ");
lcd.setCursor(1, 0);
lcd.print(" ");
lcd.print(metricOutput);
lcd.print(" mm ");
Serial.print("H");
Serial.print("M");
Serial.print(metricOutput);
Serial.print("|");
Serial.print("I");
Serial.println(milsOutput);
//delay(150);
}
else {
lcd.clear();
delay(10);
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.print(milsOutput);
lcd.print(" mil ");
lcd.setCursor(1, 0);
lcd.print(" ");
lcd.print(metricOutput);
lcd.print(" mm ");
//delay(150);
Serial.print("M");
Serial.print(metricOutput);
Serial.print("|");
Serial.print("I");
Serial.println(milsOutput);
// delay(50);
}
}
}
fMenu();
}
}
//