 const int pinLED1 = 9;         // LED1
 
 // high limits expressed (units of pin values)
-const int limLED1 =  50;       // LED1 limit
 const int limQ1   = 150;       // Q1 limit
 const int limQ2   = 150;       // Q2 limit
 const int limT1   = 310;       // T1 high alarm (approx. 50 deg C)
 const int limT2   = 310;       // T2 high alarm (approx. 50 deg C)
 
+// LED1 levels
+const int hiLED   =  50;       // high limit of LED
+const int loLED   = hiLED/16;  // low LED
+
+void setHeater1(int pv) {
+  if (brdStatus > 0) {
+    Q1 = max(0, min(limQ1, pv));
+    analogWrite(pinQ1, Q1);
+    Serial.println(Q1);
+  }
+}
+
+void setHeater2(int pv) {
+  if (brdStatus > 0) {
+    Q2 = max(0, min(limQ2, pv));
+    analogWrite(pinQ2, Q2);
+    Serial.println(Q2);
+  }
+}
 
 // parse serial input
 void SerialParse(void) {

    ; // wait for serial port to connect.
  }
  Serial.flush();
  analogWrite(pinQ1,0);
  analogWrite(pinQ2,0);
}


// main event loop
void loop() {
  SerialParse();
  CommandDispatch();
  AlarmsCheck();
}

    Serial.println(degC);
  }
  else if (cmd == "VERSION") {
    Serial.println("TClab Firmware Version " + vers);
  }
  // shutdown
  else if ((cmd == "X") or (cmd.length() > 0)) {
    Serial.println("Unrecognized command. Please reset.");
    setHeater1(0);
    setHeater2(0);
    brdStatus = 0;
  }
}

// check alarms and update status on LED1
void AlarmCheck(void) {
  if (analogRead(pinT1) > limT1) {
    alarmStatus = 1;
  }
  else if (analogRead(pinT2) > limT2) {
    alarmStatus = 1;
  }
  else {
    alarmStatus = 0;
  }
}

// update LED
void LEDUpdate(void) {
  // find led status
  ledStatus = brdStatus;
  if ((Q1 > 0) or (Q2 > 0)) {
    ledStatus = 2;
  }
  if (alarmStatus > 0) {
    ledStatus = 3;
    if ((Q1 > 0) or (Q2 > 0)) {
      ledStatus = 4;
    }
  }
  // update led depending on ledStatus
  if (ledStatus == 0) {
    analogWrite(pinLED1, 0);
  }
  else if (ledStatus == 1) {
    analogWrite(pinLED1, loLED);
  }
  else if (ledStatus == 2) {
    analogWrite(pinLED1, hiLED);
  }
  else if (ledStatus == 3) {
    if ((millis() % 2000) > 1000) {
      analogWrite(pinLED1, loLED);
    } else {
      analogWrite(pinLED1, 0);
    }
  }
  else if (ledStatus == 4) {
    if ((millis() % 2000) > 1000) {
      analogWrite(pinLED1, hiLED);
    } else {
      analogWrite(pinLED1, 0);
    }
  }
}

// arduino setup procedure
void setup() {
  analogReference(EXTERNAL);
  Serial.begin(baud); 
