   char c;
   int ledpin=0,val=0,id=0;
   // format: "^LG1=0$" turn off green led 1 (RCS), "^LR2=1$" turn off red led 2 (SCS)
+  if (Serial.available()>0) {
   if (Serial.find("L")) {
     c = Serial.read();
     id = Serial.parseInt();  // skip '='
     val = Serial.parseInt(); // skip newline
-    Serial.print(c); Serial.print(id); Serial.print(val);  // echo
+    Serial.print(c); Serial.print(id); Serial.println(val);  // echo for ack
     if (c=='G' && id==1) { ledpin = ledRCSonPin; }
     if (c=='R' && id==1) { ledpin = ledRCSoffPin; }
     if (c=='G' && id==2) { ledpin = ledSCSonPin; }

void updateThrottle() {
  // read the analog in value:
  throttleValue = analogRead(throttlePin);
  // calibrate
  if (throttleValue>throttleMax) { throttleMax=throttleValue; }
  if (throttleValue<throttleMin) { throttleMin=throttleValue; }
  // map it to the range of the analog out:
  throttleValue = map(throttleValue, throttleMin, throttleMax, 0, 255);
  // is it different enough from last reading?
  if (abs(throttleValue-lastThrottleValue)>4) {
    // dump status
    Serial.print("P0=");
    Serial.println(throttleValue,HEX);
  }
  lastThrottleValue = throttleValue;
}

uint8_t updateButton(int pin, int id, uint8_t lastState) {
  uint8_t state = digitalRead(pin);
  if (state != lastState) {
    Serial.print('D');
    Serial.print(id);

int throttleValue = 0;
int throttleMin = 1023;
int throttleMax = 0;
#define THROTTLE_THRESHOLD 4

// switch control
uint8_t lastStageState = HIGH;
