Need help figuring out my problem Please

Trying to build a controller to handle temperature and auto top up on my aquarium.

I'm using ST7920 GLcd to display information.

I an get it running and displaying temperature, also controlling relays for heating and cooling.
Auto top off all works as it should.

Problem I'm having is that I want to print to GLcd with when my TopUp, Fresh, Heat and Cooling is running but I cant get it to print When the relays re activated.

Thanks in Advance.

Matts_ATO2.ino (5.52 KB)

It looks like in draw_main() those strings are displayed unconditionally. If you want parts of the display to be conditional you probably need to put in an 'if' statement. If the text is to be shown, draw it. If not, you will probably have to erase it by drawing blanks over it.

#include <U8glib.h>
#include <Wire.h>
#include <DallasTemperature.h>
#define Heat  7  // Relay heating
#define Cool  8  // Relay cooling
#define ONE_WIRE_BUS 4

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

U8GLIB_ST7920_128X64_4X u8g(10);    // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10, HW SPI
//U8GLIB_ST7920_128X64_4X u8g(18, 16, 17);  // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17

byte sumplowWaterPin = 2;
byte atolowWaterPin = 3;

byte sumphighWaterPin = 5;
byte atohighWaterPin = 6;

byte sumppumpPin = A1;
byte atopumpPin = A2;

unsigned long Sec = 1000UL;                //1 Second
unsigned long Min = 60000UL;               //1 minute
unsigned long Hr = 60 * Min;               //1 hour
unsigned long Dy = 24 * Hr;                //1 day

unsigned long maxsumpRunTime = 15 * Sec;
unsigned long maxatoRunTime = 1 * Hr;

unsigned long minsumpOffTime = 1 * Hr;
unsigned long minatoOffTime = 1 * Dy;

unsigned long sumpswitchDebounceTime = 1 * Sec;
unsigned long atoswitchDebounceTime = 1 * Sec;

unsigned long lastsumpPumpTime = 0;
unsigned long lastatoPumpTime = 0;

unsigned long lastsumplowWaterDetectTime = 0;
unsigned long lastatolowWaterDetectTime = 0;

int temp1;

boolean lastlowsumpWaterState = HIGH;
boolean lastlowatoWaterState = HIGH;

boolean sumppumpRunning = true;
boolean atopumpRunning = true;

void draw_splash(void) {
  u8g.setFont(u8g_font_helvB12);
  u8g.drawStr(22, 13, "WELCOME");
  u8g.setFont(u8g_font_8x13);
  u8g.drawStr(5, 25, "Matts Aquarium");
  u8g.drawStr(18, 52, "Designed By:");
  u8g.drawStr(17, 63, "Matt Johnson");
}

void draw_main(void) {
  u8g.drawLine(0, 16, 84, 16);

  u8g.setFont(u8g_font_fur42n);
  u8g.setPrintPos(0, 63);
  u8g.print(temp1);
  u8g.setFont(u8g_font_helvB12);
  u8g.drawStr(64, 62, "°C");

  u8g.setFont(u8g_font_8x13);
  u8g.drawStr(87, 10, "TopUp");
  u8g.setFont(u8g_font_helvB12);
  u8g.setPrintPos(90, 29);
  //u8g.print("Run");

  u8g.setFont(u8g_font_8x13);
  u8g.drawStr(87, 43, "Fresh");
  u8g.setFont(u8g_font_helvB12);
  u8g.setPrintPos(92, 63);
  //u8g.print("Fill");

  u8g.drawLine(84, 0, 84, 63);
  u8g.drawLine(84, 32, 128, 32);
}

void setup() {
  sensors.begin();

  pinMode (sumplowWaterPin, INPUT_PULLUP);
  pinMode (atolowWaterPin, INPUT_PULLUP);

  pinMode (sumphighWaterPin, INPUT_PULLUP);
  pinMode (atohighWaterPin, INPUT_PULLUP);

  pinMode (sumppumpPin, OUTPUT);
  pinMode (atopumpPin, OUTPUT);

  pinMode(Heat, OUTPUT);
  pinMode(Cool, OUTPUT);
}


