 }
 
 void customCol(){
+	lcd.setCursor(0,0);
+	lcd.print(" RED GREEN BLUE ");
+	int rpot = 0;
+	int gpot = 0;
+	int bpot = 0;
+	bool clapper=false;
 	while(1){
-		int rpot, gpot, bpot;
-		lcd.setCursor(0,0);
-		lcd.print(" RED GREEN BLUE ");
-		rpot=analogRead(A3);
-		lcd.setCursor(1,1);
-		lcd.print(rpot*10/102);
 		if(consolidate()==LEFT) return;
-		lcd.print(" ");
-		gpot=analogRead(A4);
-		lcd.setCursor(6,1);
-		lcd.print(gpot*10/102);
-		if(consolidate()==LEFT) return;
-		lcd.print(" ");
-		bpot=analogRead(A5);
-		lcd.setCursor(12,1);
-		lcd.print(bpot*10/102);
-		if(consolidate()==LEFT) return;
-		lcd.print(" ");
-		apply(rpot/4,gpot/4,bpot/4);	
+		if(consolidate()==DOWN) clapper=true; //enter clap mode by pressing down
+		if(rpot!=analogRead(A3)){
+			lcd.setCursor(1,1);
+			lcd.print(rpot*10/102);
+			lcd.print(" ");
+			rpot=analogRead(A3);
+		}
+		if(gpot!=analogRead(A4)){
+			gpot=analogRead(A4);
+			lcd.setCursor(6,1);
+			lcd.print(gpot*10/102);
+			lcd.print(" ");
+		}
+		if(bpot!=analogRead(A5)){
+			bpot=analogRead(A5);
+			lcd.setCursor(12,1);
+			lcd.print(bpot*10/102);
+			lcd.print(" ");
+		}
+		apply(rpot/4,gpot/4,bpot/4);
+		if(clapper){
+			boolean lightState = false;
+			int relay = 13;
+			int claps = 0;
+			long detectionSpanInitial = 0;
+			long detectionSpan = 0;
+			pinMode(A1, INPUT);
+			pinMode(relay, OUTPUT);
+			while(analogRead(A5)!=0){ //exit clap mode by turning red to 0
+				int sensorState = digitalRead(A1);
+				if (sensorState == 1){
+					if (claps == 0){
+						detectionSpanInitial = detectionSpan = millis();
+						claps++;
+					}
+					else if (claps > 0 && millis()-detectionSpan >= 50)
+					{
+					  detectionSpan = millis();
+					  claps++;
+					}
+				}
+				if (millis()-detectionSpanInitial >= 400){
+					if (claps == 2){
+						if (!lightState){
+							lightState = true;
+							digitalWrite(relay, HIGH);
+							apply(rpot/4,gpot/4,bpot/4);
+						}
+					    else if (lightState){
+							lightState = false;
+							digitalWrite(relay, LOW);
+							apply(0,0,0);
+					    }
+					}
+					claps = 0;
+				}
+			}
+			clapper=false;
+		}
 	}
 }
 

		    				lcd.print("               ");
		    				customCol();
		    				break;
			    		case 2:  // Fade
		    				delay(500);
		    				lcd.setCursor(0,0);

	pinMode(10,OUTPUT);
	pinMode(11,OUTPUT);
	analogReference(EXTERNAL);
	Serial.begin(9600);
}

void establishContact() {
