     else {
       stillMillis = millis() - stillBegin;
       if (stillMillis > 250) {
-        int a = vraw[0]>>8;
-        int b = vraw[1]>>8;
-        int c = vraw[2]>>8;
-        unsigned char roll=0;
-        if (a>0x1d && a<0x3d && b>-10 && b<13 && c>0x12 && c<0x32)
-          {roll=1; dispLed(0x1,0x0f0, 30);}
-        else if (a>0x13 && a<0x37 && b>-13 && b<13 && c>(signed char)0xb3 && c<(signed char)0xd6)
-          {roll=2; dispLed(0x3, 0x0f0, 30);}
-        else if (a>(signed char)0xee && a<10 && b>(signed char)0xb1 && b<(signed char)0xd1 && c>(signed char)0xe6 && c<10)
-          {roll=3; dispLed(0x7, 0x0f0, 30);}
-        else if (a>(signed char)0xed && a<10 && b>0x30 && b<0x50 && c>(signed char)0xeb && c<10)
-          {roll=4; dispLed(0x17, 0x0f0, 30);}
-        else if (a>(signed char)0xc5 && a<(signed char)0xe0 && b>-10 && b<10 && c>0x1a && c<0x36)
-          {roll=5; dispLed(0x37, 0x0f0, 30);}
-        else if (a>(signed char)0xbb && a<(signed char)0xdb && b>-10 && b<10 && c>(signed char)0xbb && c<(signed char)0xdb)
-          {roll=6; dispLed(0x77, 0x0f0, 30);}
-        if (roll!=0 && !rollSent)
-        {
-          diceRollCharacteristic.setValue((diceId << 4) | roll);
-          rollSent = true;
+        if (moves < GOOD_ROLL) {
+          dispLed(0xff, 0x000, 0);
+          dispLed(0xff, 0xf00, 0);
+          moves=0;
+          for (int i=0; i<6; i++) maxMove[i]=0;
+        }
+        else if (!rollSent) {
+          int a = vraw[0]>>8;
+          int b = vraw[1]>>8;
+          int c = vraw[2]>>8;
+          unsigned char roll=0;
+          int disp=0;
+          if (a>0x1d && a<0x3d && b>-10 && b<13 && c>0x12 && c<0x32)
+            {roll=1; dispLed(0x1,0x0f0, 30);}
+          else if (a>0x13 && a<0x37 && b>-13 && b<13 && c>(signed char)0xb3 && c<(signed char)0xd6)
+            {roll=2; disp=0x3;}
+          else if (a>(signed char)0xee && a<10 && b>(signed char)0xb1 && b<(signed char)0xd1 && c>(signed char)0xe6 && c<10)
+            {roll=3; disp=0x7;}
+          else if (a>(signed char)0xed && a<10 && b>0x30 && b<0x50 && c>(signed char)0xeb && c<10)
+            {roll=4; disp=0x17;}
+          else if (a>(signed char)0xc5 && a<(signed char)0xe0 && b>-10 && b<10 && c>0x1a && c<0x36)
+            {roll=5; disp=0x37;}
+          else if (a>(signed char)0xbb && a<(signed char)0xdb && b>-10 && b<10 && c>(signed char)0xbb && c<(signed char)0xdb)
+            {roll=6; disp=0x77;}
+          if (roll!=0) {
+            dispLed(disp, 0x0f0, 50);
+            diceRollCharacteristic.setValue((diceId << 4) | roll);            
+            rollSent = true;
+          }
+          else
+          {
+            moves=0;
+            for (int i=0; i<6; i++) maxMove[i]=0;
+          }
+        } else { // rollSent
+          idleShow();
         }
       }
     }
   }
-  else stillMillis=0;
+  else
+  {
+    if (rollSent==true) {
+      moves=0;
+      for (int i=0; i<6; i++) maxMove[i]=0;
+    }
+    stillMillis=0;
+  }
   
   SERIAL_PRINT(movement);
   SERIAL_PRINT("\t");

  return seqNum;
}
bool rollSent = false;

// ************* IMU **************************************************
int16_t vraw[10]; // raw readings from IMU and info for sending via BLE
                  // [0:5]=AxAyAzGxGyGz, [6]=movement, [7]=stillMs, [8]=diceId, [9]=seqNum
int vprev[6];     // previous reading

int16_t movement=0;
unsigned long stillBegin;
unsigned long stillMillis=0;   // number of sequential zero movements


int16_t imuRead() {
  for (int i=0; i<6; i++) vprev[i] = vraw[i];
  CurieImu.getMotion6(&vraw[0], &vraw[1], &vraw[2], &vraw[3], &vraw[4], &vraw[5]);
  movement = 0;
  for (int i=0; i<6; i++) {
    int m = (abs(vprev[i]-vraw[i])) >> 8;
    if (m>movement) movement = m;
  }
  // movement is 8 bits
  int mask = 0x0;

  blePeripheral.setEventHandler(BLEConnected, connectHandler);
  blePeripheral.setEventHandler(BLEDisconnected, disconnectHandler);
  diceCommandCharacteristic.setEventHandler(BLEWritten, commandHandler);
  blePeripheral.begin();
  SERIAL_PRINTLN("Bluetooth device active, waiting for connections...");

  dispLed(0x01, 0x0f0, 500);      // 0 - green BLE setup done

  dispLed(0x02, 0xff0, 500);      // 1 - yellow IMU setup

  // *************** IMU Setup ***************************************
  // initialize device
  SERIAL_PRINTLN("Initializing IMU device...");
  CurieImu.initialize();
