 float irSensorVal=0;
 
 int irDelta=100;
-int irBase=20;
-int irMax=230;
+int irBase=25;
+int irMax=200;
 
 
 int t1=0;
 int t2=0;
 
 int state=0; // 0= off, 1 = on
+int handposition=0; // 0 = off, 1 = on
+
+int dimMode=0;
+int minDim=5;
+int maxDim=255;
+int dimVal=200;
 int readyForChange=1;
 
 
 int pwmOut=9;
 
 unsigned long lastTime;
-int timeDelta=50;
+int timeDelta=500;
 
 
 void switchState(){


  unsigned long thisTime= millis();
  
  if( thisTime >= lastTime + timeDelta){
    Serial.print(thisTime);
    Serial.println("BINGO");
    
    lastTime=thisTime;
    
  }
  
  readIR();


  if( irSensorVal >= (t1 + irDelta) ){
    switchState();
  }

  if(irSensorVal <  (t1 + irDelta) ){
     readyForChange=1; 
  }


  
  if(state == 1){
    analogWrite(pwmOut,200);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255  
  }else if(state == 0){
    analogWrite(pwmOut,0);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255  


    irSensorVal = irSensorVal*10;

    irSensorVal = map(irSensorVal, irBase, irMax, 0, 1000);

    if(irSensorVal > 1000){
      irSensorVal = 1000;
    }
    
}

