 }
 
 void loop() {
-    buffer_write(&tempRingBuf_1, readTemperatureInCelcius(LM35_1_PIN));
-    buffer_write(&tempRingBuf_2, readTemperatureInCelcius(LM35_2_PIN));
-    delay(AVERAGE_INTERVAL_IN_MILLIS / RING_BUFFER_SIZE); // e.g. one minute = 60*1000
-
-    float lastIntervalTempAverage = averageValues(&tempRingBuf_1);
-    if (lastIntervalTempAverage > SENSOR_1_TEMP_THRESHOLD_in_CELCIUS) {
-        analogWrite(FAN_PWM_PIN, 255);
-    } else {
-        analogWrite(FAN_PWM_PIN, 0);
-    }
-
+    recordSensorMeasurements();
+    adjustFanSpeed();
     if (SEND_TEMP_VALUES_TO_HOST) {
         sendValuesToHost();
     }


void sendValuesToHost() {
    unsigned long currentMillis = millis();
    if ((currentMillis - lastSend) > SEND_TO_HOST_INTERVALL_IN_MILLIS) {
        lastSend = currentMillis;

        Serial.print("(1) ");
        Serial.print(averageValues(&tempRingBuf_1), 1);
        Serial.println("Grad Celsius");

        Serial.print("(2) ");
        Serial.print(averageValues(&tempRingBuf_2), 1);
        Serial.println("Grad Celsius");

        Serial.println("");
    }
}

void setup() {


TemperatureRingBuffer tempRingBuf_1;
TemperatureRingBuffer tempRingBuf_2;
unsigned long lastSendMillis = 0;
unsigned long lastRecordedMillis = 0;

/**************************************************************/

