/* * Heat Recovery Experiment Valve Control */ int ValvePin = 10; // set the DI/O pin to send the signal to the valve as pin 10 int ValveState = LOW; // Valve state used to set the valve unsigned long previousMillis = 0; // will store last time valve was updated long OnTime = 500; // milliseconds of on-time long OffTime = 500; // milliseconds of off-time // This sets the baud rate which is to do with displaying the values on the serial monitor // Initiliase the valve pin (pin 10) as an output void setup() { Serial.begin(9600); pinMode(ValvePin, OUTPUT); } // This is the loop which will be repeated. Everything above this can be given before the loop in the combined code. // The code below needs to somehow be included in with the code for operating the valve void loop() { // check to see if it's time to change the state of the valve unsigned long currentMillis = millis(); if((ValveState == HIGH) && (currentMillis - previousMillis >= OnTime)) { ValveState = LOW; // Turn it off previousMillis = currentMillis; // Remember the time digitalWrite(ValvePin, ValveState); // Update the actual valve } else if ((ValveState == LOW) && (currentMillis - previousMillis >= OffTime)) { ValveState = HIGH; // turn it on previousMillis = currentMillis; // Remember the time digitalWrite(ValvePin, ValveState); // Update the actual LED } }