void loop () {
  //////////picture loop/////////
  if (millis() < 10 * Sec) { // The time in milli seconds, for you want to show the splash screen 10000 = 10 Seconds
    u8g.firstPage();
    do {
      draw_splash();
    } while ( u8g.nextPage() );
  } else {
    u8g.firstPage();
    do {
      draw_main();
    } while ( u8g.nextPage() );

    // rebuild the picture after some delay
    delay(50);
  }

  ///////////Temperature Setup//////////
  sensors.requestTemperatures();
  float temp = sensors.getTempCByIndex(0);
  temp1 = temp;

  if ( (temp) > 26)
  {
    u8g.setFont(u8g_font_helvB12);
    u8g.drawStr(2, 14, "Cooler");
    digitalWrite(Cool, HIGH);
    delay(100);
  }
  else if ( (temp) < 26)
  {
    digitalWrite(Cool, LOW);
  }

  if ( (temp) < 25 )
  {
    u8g.setFont(u8g_font_helvB12);
    u8g.drawStr(2, 14, "Heater");
    digitalWrite(Heat, HIGH);
    delay(100);
  }
  else if ( (temp) > 25 )
  {
    digitalWrite(Heat, LOW);
  }

  //////////Float switch Setup//////////
  unsigned long currentMillis = millis();

  boolean lowsumpWaterState = digitalRead(sumplowWaterPin);
  boolean highsumpWaterState = digitalRead(sumphighWaterPin);

  if (lowsumpWaterState != lastlowsumpWaterState) {
    lastsumplowWaterDetectTime = currentMillis;
  }


  if (sumppumpRunning) {  // if the pump is on then let's see if we should turn it off yet

    if ((highsumpWaterState == HIGH) || (currentMillis - lastsumpPumpTime >= maxsumpRunTime)) {
      u8g.setFont(u8g_font_helvB12);
      u8g.drawStr(90, 29, "     ");
      digitalWrite(sumppumpPin, HIGH);
      sumppumpRunning = false;
      lastsumpPumpTime = currentMillis;
    }
  }
  else {   // pump is not running, see if we need to turn it on
    if ((lowsumpWaterState == HIGH)  &&
        (currentMillis - lastsumplowWaterDetectTime >= sumpswitchDebounceTime) &&
        (currentMillis - lastsumpPumpTime > minsumpOffTime)) { // switch is low and has been for at least 3 seconds
      u8g.setFont(u8g_font_helvB12);
      u8g.drawStr(90, 29, "Run");
      digitalWrite(sumppumpPin, LOW);
      sumppumpRunning = true;
      lastsumpPumpTime = currentMillis;
    }
  }

  lastlowsumpWaterState = lowsumpWaterState;

  boolean lowatoWaterState = digitalRead(atolowWaterPin);
  boolean highatoWaterState = digitalRead(atohighWaterPin);

  if (lowatoWaterState != lastlowatoWaterState) {
    lastatolowWaterDetectTime = currentMillis;
  }


  if (atopumpRunning) {  // if the pump is on then let's see if we should turn it off yet

    if ((highatoWaterState == HIGH) || (currentMillis - lastatoPumpTime >= maxatoRunTime)) {
      digitalWrite(atopumpPin, HIGH);
      atopumpRunning = false;
      lastatoPumpTime = currentMillis;
    }
  }
  else {   // pump is not running, see if we need to turn it on
    if ((lowatoWaterState == HIGH)  &&
        (currentMillis - lastatolowWaterDetectTime >= atoswitchDebounceTime) &&
        (currentMillis - lastatoPumpTime > minatoOffTime)) { // switch is low and has been for at least 3 seconds
      digitalWrite(atopumpPin, LOW);
      atopumpRunning = true;
      lastatoPumpTime = currentMillis;
    }
  }

  lastlowatoWaterState = lowatoWaterState;
}