int temp = rand() % 1000 + 2000;
int direction = 1;
void setup() {
Serial.begin(115200);
pinMode(13, OUTPUT);
}
void loop() {
int temphigh = analogRead(15) + 100;
int templow = analogRead(15) - 100;
Serial.println();
Serial.print("Temp = ");
Serial.println(temp);
Serial.print("Temp high = ");
Serial.println(temphigh);
Serial.print("Temp low = ");
Serial.println(templow);
if (temp >= temphigh) {
direction = -1;
Serial.println("Det er koldt.");
} else if (temp <= templow) {
direction = 1;
Serial.println("Det er varmt.");
} else {
Serial.println("Det er lunt");
}
if (direction == -1) {
digitalWrite(13, LOW);
} else if (direction == 1) {
digitalWrite(13, HIGH);
}
temp += direction * (rand() % 20 + 10); // Gradually adjust temp
delay(500);
}