//
//
//millisTest9Mar

 int myPin = A2; // INPUT Analogue Sensor
   int stoke = 2; // INPUT Stoking Temp Sensor (Bottom of store)
   int houseUFH = 3; // OUTPUT UFH Relay
    int runPin = 4; // INPUT Heat Available Temp Sensor (Top of store)
     int annex = 5; // INPUT Annex Pump
      int house = 6; // INPUT House Pump
       int alarm = 7; // OUTPUT Alarm Light Relay
        int clok = 8; // INTPUT from Clock
         int veryHot = 9; // INPUT  Boiler too hot
          int logStoreUFH = 10; // OUTPUT Log Store UFH Relay
           int butt = 12; // INTPUT from Cancel Button
          
          int ledPin = 13; // OUTPUT Indicator LED

    int currentMillis = ( 0);

unsigned long previousMillis = 0;        // will store last time LED was updated

const long interval = 1000;           // interval at which to update millis (milliseconds)
           
      int dt = 500; // Delay of 500secs

void setup() {
  Serial.begin(9600);
  
    pinMode(myPin,INPUT);          //  pin A2
     pinMode(stoke,INPUT);         // stat acts 70deg    pin 2
      pinMode(houseUFH, OUTPUT);   // Yellow Relay Wire  pin 3
       pinMode(runPin, INPUT);     // stat acts at 56deg    pin 4
        pinMode(annex,INPUT);      //    pin 5
         pinMode(house,INPUT);     //    pin 6
          pinMode(alarm, OUTPUT);         // Blue Relay Wire   pin 7
           pinMode(clok, INPUT);         // 5v from clock      pin 8
            pinMode(veryHot, INPUT);        // stat acts at 85deg   pin 9
             pinMode(logStoreUFH, OUTPUT); // Green Relay Wire  pin 10
             pinMode(butt,INPUT);           //  cancel button  pin12
              pinMode(ledPin, OUTPUT);     // Indicator LED     pin13
               
}

void loop() {

delay (dt);
Serial.print("   Millis  =   ");
Serial.println(millis());

int analog = analogRead(myPin);    // Reads data from myPin (A2) pin and puts in analog Int
int readRun = digitalRead(runPin);  // Reads data from runPin (4) and puts it in readRun Int
int readStoke = digitalRead(stoke); // Reads data from stoke (2) and puts in readStoke Int
int readAlarm = digitalRead(alarm); // Reads data from alarm (7) and puts in readAlarm Int
int readClock = digitalRead(clok);  // Reads data from clok (8) and puts it in readClock Int
int readHot = digitalRead(veryHot);      // Reads data from veryHot (9) and puts it in readHot Int
int readButt = digitalRead(butt);  // Reads data from butt (12) and puts it in readButt Int

if (readStoke == 0){
                    
  Serial.println("Boiler Requires Stoking");
   digitalWrite(ledPin,HIGH);                 // starts indicator LED flashing
    delay (dt/8);
     digitalWrite(ledPin,LOW);
      delay (dt/2);
       digitalWrite(ledPin,HIGH);                 // starts indicator LED flashing
        delay (dt/8);
         digitalWrite(ledPin,LOW);
          delay (dt);             
  
  digitalWrite(alarm,HIGH); }    // lights alarm led pin 7

else{
  digitalWrite(ledPin,LOW);
  digitalWrite(alarm,LOW);
  
  }  
          if (readButt == HIGH ){
            digitalWrite(alarm,LOW);
            Serial.println("Button Pressed");
            
              if(currentMillis - previousMillis > interval){
                digitalWrite(alarm,LOW);

    }

  if (readHot == HIGH ){
  
  digitalWrite(logStoreUFH,LOW);       // Turns Store Pump relay on
  Serial.println("Store Pump Turned On");
  
  }
else{
  digitalWrite(logStoreUFH,HIGH);      // Turns Store Pump Relay off pin10
  }  
    
Serial.print("readHot = ");
   Serial.println(readHot);
   Serial.println("   ");
  }
      
                    }