Setup section:
Code:
void setup() {
//push buttons
pinMode(bLeft,INPUT_PULLUP);
pinMode(bRight,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(bLeft),LeftButton,CHANGE);
attachInterrupt(digitalPinToInterrupt(bRight),RightButton,CHANGE);
tft.init(240, 240, SPI_MODE3);
tft.fillScreen(0x0000);
tft.setRotation(2);
tft.setTextWrap(false); // turn off text wrap option
ads.setGain(GAIN_FOUR); // 4x gain 1 bit = 0.03125mV
ads.begin();
if (enableCO) {
ads2.setGain(GAIN_TWOTHIRDS); // 2x gain 1 bit = 0.125mV
ads2.begin();
}
RAhe.clear();
RAox.clear();
RAco.clear();
heVcal = readHEsensor();
oxVcal = readO2sensor();
// read EEPROM values
int eeAddress = 0;
EEPROM.get(eeAddress, oxVmax);
eeAddress += sizeof(oxVmax); //Move address to the next byte after float 'f'.
EEPROM.get(eeAddress, heVmax );
eeAddress += sizeof(heVmax); //Move address to the next byte after float 'f'.
EEPROM.get(eeAddress, oxVmin );
if (isnan(oxVmax)) {
calibrateO2 = true;
}
if (isnan(heVmax)) {
calibrateHe = true;
}
tft.fillRect(0,32,240,240,0x0000);
tft.setTextColor(0xFFFF, 0x0000);
tft.setTextSize(2);
tft.setCursor(10,35);
tft.print(ver1);
tft.setCursor(10,55);
tft.print(ver2);
delay(250);
//He sensor
if (enableHe) {
tft.setTextSize(2);
tft.setCursor(10,80);
tft.print(HEsensor);
while(heVcal > 2 or heVcal < -1){ //keeps looping if sensor is cold
heVcal = readHEsensor();
tft.setCursor(10,100);
tft.print(calibrate);
tft.print(heVcal,1);
delay(25);
}
tft.setCursor(10,100);
tft.print(F("He "));
tft.print(calibOK);
}
//O2 sensor
tft.setTextSize(2);
tft.setCursor(10,140);
tft.print(calibrate);
tft.setCursor(10,160);
tft.print(O2sensor);
while (oxVcal < 9 or oxVcal > 12) {
tft.setCursor(10,180);
if (oxVcal < 9) {
tft.print(F("V cell too low "));
}
if (oxVcal > 12) {
tft.print(F("V cell too high"));
}
oxVcal = readO2sensor();
tft.setCursor(155,160);
tft.print(oxVcal,2);
tft.print(mV);
delay(250);
}
tft.setCursor(10,180);
tft.print(F("O2 "));
tft.print(calibOK);
delay(2000);
tft.fillRect(0,32,240,240,0x0000);
tft.setTextSize(3);
tft.setCursor(0,80);
tft.println(warn1);
tft.print(warn2);
tft.setCursor(0,170);
tft.print(warn3);
delay(3000);
//end of calibration, draw screen for loop operation:
MODcalc = 1.4;
leftclick=0;
tft.fillScreen(0x0000);
}