   //read lasers
   for (int i = 0; i < 6; i++) {
     boolean blocked = false;
-    if (analogRead(laser_pins[i]) > LASER_ANALOG_TH)
+
+    int a = analogRead(laser_pins[i]);
+//    if (i==1){
+//    send_midi_debug(i, (int)((float)a / 8));
+//    send_midi_debug(i, (int)((float)LASER_ANALOG_TH[i] / 8));
+//    delay(100);
+//    }
+    if (a > LASER_ANALOG_TH[i]+5)
       blocked = true;
-
+    else {
+      int delta = (int)((a - LASER_ANALOG_TH[i]) / 2);
+      if (delta < -1) delta = -1;
+      if (delta > 1) delta = 1;
+      LASER_ANALOG_TH[i] += delta; //update level of laser sensors dynamically
+    }
+      
     if (last_alaser_status[i] != blocked) { //status changed
+//      send_midi_debug(i, (int)((float)a / 8));
       last_alaser_status[i] = blocked;
       laser_common_analog(i, blocked);
     }


inline void laser_common_analog(int l_idx, boolean laser_blocked) {
  unsigned long us = micros();
  if (laser_blocked != laser_status[l_idx]) { //ISR invoked but status did not change from current, do not know why ISR is called -> ignore

    if (us > (laser_status_last_update_us[l_idx] + LASER_ANALOG_THOLD_US)) {

      laser_status[l_idx] = laser_blocked;


#define TUNING -12


//const int LASER_ANALOG_TH[] = {960, 920, 975, 711, 900, 975}; //for analog read of bpw34. 900-1023 means laser is blocked, 0-600 means laser hit diode
int LASER_ANALOG_TH[] = {1024, 1024, 1024, 1024, 1024, 1024}; //for analog read of bpw34. 900-1023 means laser is blocked, 0-600 means laser hit diode
#define LASER_ANALOG_EMPH 975 //for analog read of bpw34. 900-1023 means laser is blocked, 0-600 means laser hit diode
#define LASER_ANALOG_THOLD_US 500 //[us] fastest accepted laser state change to prevent noise, fast strum may not be accepted 
//off topic: measured fastest cadence of strumming is 120ms(120000us)
#define LASER_THOLD 1000 //[us]
#define STOP_THOLD 500000 //[us]
