     powerCache [i].put (power [i]);
     lastChannelSample [i] = channelSample [i];
     
+    if (powerCache [i].get (1) == 0) {
+      triggered [i] = false;
+    }
+
+    bool isDescending = true;
     for (short int j = 0; j < POWER_CACHE_LENGTH - 1; j++){
-      
-      if (powerCache [i].get (j) == 0) {
-        triggered [i] = false;
+      if (!triggered [i] && (powerCache [i].get (j - 1) > powerCache [i].get (j))) {
+        isDescending = false;
+        break;
       }
-      
-      if (!triggered [i]) {
-        if (powerCache [i].get (j + 1) >= powerCache [i].get (j) || j != POWER_CACHE_LENGTH - 2) {
-          break;
-        } else {
-#if MODE_JIRO
-          if (power [i] >= LIGHT_THRES) {
-            triggered [i] = true;
-            switch (i) {
-              case 0: Keyboard.print ('g'); break;
-              case 1: Keyboard.print ('h'); break;
-              case 2: Keyboard.print ('f'); break;
-              case 3: Keyboard.print ('j'); break;
-            }
-          }
-#else
-          if (power [i] >= HEAVY_THRES) {
-            triggered [i] = true;
-            switch (i) {
-              case 0: Keyboard.print ('t'); break;
-              case 1: Keyboard.print ('y'); break;
-              case 2: Keyboard.print ('r'); break;
-              case 3: Keyboard.print ('u'); break;
-            }
-          } else if (power [i] >= LIGHT_THRES) {
-            triggered [i] = true;
-            switch (i) {
-              case 0: Keyboard.print ('g'); break;
-              case 1: Keyboard.print ('h'); break;
-              case 2: Keyboard.print ('f'); break;
-              case 3: Keyboard.print ('j'); break;
-            }
-          }
+    }
+    if (isDescending) {
+      if (power [i] >= HEAVY_THRES) {
+        triggered [i] = true;
+        Keyboard.print (heavyKeys [i]);
+      } else if (power [i] >= LIGHT_THRES) {
+        triggered [i] = true;
+        Keyboard.print (lightKeys [i]);
+      }
+
+#if MODE_DEBUG
+    calcLastTime += micros () - lastTime;
 #endif
-        }
-      }
     }
     
 #if MODE_DEBUG


#include <Keyboard.h>
#include "cache.h"

int channelSample [CHANNELS];
int lastChannelSample [CHANNELS];

  }

#if MODE_DEBUG
  Serial.print(sampleLastTime);
  Serial.print('\t');
  Serial.print(calcLastTime);
  Serial.println ("");
#endif

