   } else {
     light_state = "off";
   }
+  Serial.println(light_state);
   return true;
 }
 
 void serialEvent() {
   String serial_data = Serial.readString();
+  long serial_num = serial_data.toInt();
   Serial.flush();
   if (serial_data == "i") {
     Serial.println(light_state);
-  } else if (light_state == "alarm" && serial_data == "o") {
-    light_state = "on";
-    Serial.println(light_state);
-  } else if (light_state != "on" && serial_data == "o") {
-    light_state = "dimming";
-    dim(500, true);
-    Serial.println(light_state);
-  } else if (serial_data == "o") {
-    light_state = "dimming";
-    dim(500, false);
-    Serial.println(light_state);
-  } else if (serial_data == "a" && light_state == "off") {
-    light_state = "dimming";
-    //alarm(1800000);
-    alarm(1800000);
+  } else if (serial_num >= 300000l) {
+    alarm(serial_num);
+  } else if (serial_num != 0){
+    dim(serial_num);
   }
 }
 

  }
}

// Returns false if was interrupted, otherwise returns true
boolean dim(unsigned long duration, boolean brighten) {
  double lnb = log(pow(256.0, 1.0 / (float) duration));
  for (int i = 1; i < 256; i++) {
    if (light_state != "dimming") {
      return false;
    }
    unsigned long interval;
    if (brighten) {
      analogWrite(gate_pin, i);
      interval = (unsigned long) round(log(((float) i + 1) / (float) i) / lnb);
    } else {
      int x = 256 - i;
      analogWrite(gate_pin, x - 1);
      interval = (unsigned long) round(log((float) x / ((float) x - 1)) / lnb);
    }
    unsigned long previousMillis = millis();
    if (i < 255) {

}

void blink(unsigned long interval) {
  unsigned long previousMillis;
  light_state = "blink";
  while(light_state == "blink") {
    digitalWrite(gate_pin, LOW);
