           fanPWM = 255;
         }
       } else if (maxTemp >= tempMin) {
-        fanPWM = map(maxTemp, tempMin, tempMax, fanMin, fanMax);
-        Serial.print(F("Fan PWM: "));
-        Serial.println(fanPWM);
+        byte newPWM = map(maxTemp, tempMin, tempMax, fanMin, fanMax);
+        if (newPWM != fanPWM) {
+          fanPWM = newPWM;
+          debug(currentMillis, F("Fan PWM: "));
+          Serial.println(fanPWM);
+        }
       } else if (fanPWM > 0) {
         fanPWM = fanMin;
       }


  pinMode(pirPin, INPUT);

  // scan 1-wire bus for temperature sensors
  byte addr[8];
  byte dsIdx = 0;

  ds.reset_search();
  Serial.print(F("Searching 1-wire...\r\n"));

  while (ds.search(addr) && dsIdx < dsMax) {
    Serial.print(F("Detected device: "));
    for (int i = 0; i < 8; i++) {
      Serial.print(addr[i], HEX);
    }

    Serial.print(F(" - "));
    if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.print(F("invalid CRC!\r\n"));
      continue;
    }

    if (addr[0] == 0x28) {
      for (int i = 0; i < 8; i++) {
        dsAddrs[dsIdx][i] = addr[i];
      }
      dsIdx++;
      Serial.print(F("DS18B20 registered\r\n"));
    } else {
      Serial.print(F("unknown device ignored\r\n"));
     }
  }
  dsCount = dsIdx;
  ds.reset_search();

  // initialize debounce registers, assume steady state
  swFrontDebounce = (swFront = swFrontDeglitch = digitalRead(switchFront)) * 0xFFFF;


  if (dsMillis >= dsInterval) {
    dsMillis = 0;

    byte data[9];
    byte dsRead = 0;
    signed int maxTemp = 0;

    for (int i = 0; i < dsCount; i++) {
      // read temperature
      ds.reset();
      ds.select(dsAddrs[i]);
      ds.write(0xBE);
      for (int j = 0; j < 9; j++) {
        data[j] = ds.read();
      }
