   }
 }
 
+void storeandclearLamps() {
+  memcpy(storedLamp,previousLamp,256);
+  for(int i=0;i<397;i++) writeLamp(i,0);
+}
+
+void restoreLamps() {
+  // 0 all lamps
+  for(int i=0;i<397;i++) writeLamp(i,0);
+  // now write out to addresses that have data in (then we don't accidentally set displays/dimmers
+  for(int i=0;i<256;i++) {
+    if(storedLamp[i]) {
+      sendData(i,storedLamp[i]);
+    }
+  }
+}
+
 void setup() {
   Serial.begin(115200);
   

uint8_t previousLamp[255] = {0};
uint8_t previousDim[9] = {0};

uint8_t previousButtons_XPT[22] = {0};
uint8_t previousButtons_DSK[8] = {0};
uint8_t previousButtons_DSK_SEC[5] = {0};

          break;
      }
    } else {
      // things that don't require two values
      switch(buffer[0]) {
        case 'a':
          Serial.print("a");Serial.print(atoi(buffer+1));Serial.print(",");Serial.println(readAnalog(atoi(buffer+1)));
          break;
        case '!':
          resetFunc();
        case '~':
          Serial.println("Analog Calibrate mode");
          storeandclearLamps();
          Serial.println("Waiting...");
          waitSerial();
          restoreLamps();
          break;
      }
    }
    memset(buffer, 0, BUFFER_SIZE);
  }
