   }
 }
 
+void sendCodeOnce() {
+  unsigned long time = millis();
+
+  if ( (time - sentLockMillis) > 10000) { //10 seconds
+    Serial.println("Sending once");
+    sendCode();
+    sentLockMillis = time;
+  }
+}
+
 void loop()
 {
   int buttonState = digitalRead(BUTTON_PIN);
+  int lightValue = analogRead(ANALOG_LIGHT_PIN);
+  
+  if (lightValue < 200) {
+    sendCodeOnce();
+  }
 
   if (buttonState == HIGH) {
     if (irrecv.decode(&results)) {

    pinMode(ledPin1, OUTPUT);
    pinMode(RECV_PIN, INPUT);
    pinMode(BUTTON_PIN, INPUT);
  
    //WiFi.init();
    WiServer.init(sendPage);

unsigned long codeValue; // The code value if not raw
int codeLen; // The length of the code
int toggle = 0; // The RC5/6 toggle state
unsigned long sentLockMillis = 0;

int lastButtonState;

