void loop()
{
timesincestarts = millis(); //Counting millis to minutes
timesincestart= timesincestarts/ minute;
Serial.println(timesincestart);
//Button
reading = digitalRead(inPin); //Reading the value of the button and setting reading
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
if(state == HIGH)
{
//Tempmätare Serial
uint16_t rtd = max.readRTD();
float ratio = rtd;
ratio /= 32768;
Serial.print("Temperature = "); Serial.println(max.temperature(RNOMINAL, RREF)); //Writing Temperatur c value on second line of serial monitor
TempC = max.temperature(RNOMINAL, RREF);
//Tempgauge 2
sensors.requestTemperatures(); //Get temp
TempC2 = sensors.getTempCByIndex(0); //Turning it to degres
//The different sequences
if(0 <= timesincestart && timesincestart < sequence1 )
{
Settemp = temp1;
Setspeed = speed1;
currentsequence = 1;
}
if(sequence1 < timesincestart && timesincestart < (sequence2 + sequence1))
{
Settemp = temp2;
Setspeed = speed2;
currentsequence = 2;
}
if((sequence2 + sequence1) < timesincestart && timesincestart < (sequence3 + sequence2 + sequence1))
{
Settemp = temp3;
Setspeed = speed3;
currentsequence = 3;
}
if((sequence3 + sequence2 + sequence1) < timesincestart && timesincestart < (sequence4 + sequence3 + sequence2 + sequence1))
{
Settemp = temp4;
Setspeed = speed4;
currentsequence = 4;
}
if((sequence4 + sequence3 + sequence2 + sequence1) < timesincestart && timesincestart < (sequence5 + sequence4 + sequence3 + sequence2 + sequence1))
{
Settemp = temp5;
Setspeed = speed5;
currentsequence = 5;
}
if((sequence5 + sequence4 + sequence3 + sequence2 + sequence1) < timesincestart && timesincestart < (sequence6 + sequence5 + sequence4 + sequence3 + sequence2 + sequence1))
{
Settemp = temp6;
Setspeed = speed6;
currentsequence = 6;
}
if((sequence6 + sequence5 + sequence4 + sequence3 + sequence2 + sequence1) < timesincestart && timesincestart > (sequence7 + sequence6 + sequence5 + sequence4 + sequence3 + sequence2 + sequence1))
{
Settemp = speed7;
Setspeed = speed7;
currentsequence = 7;
}
if((sequence7 + sequence6 + sequence5 + sequence4 + sequence3 + sequence2 + sequence1) < timesincestart && timesincestart < (sequence8 + sequence7 + sequence6 + sequence5 + sequence4 + sequence3 + sequence2 + sequence1))
{
Settemp = temp8;
Setspeed = speed8;
currentsequence = 8;
}
if(sequence8 < timesincestart) //Timear den ut så når den inte setcurrent
{
previous = HIGH;
state = LOW;
currentsequence = 9;
}
else
{}
//Count
Setspeedcalc = 3/(10*Setspeed+1);
//Seriall Monitor
lcd.clear();
lcd.setCursor (0,0);
lcd.print("Sequence");
lcd.setCursor(9,0);
lcd.print(currentsequence);
lcd.setCursor(0,1);
lcd.print("Temp:");
lcd.print(TempC);
lcd.setCursor(8,1);
lcd.print("RPM:");
lcd.print(Setspeed);
//Motor kontroll
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < stepsPerRevolution; x++) {
digitalWrite(stepPin,HIGH);
digitalWrite(stepPin,LOW);
delay(Setspeedcalc);
}
//if sats
if (TempC < Settemp && TempC != -247) { //Relay control with failsafe
analogWrite(relaych1, 1);
Serial.println("YES"); //diagnotsik
}
if (TempC > Settemp) {
analogWrite(relaych1, 0);
Serial.println("NO"); //diagnostik
}
//Nollställa värden
sensorValue = 0; // återställer värdet innan nästa loop
}
else if(currentsequence == 9)
{
digitalWrite(relaych1, 0);
lcd.clear();
lcd.setCursor (0,0);
lcd.print("Finish!");
}
previous = reading;
}