reverting freddy file

reverting freddy file

--- firmware/http-neopixel-freddy/freddy.ino
+++ firmware/http-neopixel-freddy/freddy.ino
@@ -128,6 +128,498 @@
         if(client.connected())
             return;
     }
+
+    //////////command processing////////////////////
+
+    if(loopRun.equals(STOP))
+    {
+        delay(100);
+    }
+    else if(loopRun.equals(ALLOFF))
+    {
+        allOff();
+        loopRun = STOP;
+    }
+    else if(loopRun.equals(HEARTEYES))
+    {
+        heartEyes();
+    }
+    else if(loopRun.equals(SPIRALEYES))
+    {
+        spiralEyes();
+    }
+    else if(loopRun.equals(SPARKLEEYES))
+    {
+        sparkleEyes();
+    }
+    else if(loopRun.equals(STATICHEARTEYES))
+    {
+        staticHeartEyes();
+    }
+    else if(loopRun.equals(RAINBOWEYES))
+    {
+        rainbowEyes();
+    }
+    else if(loopRun.equals(GLOWEYES))
+    {
+        glowEyes();
+    }
+    else if(loopRun.equals(WAKEUPEYES))
+    {
+        wakeUpEyes();
+    }
+    else if(loopRun.equals(FIRESPARKLE))
+    {
+        fireSparkle();
+    }
+    else if(loopRun.equals(FIREHEART))
+    {
+        fireHeart();
+    }
+    else if(loopRun.equals(FIRESPIRAL))
+    {
+        fireSpiral();
+    }
+    else if(loopRun.equals(RANDOM))
+    {
+        random();
+    }
+    else if(loopRun.equals(KEITHEYES))
+    {
+        keithEyes();
+    }
+    else
+    {
+        String("INVALID_ACTION").toCharArray(action, 64);
+        loopRun = STOP;
+    }
+}
+
+int keithEyes()
+{
+    uint32_t c1 = strip.Color(160, 160, 160);
+    uint32_t c2 = strip.Color(250, 0, 0);
+    uint32_t c3 = strip.Color(0, 0, 0);
+
+    int farLeftColor1[] = {1, 2, 3, 6, 5, 4, 12, 13, 14, 17, 16, 15, 26, 27, 28, 29, 32, 31, 30, 40, 41, 42, 45, 44, 43, 49, 50, 51};
+    int farLeftColor2[] = {0, 8, 7, 9, 11, 21, 18, 22, 25, 36, 33, 37, 39, 47, 46, 48};
+    int farLeftColor3[] = {10, 20, 19, 23, 24, 35, 34, 38};
+
+    int leftColor1[] = {2, 3, 5, 4, 13, 14, 16, 15, 22, 27, 28, 29, 31, 30, 41, 42, 44, 43, 50, 51};
+    int leftColor2[] = {0, 1, 8, 7, 6, 9, 12, 21, 17, 23, 26, 36, 32, 37, 40, 47, 46, 45, 48, 49};
+    int leftColor3[] = {10, 11, 20, 19, 18, 24, 25, 35, 34, 33, 38, 39};
+
+    int centerColor1[] = {0, 3, 8, 4, 9, 14, 21, 15, 22, 23, 28, 29, 36, 30, 37, 42, 47, 43, 48, 51};
+    int centerColor2[] = {1, 2, 7, 6, 5, 10, 13, 20, 16, 24, 27, 35, 31, 38, 41, 46, 45, 44, 49, 50};
+    int centerColor3[] = {11, 12, 19, 18, 17, 25, 26, 34, 33, 32, 39, 40};
+
+    int rightColor1[] = {0, 1, 8, 7, 9, 10, 21, 20, 22, 23, 24, 29, 36, 35, 37, 38, 47, 46, 48, 49};
+    int rightColor2[] = {2, 3, 6, 5, 4, 11, 14, 19, 15, 25, 28, 34, 30, 39, 42, 45, 44, 43, 50, 51};
+    int rightColor3[] = {12, 13, 18, 17, 16, 26, 27, 33, 32, 31, 40, 41};
+
+    int farRightColor1[] = {0, 1, 2, 8, 7, 6, 9, 10, 11, 21, 20, 19, 22, 23, 24, 25, 36, 35, 34, 37, 38, 39, 47, 46, 45, 48, 49, 50};
+    int farRightColor2[] = {3, 5, 4, 12, 14, 18, 15, 26, 29, 33, 30, 40, 42, 44, 43, 51};
+    int farRightColor3[] = {13, 17, 16, 27, 28, 32, 31, 41};
+
+    int downRightColor1[] = {0, 1, 2, 3, 8, 7, 6, 9, 10, 11, 21, 20, 19, 22, 23, 24, 36, 35, 34, 37, 38, 47, 46, 48, 49};
+    int downRightColor2[] = {5, 4, 12, 13, 14, 18, 15, 25, 29, 33, 30, 39, 45, 50, 51};
+    int downRightColor3[] = {17, 16, 26, 27, 28, 32, 31, 40, 41, 42, 44, 43};
+
+    int downMidRightColor1[] = {0, 1, 2, 3, 8, 7, 4, 9, 10, 14, 21, 20, 15, 22, 23, 29, 36, 35, 30, 37, 47, 48};
+    int downMidRightColor2[] = {6, 5, 11, 12, 13, 19, 16, 24, 28, 34, 31, 38, 42, 46, 43, 49, 50, 51};
+    int downMidRightColor3[] = {18, 17, 25, 26, 27, 33, 32, 39, 40, 41, 45, 44};
+
+    int downMidLeftColor1[] = {0, 1, 2, 3, 8, 5, 4, 9, 13, 14, 21, 16, 15, 22, 28, 29, 36, 31, 30, 42, 43, 51};
+    int downMidLeftColor2[] = {7, 6, 10, 11, 12, 20, 17, 23, 27, 35, 32, 37, 41, 47, 44, 48, 49, 50};
+    int downMidLeftColor3[] = {19, 18, 24, 25, 26, 34, 33, 38, 39, 40, 46, 45};
+
+    int downLeftColor1[] = {0, 1, 2, 3, 6, 5, 4, 12, 13, 14, 17, 16, 15, 27, 28, 29, 32, 31, 30, 41, 42, 44, 43, 50, 51};
+    int downLeftColor2[] = {8, 7, 9, 10, 11, 21, 18, 22, 26, 36, 33, 40, 45, 48, 49};
+    int downLeftColor3[] = {20, 19, 23, 24, 25, 35, 34, 37, 38, 39, 47, 46};
+
+    int blink1Color1[] = {4, 4, 9, 14, 21, 15, 22, 23, 28, 29, 36, 30, 37, 42, 47, 43, 48, 51};
+    int blink1Color2[] = {5, 6, 5, 10, 13, 20, 16, 24, 27, 35, 31, 38, 41, 46, 45, 44, 49, 50};
+    int blink1Color3[] = {0, 1, 2, 3, 11, 12, 19, 18, 17, 25, 26, 34, 33, 32, 39, 40};
+
+    int blink2Color1[] = {9, 14, 21, 15, 22, 23, 28, 29, 36, 30, 37, 42, 47, 43, 48, 51};
+    int blink2Color2[] = {10, 13, 20, 16, 24, 27, 35, 31, 38, 41, 46, 45, 44, 49, 50};
+    int blink2Color3[] = {0, 1, 2, 3, 8, 7, 6, 5, 4, 11, 12, 19, 18, 17, 25, 26, 34, 33, 32, 39, 40};
+
+    int blink3Color1[] = {15, 15, 22, 23, 28, 29, 36, 30, 37, 42, 47, 43, 48, 51};
+    int blink3Color2[] = {16, 16, 24, 27, 35, 31, 38, 41, 46, 45, 44, 49, 50};
+    int blink3Color3[] = {0, 1, 2, 3, 8, 7, 6, 5, 4, 9, 10, 11, 12, 13, 14, 19, 18, 17, 25, 26, 34, 33, 32, 39, 40};
+
+    int blink4Color1[] = {22, 29, 36, 30, 37, 42, 47, 43, 48, 51};
+    int blink4Color2[] = {31, 31, 38, 41, 46, 45, 44, 49, 50};
+    int blink4Color3[] = {0, 1, 2, 3, 8, 7, 6, 5, 4, 9, 10, 11, 12, 13, 14, 21, 20, 19, 18, 17, 16, 15, 23, 24, 25, 26, 27, 28, 34, 33, 32, 39, 40};
+
+    int blink5Color1[] = {37, 42, 47, 43, 48, 51};
+    int blink5Color2[] = {49, 50};
+    int blink5Color3[] = {0, 1, 2, 3, 8, 7, 6, 5, 4, 9, 10, 11, 12, 13, 14, 21, 20, 19, 18, 17, 16, 15, 22, 23, 24, 25, 26, 27, 28, 29, 36, 35, 32};
+
+    int blink6Color1[] = {};
+    int blink6Color2[] = {};
+    int blink6Color3[] = {0, 1, 2, 3, 8, 7, 6, 5, 4, 9, 10, 11, 12, 13, 14, 21, 20, 19, 18, 17, 16, 15, 22, 23, 24, 25, 26, 27, 28, 29, 36, 35, 34, 33, 32, 31, 30, 37, 38, 39, 40, 41, 42, 47, 46, 45, 44, 43, 48, 49, 50, 51};
+
+    setPixels(leftColor1, c1, ARRAYLEN(leftColor1));
+    setPixels(leftColor2, c2, ARRAYLEN(leftColor2));
+    setPixels(leftColor3, c3, ARRAYLEN(leftColor3));
+    strip.show();
+    delay(250); //2
+
+    setPixels(farLeftColor1, c1, ARRAYLEN(farLeftColor1));
+    setPixels(farLeftColor2, c2, ARRAYLEN(farLeftColor2));
+    setPixels(farLeftColor3, c3, ARRAYLEN(farLeftColor3));
+    strip.show();
+    delay(1000); //3
+
+    setPixels(leftColor1, c1, ARRAYLEN(leftColor1));
+    setPixels(leftColor2, c2, ARRAYLEN(leftColor2));
+    setPixels(leftColor3, c3, ARRAYLEN(leftColor3));
+    strip.show();
+    delay(250); //4
+
+    setPixels(centerColor1, c1, ARRAYLEN(centerColor1));
+    setPixels(centerColor2, c2, ARRAYLEN(centerColor2));
+    setPixels(centerColor3, c3, ARRAYLEN(centerColor3));
+    strip.show();
+    delay(250); //5
+
+    setPixels(rightColor1, c1, ARRAYLEN(rightColor1));
+    setPixels(rightColor2, c2, ARRAYLEN(rightColor2));
+    setPixels(rightColor3, c3, ARRAYLEN(rightColor3));
+    strip.show();
+    delay(250); //6
+
+    setPixels(farRightColor1, c1, ARRAYLEN(farRightColor1));
+    setPixels(farRightColor2, c2, ARRAYLEN(farRightColor2));
+    setPixels(farRightColor3, c3, ARRAYLEN(farRightColor3));
+    strip.show();
+    delay(1000); //7
+
+    setPixels(rightColor2, c2, ARRAYLEN(rightColor2));
+    setPixels(rightColor1, c1, ARRAYLEN(rightColor1));
+    setPixels(rightColor3, c3, ARRAYLEN(rightColor3));
+    strip.show();
+    delay(250); //8
+
+    setPixels(centerColor1, c1, ARRAYLEN(centerColor1));
+    setPixels(centerColor2, c2, ARRAYLEN(centerColor2));
+    setPixels(centerColor3, c3, ARRAYLEN(centerColor3));
+    strip.show();
+    delay(1000); //9
+
+    setPixels(blink1Color1, c1, ARRAYLEN(blink1Color1));
+    setPixels(blink1Color2, c2, ARRAYLEN(blink1Color2));
+    setPixels(blink1Color3, c3, ARRAYLEN(blink1Color3));
+    strip.show();
+    delay(50); //10
+
+    setPixels(blink2Color1, c1, ARRAYLEN(blink2Color1));
+    setPixels(blink2Color2, c2, ARRAYLEN(blink2Color2));
+    setPixels(blink2Color3, c3, ARRAYLEN(blink2Color3));
+    strip.show();
+    delay(50); //11
+
+    setPixels(blink3Color1, c1, ARRAYLEN(blink3Color1));
+    setPixels(blink3Color2, c2, ARRAYLEN(blink3Color2));
+    setPixels(blink3Color3, c3, ARRAYLEN(blink3Color3));
+    strip.show();
+    delay(50); //12
+
+    setPixels(blink4Color1, c1, ARRAYLEN(blink4Color1));
+    setPixels(blink4Color2, c2, ARRAYLEN(blink4Color2));
+    setPixels(blink4Color3, c3, ARRAYLEN(blink4Color3));
+    strip.show();
+    delay(50); //13
+
+    setPixels(blink5Color1, c1, ARRAYLEN(blink5Color1));
+    setPixels(blink5Color2, c2, ARRAYLEN(blink5Color2));
+    setPixels(blink5Color3, c3, ARRAYLEN(blink5Color3));
+    strip.show();
+    delay(50); //14
+
+    setPixels(blink6Color1, c1, ARRAYLEN(blink6Color1));
+    setPixels(blink6Color2, c2, ARRAYLEN(blink6Color2));
+    setPixels(blink6Color3, c3, ARRAYLEN(blink6Color3));
+    strip.show();
+    delay(150); //15
+
+    setPixels(blink5Color1, c1, ARRAYLEN(blink5Color1));
+    setPixels(blink5Color2, c2, ARRAYLEN(blink5Color2));
+    setPixels(blink5Color3, c3, ARRAYLEN(blink5Color3));
+    strip.show();
+    delay(50); //16
+
+    setPixels(blink4Color1, c1, ARRAYLEN(blink4Color1));
+    setPixels(blink4Color2, c2, ARRAYLEN(blink4Color2));
+    setPixels(blink4Color3, c3, ARRAYLEN(blink4Color3));
+    strip.show();
+    delay(50); //17
+
+    setPixels(blink3Color1, c1, ARRAYLEN(blink3Color1));
+    setPixels(blink3Color2, c2, ARRAYLEN(blink3Color2));
+    setPixels(blink3Color3, c3, ARRAYLEN(blink3Color3));
+    strip.show();
+    delay(50); //18
+
+    setPixels(blink2Color1, c1, ARRAYLEN(blink2Color1));
+    setPixels(blink2Color2, c2, ARRAYLEN(blink2Color2));
+    setPixels(blink2Color3, c3, ARRAYLEN(blink2Color3));
+    strip.show();
+    delay(50); //19
+
+    setPixels(blink1Color1, c1, ARRAYLEN(blink1Color1));
+    setPixels(blink1Color2, c2, ARRAYLEN(blink1Color2));
+    setPixels(blink1Color3, c3, ARRAYLEN(blink1Color3));
+    strip.show();
+    delay(50); //20
+
+    setPixels(centerColor1, c1, ARRAYLEN(centerColor1));
+    setPixels(centerColor2, c2, ARRAYLEN(centerColor2));
+    setPixels(centerColor3, c3, ARRAYLEN(centerColor3));
+    strip.show();
+    delay(1000); //21
+
+    setPixels(rightColor1, c1, ARRAYLEN(rightColor1));
+    setPixels(rightColor2, c2, ARRAYLEN(rightColor2));
+    setPixels(rightColor3, c3, ARRAYLEN(rightColor3));
+    strip.show();
+    delay(250); //22
+
+    setPixels(downRightColor1, c1, ARRAYLEN(downRightColor1));
+    setPixels(downRightColor2, c2, ARRAYLEN(downRightColor2));
+    setPixels(downRightColor3, c3, ARRAYLEN(downRightColor3));
+    strip.show();
+    delay(1000); //23
+
+    setPixels(downMidRightColor1, c1, ARRAYLEN(downMidRightColor1));
+    setPixels(downMidRightColor2, c2, ARRAYLEN(downMidRightColor2));
+    setPixels(downMidRightColor3, c3, ARRAYLEN(downMidRightColor3));
+    strip.show();
+    delay(250); //24
+
+    setPixels(downMidLeftColor1, c1, ARRAYLEN(downMidLeftColor1));
+    setPixels(downMidLeftColor2, c2, ARRAYLEN(downMidLeftColor2));
+    setPixels(downMidLeftColor3, c3, ARRAYLEN(downMidLeftColor3));
+    strip.show();
+    delay(250); //25
+
+    setPixels(downLeftColor1, c1, ARRAYLEN(downLeftColor1));
+    setPixels(downLeftColor2, c2, ARRAYLEN(downLeftColor2));
+    setPixels(downLeftColor3, c3, ARRAYLEN(downLeftColor3));
+    strip.show();
+    delay(1000); //26
+
+    setPixels(downMidLeftColor1, c1, ARRAYLEN(downMidLeftColor1));
+    setPixels(downMidLeftColor2, c2, ARRAYLEN(downMidLeftColor2));
+    setPixels(downMidLeftColor3, c3, ARRAYLEN(downMidLeftColor3));
+    strip.show();
+    delay(250); //27
+
+    setPixels(downMidRightColor1, c1, ARRAYLEN(downMidRightColor1));
+    setPixels(downMidRightColor2, c2, ARRAYLEN(downMidRightColor2));
+    setPixels(downMidRightColor3, c3, ARRAYLEN(downMidRightColor3));
+    strip.show();
+    delay(250); //28
+
+    setPixels(downRightColor1, c1, ARRAYLEN(downRightColor1));
+    setPixels(downRightColor2, c2, ARRAYLEN(downRightColor2));
+    setPixels(downRightColor3, c3, ARRAYLEN(downRightColor3));
+    strip.show();
+    delay(1000); //29
+
+    setPixels(downMidLeftColor1, c1, ARRAYLEN(downMidLeftColor1));
+    setPixels(downMidLeftColor2, c2, ARRAYLEN(downMidLeftColor2));
+    setPixels(downMidLeftColor3, c3, ARRAYLEN(downMidLeftColor3));
+    strip.show();
+    delay(250); //30
+
+    setPixels(downMidRightColor1, c1, ARRAYLEN(downMidRightColor1));
+    setPixels(downMidRightColor2, c2, ARRAYLEN(downMidRightColor2));
+    setPixels(downMidRightColor3, c3, ARRAYLEN(downMidRightColor3));
+    strip.show();
+    delay(250); //31
+
+    setPixels(downMidLeftColor1, c1, ARRAYLEN(downMidLeftColor1));
+    setPixels(downMidLeftColor2, c2, ARRAYLEN(downMidLeftColor2));
+    setPixels(downMidLeftColor3, c3, ARRAYLEN(downMidLeftColor3));
+    strip.show();
+    delay(1000); //32
+
+    setPixels(downMidRightColor1, c1, ARRAYLEN(downMidRightColor1));
+    setPixels(downMidRightColor2, c2, ARRAYLEN(downMidRightColor2));
+    setPixels(downMidRightColor3, c3, ARRAYLEN(downMidRightColor3));
+    strip.show();
+    delay(250); //33
+
+    setPixels(downRightColor1, c1, ARRAYLEN(downRightColor1));
+    setPixels(downRightColor2, c2, ARRAYLEN(downRightColor2));
+    setPixels(downRightColor3, c3, ARRAYLEN(downRightColor3));
+    strip.show();
+    delay(250); //34
+
+    setPixels(rightColor1, c1, ARRAYLEN(rightColor1));
+    setPixels(rightColor2, c2, ARRAYLEN(rightColor2));
+    setPixels(rightColor3, c3, ARRAYLEN(rightColor3));
+    strip.show();
+    delay(1000); //35
+
+    setPixels(centerColor1, c1, ARRAYLEN(centerColor1));
+    setPixels(centerColor2, c2, ARRAYLEN(centerColor2));
+    setPixels(centerColor3, c3, ARRAYLEN(centerColor3));
+    strip.show();
+    delay(250); //36
+
+    setPixels(downMidRightColor1, c1, ARRAYLEN(downMidRightColor1));
+    setPixels(downMidRightColor2, c2, ARRAYLEN(downMidRightColor2));
+    setPixels(downMidRightColor3, c3, ARRAYLEN(downMidRightColor3));
+    strip.show();
+    delay(1000); //37
+
+    setPixels(blink1Color1, c1, ARRAYLEN(blink1Color1));
+    setPixels(blink1Color2, c2, ARRAYLEN(blink1Color2));
+    setPixels(blink1Color3, c3, ARRAYLEN(blink1Color3));
+    strip.show();
+    delay(50); //38
+
+    setPixels(blink2Color1, c1, ARRAYLEN(blink2Color1));
+    setPixels(blink2Color2, c2, ARRAYLEN(blink2Color2));
+    setPixels(blink2Color3, c3, ARRAYLEN(blink2Color3));
+    strip.show();
+    delay(50); //39
+
+    setPixels(blink3Color1, c1, ARRAYLEN(blink3Color1));
+    setPixels(blink3Color2, c2, ARRAYLEN(blink3Color2));
+    setPixels(blink3Color3, c3, ARRAYLEN(blink3Color3));
+    strip.show();
+    delay(50); //40
+
+    setPixels(blink4Color1, c1, ARRAYLEN(blink4Color1));
+    setPixels(blink4Color2, c2, ARRAYLEN(blink4Color2));
+    setPixels(blink4Color3, c3, ARRAYLEN(blink4Color3));
+    strip.show();
+    delay(50); //41
+
+    setPixels(blink5Color1, c1, ARRAYLEN(blink5Color1));
+    setPixels(blink5Color2, c2, ARRAYLEN(blink5Color2));
+    setPixels(blink5Color3, c3, ARRAYLEN(blink5Color3));
+    strip.show();
+    delay(50); //42
+
+    setPixels(blink6Color1, c1, ARRAYLEN(blink6Color1));
+    setPixels(blink6Color2, c2, ARRAYLEN(blink6Color2));
+    setPixels(blink6Color3, c3, ARRAYLEN(blink6Color3));
+    strip.show();
+    delay(50); //43
+
+    setPixels(blink5Color1, c1, ARRAYLEN(blink5Color1));
+    setPixels(blink5Color2, c2, ARRAYLEN(blink5Color2));
+    setPixels(blink5Color3, c3, ARRAYLEN(blink5Color3));
+    strip.show();
+    delay(50); //44
+
+    setPixels(blink4Color1, c1, ARRAYLEN(blink4Color1));
+    setPixels(blink4Color2, c2, ARRAYLEN(blink4Color2));
+    setPixels(blink4Color3, c3, ARRAYLEN(blink4Color3));
+    strip.show();
+    delay(50); //45
+
+    setPixels(blink3Color1, c1, ARRAYLEN(blink3Color1));
+    setPixels(blink3Color2, c2, ARRAYLEN(blink3Color2));
+    setPixels(blink3Color3, c3, ARRAYLEN(blink3Color3));
+    strip.show();
+    delay(50); //46
+
+    setPixels(blink2Color1, c1, ARRAYLEN(blink2Color1));
+    setPixels(blink2Color2, c2, ARRAYLEN(blink2Color2));
+    setPixels(blink2Color3, c3, ARRAYLEN(blink2Color3));
+    strip.show();
+    delay(50); //47
+
+    setPixels(blink1Color1, c1, ARRAYLEN(blink1Color1));
+    setPixels(blink1Color2, c2, ARRAYLEN(blink1Color2));
+    setPixels(blink1Color3, c3, ARRAYLEN(blink1Color3));
+    strip.show();
+    delay(50); //48
+
+    setPixels(centerColor1, c1, ARRAYLEN(centerColor1));
+    setPixels(centerColor2, c2, ARRAYLEN(centerColor2));
+    setPixels(centerColor3, c3, ARRAYLEN(centerColor3));
+    strip.show();
+    delay(3000); //49
+
+    setPixels(blink1Color1, c1, ARRAYLEN(blink1Color1));
+    setPixels(blink1Color2, c2, ARRAYLEN(blink1Color2));
+    setPixels(blink1Color3, c3, ARRAYLEN(blink1Color3));
+    strip.show();
+    delay(50); //50
+
+    setPixels(blink2Color1, c1, ARRAYLEN(blink2Color1));
+    setPixels(blink2Color2, c2, ARRAYLEN(blink2Color2));
+    setPixels(blink2Color3, c3, ARRAYLEN(blink2Color3));
+    strip.show();
+    delay(50); //51
+
+    setPixels(blink3Color1, c1, ARRAYLEN(blink3Color1));
+    setPixels(blink3Color2, c2, ARRAYLEN(blink3Color2));
+    setPixels(blink3Color3, c3, ARRAYLEN(blink3Color3));
+    strip.show();
+    delay(50); //52
+
+    setPixels(blink4Color1, c1, ARRAYLEN(blink4Color1));
+    setPixels(blink4Color2, c2, ARRAYLEN(blink4Color2));
+    setPixels(blink4Color3, c3, ARRAYLEN(blink4Color3));
+    strip.show();
+    delay(50); //53
+
+    setPixels(blink5Color1, c1, ARRAYLEN(blink5Color1));
+    setPixels(blink5Color2, c2, ARRAYLEN(blink5Color2));
+    setPixels(blink5Color3, c3, ARRAYLEN(blink5Color3));
+    strip.show();
+    delay(50); //54
+
+    setPixels(blink6Color1, c1, ARRAYLEN(blink6Color1));
+    setPixels(blink6Color2, c2, ARRAYLEN(blink6Color2));
+    setPixels(blink6Color3, c3, ARRAYLEN(blink6Color3));
+    strip.show();
+    delay(50); //55
+
+    setPixels(blink5Color1, c1, ARRAYLEN(blink5Color1));
+    setPixels(blink5Color2, c2, ARRAYLEN(blink5Color2));
+    setPixels(blink5Color3, c3, ARRAYLEN(blink5Color3));
+    strip.show();
+    delay(50); //56
+
+    setPixels(blink4Color1, c1, ARRAYLEN(blink4Color1));
+    setPixels(blink4Color2, c2, ARRAYLEN(blink4Color2));
+    setPixels(blink4Color3, c3, ARRAYLEN(blink4Color3));
+    strip.show();
+    delay(50); //57
+
+    setPixels(blink3Color1, c1, ARRAYLEN(blink3Color1));
+    setPixels(blink3Color2, c2, ARRAYLEN(blink3Color2));
+    setPixels(blink3Color3, c3, ARRAYLEN(blink3Color3));
+    strip.show();
+    delay(50); //58
+
+    setPixels(blink2Color1, c1, ARRAYLEN(blink2Color1));
+    setPixels(blink2Color2, c2, ARRAYLEN(blink2Color2));
+    setPixels(blink2Color3, c3, ARRAYLEN(blink2Color3));
+    strip.show();
+    delay(50); //59
+
+    setPixels(blink1Color1, c1, ARRAYLEN(blink1Color1));
+    setPixels(blink1Color2, c2, ARRAYLEN(blink1Color2));
+    setPixels(blink1Color3, c3, ARRAYLEN(blink1Color3));
+    strip.show();
+    delay(50); //60
+
+    setPixels(centerColor1, c1, ARRAYLEN(centerColor1));
+    setPixels(centerColor2, c2, ARRAYLEN(centerColor2));
+    setPixels(centerColor3, c3, ARRAYLEN(centerColor3));
+    strip.show();
+    delay(1000); //61
 }

 void setPixels(int pix[], uint32_t color, int arrlen)
@@ -156,9 +648,629 @@
     }
 }

+
+int random()
+{
+    /*
+    0#define HEARTEYES "hearteyes"
+    1#define SPIRALEYES "spiraleyes"
+    2#define SPARKLEEYES "sparkleeyes"
+    3#define STATICHEARTEYES "statichearteyes"
+    4#define RAINBOWEYES "rainboweyes"
+    5#define WAKEUPEYES "wakeupeyes"
+    6#define GLOWEYES "gloweyes"*/
+    int r = random(6);
+    allOff();
+    switch (r)
+    {
+        case 0:
+            heartEyes();
+            break;
+        case 1:
+            spiralEyes();
+            break;
+        case 2:
+            sparkleEyes();
+            break;
+        case 3:
+            staticHeartEyes();
+            break;
+        case 4:
+            rainbowEyes();
+            break;
+        case 5:
+            wakeUpFreddy();
+            break;
+        case 6:
+            glowEyes();
+            break;
+        default:
+            staticHeartEyes();
+            break;
+    }
+}
+
+void HSIOn()
+{
+    digitalWrite(D4, HIGH); //turn on hot surface igniter
+}
+
+void HSIOff()
+{
+    digitalWrite(D4, LOW); //turn off hot surface igniter
+}
+
+void gasOn()
+{
+    digitalWrite(D5, HIGH);
+}
+
+void gasOff()
+{
+    digitalWrite(D5, LOW);
+}
+
+int fireHeart()
+{
+    allOff();
+    HSIOn();
+    drawHeartEye(35, 0, 60);
+    strip.show();
+    delay(500);
+    drawHeartEye(0, 255, 0);
+    strip.show();
+    delay(300);
+    drawHeartEye(35, 0, 60);
+    strip.show();
+    delay(300);
+    drawHeartEye(0, 255, 0);
+    strip.show();
+    delay(300);
+    drawHeartEye(35, 0, 60);
+    strip.show();
+    delay(300);
+    drawHeartEye(0, 255, 0);
+    strip.show();
+    delay(300);
+    drawHeartEye(35, 0, 60);
+    strip.show();
+    delay(500);
+    gasOn();
+    drawHeartEye(35, 0, 60);
+    strip.show();
+    delay(1000);
+    gasOff();
+    HSIOff();
+    loopRun = STOP;
+}
+
+int fireSpiral()
+{
+    HSIOn();
+    for(int i=0; i<10; i++)
+        spiralFreddy(random(128), random(128), random(255), random(50), random(50), random(50));
+
+    gasOn();
+    delay(200);
+    gasOff();
+    delay(200);
+    gasOn();
+    delay(200);
+    gasOff();
+    delay(200);
+    gasOn();
+    delay(200);
+    gasOff();
+    HSIOff();
+    blink(50);
+    narrowEyes(50);
+    loopRun = STOP;
+}
+
+int fireSparkle()
+{
+    HSIOn();
+
+    fadeColor(255, 0, 0, 0, 0, 0, 50, 3000);
+
+    //turn on the gas
+    gasOn();
+
+    for(int j=0; j<30; j++)
+    {
+        int cnt = 10;
+        int pixNums[cnt];
+        for(int i=0; i<cnt; i++)
+        {
+            int pix = random(strip.numPixels());
+            pixNums[i] = pix;
+            strip.setPixelColor(pix, strip.Color(random(255),random(255),random(255)));
+        }
+        strip.show();
+        delay(30);
+        for(int i=0; i<cnt; i++)
+        {
+            int pix = pixNums[i];
+            strip.setPixelColor(pix, strip.Color(255,0,0));
+        }
+        strip.show();
+        delay(30);
+    }
+
+    HSIOff();
+    gasOff();
+
+    delay(100);
+    blink(100);
+    narrowEyes(100);
+
+    // loopRun = RANDOM;
+    loopRun = STOP;
+}
+
+int heartEyes()
+{
+    drawHeartEye(35, 0, 60);
+    strip.show();
+    delay(100);
+    return 1;
+}
+
+int spiralEyes()
+{
+    for(int i=0; i<50; i++)
+        spiralFreddy(random(128), random(128), random(255), random(50), random(50), random(50));
+    return 1;
+}
+
+int sparkleEyes()
+{
+    sparkleFreddy();
+    delay(100);
+    return 1;
+}
+
+int staticHeartEyes()
+{
+    heartEyeFreddy(75, 0, 130);
+    delay(100);
+    return 1;
+}
+
+int rainbowEyes()
+{
+    rainbow(20);
+    delay(100);
+    return 1;
+}
+
+int wakeUpEyes()
+{
+    wakeUpFreddy();
+    delay(1000);
+    return 1;
+}
+
+int glowEyes()
+{
+    glowEyeFreddy(20);
+    delay(1000);
+    return 1;
+}
+
 int allOff()
 {
     return setAll(0,0,0);
+}
+
+
+///////////////////////////////////////IMP///////////////////////////////////////
+
+int setRow(int row, int eye, uint8_t r, uint8_t g, uint8_t b)
+{
+    int offset = 0;
+    if(eye != 0)
+        offset = EYE_PIXEL_COUNT;
+
+    if(row == 0)
+    { //4 pix
+        for(int i=0; i<4; i++)
+            strip.setPixelColor(i + offset, strip.Color(r, g, b));
+    }
+    else if(row == 1)
+    { //5 pix
+        for(int i=4; i<9; i++)
+            strip.setPixelColor(i + offset, strip.Color(r, g, b));
+    }
+    else if(row == 2)
+    { //6 pix
+        for(int i=9; i<15; i++)
+            strip.setPixelColor(i + offset, strip.Color(r, g, b));
+    }
+    else if(row == 3)
+    { //7 pix
+        for(int i=15; i<22; i++)
+            strip.setPixelColor(i + offset, strip.Color(r, g, b));
+    }
+    else if(row == 4)
+    { //8 pix, middle row
+        for(int i=22; i<30; i++)
+            strip.setPixelColor(i + offset, strip.Color(r, g, b));
+    }
+    else if(row == 5)
+    { //7 pix
+        for(int i=30; i<37; i++)
+            strip.setPixelColor(i + offset, strip.Color(r, g, b));
+    }
+    else if(row == 6)
+    { //6 pix
+        for(int i=37; i<43; i++)
+            strip.setPixelColor(i + offset, strip.Color(r, g, b));
+    }
+    else if(row == 7)
+    { //5 pix
+        for(int i=43; i<48; i++)
+            strip.setPixelColor(i + offset, strip.Color(r, g, b));
+    }
+    else if(row == 8)
+    { //4 pix
+        for(int i=48; i<52; i++)
+            strip.setPixelColor(i + offset, strip.Color(r, g, b));
+    }
+    strip.show();
+}
+
+int closeEyes(int del)
+{
+    // drawPupil(0, 0, 255, 0);  drawPupil(1, 0, 255, 0);
+    setRow(0, 0, 255, 0, 0);  setRow(0, 1, 255, 0, 0);
+    setRow(8, 0, 255, 0, 0);  setRow(8, 1, 255, 0, 0);
+    delay(del);
+    // drawPupil(0, 0, 255, 0);  drawPupil(1, 0, 255, 0);
+    setRow(1, 0, 255, 0, 0);  setRow(1, 1, 255, 0, 0);
+    setRow(7, 0, 255, 0, 0);  setRow(7, 1, 255, 0, 0);
+    delay(del);
+    // drawPupil(0, 0, 255, 0);  drawPupil(1, 0, 255, 0);
+    setRow(2, 0, 255, 0, 0);  setRow(2, 1, 255, 0, 0);
+    setRow(6, 0, 255, 0, 0);  setRow(6, 1, 255, 0, 0);
+    delay(del);
+    // drawPupil(0, 0, 255, 0);  drawPupil(1, 0, 255, 0);
+    setRow(3, 0, 255, 0, 0);  setRow(3, 1, 255, 0, 0);
+    setRow(5, 0, 255, 0, 0);  setRow(5, 1, 255, 0, 0);
+    delay(del);
+    // drawPupil(0, 0, 255, 0);  drawPupil(1, 0, 255, 0);
+    setRow(4, 0, 255, 0, 0);  setRow(4, 1, 255, 0, 0);
+}
+
+int openEyes(int del)
+{
+    setRow(4, 0, 0, 0, 0);  setRow(4, 1, 0, 0, 0);
+    drawPupilsRow(2, 0, 255, 0);
+    strip.show();
+
+    delay(del);
+    setRow(3, 0, 0, 0, 0);  setRow(3, 1, 0, 0, 0);
+    setRow(5, 0, 0, 0, 0);  setRow(5, 1, 0, 0, 0);
+    drawPupilsRow(1, 0, 255, 0);
+    drawPupilsRow(3, 0, 255, 0);
+    strip.show();
+
+    delay(del);
+    setRow(2, 0, 0, 0, 0);  setRow(2, 1, 0, 0, 0);
+    setRow(6, 0, 0, 0, 0);  setRow(6, 1, 0, 0, 0);
+    drawPupilsRow(0, 0, 255, 0);
+    drawPupilsRow(4, 0, 255, 0);
+    strip.show();
+
+    delay(del);
+    setRow(1, 0, 0, 0, 0);  setRow(1, 1, 0, 0, 0);
+    setRow(7, 0, 0, 0, 0);  setRow(7, 1, 0, 0, 0);
+    delay(del);
+    setRow(0, 0, 0, 0, 0);  setRow(0, 1, 0, 0, 0);
+    setRow(8, 0, 0, 0, 0);  setRow(8, 1, 0, 0, 0);
+    delay(del);
+}
+
+int narrowEyes(int del)
+{
+    closeEyes(del);
+
+    setRow(4, 0, 0, 0, 0);  setRow(4, 1, 0, 0, 0);
+    drawPupilsRow(2, 0, 255, 0);
+    strip.show();
+
+    delay(del);
+    setRow(3, 0, 0, 0, 0);  setRow(3, 1, 0, 0, 0);
+    setRow(5, 0, 0, 0, 0);  setRow(5, 1, 0, 0, 0);
+    drawPupilsRow(1, 0, 255, 0);
+    drawPupilsRow(3, 0, 255, 0);
+    strip.show();
+}
+
+
+int drawPupilRow(int eye, int row, uint8_t r, uint8_t g, uint8_t b)
+{
+    int offset = 0;
+    if(eye != 0)
+        offset = EYE_PIXEL_COUNT;
+    int row0[] = {11, 12};
+    int row1[] = {17, 18, 19};
+    int row2[] = {24, 25, 26, 27};
+    int row3[] = {32, 33, 34};
+    int row4[] = {39, 40};
+
+    if(row == 0)
+        for(int i=0; i<ARRAYLEN(row0); i++)
+            strip.setPixelColor(row0[i] + offset, strip.Color(r, g, b));
+    else if(row == 1)
+        for(int i=0; i<ARRAYLEN(row1); i++)
+            strip.setPixelColor(row1[i] + offset, strip.Color(r, g, b));
+    else if(row == 2)
+        for(int i=0; i<ARRAYLEN(row2); i++)
+            strip.setPixelColor(row2[i] + offset, strip.Color(r, g, b));
+    else if(row == 3)
+        for(int i=0; i<ARRAYLEN(row3); i++)
+            strip.setPixelColor(row3[i] + offset, strip.Color(r, g, b));
+    else if(row == 4)
+        for(int i=0; i<ARRAYLEN(row4); i++)
+            strip.setPixelColor(row4[i] + offset, strip.Color(r, g, b));
+}
+
+int drawPupilsRow(int row, uint8_t r, uint8_t g, uint8_t b)
+{
+    drawPupilRow(0, row, r, g, b);
+    drawPupilRow(1, row, r, g, b);
+}
+
+int drawPupil(int eye, uint8_t r, uint8_t g, uint8_t b)
+{
+    for(int i=0; i<5; i++)
+        drawPupilRow(eye, i, r, g, b);
+}
+
+int drawPupils(uint8_t r, uint8_t g, uint8_t b)
+{
+    drawPupil(0, r, g, b);
+    drawPupil(1, r, g, b);
+}
+
+int blink(int del)
+{
+    closeEyes(del);
+    delay(200);
+    openEyes(del);
+}
+
+int wakeUpFreddy()
+{
+    int blinkDel = 10;
+
+    narrowEyes(100);
+    delay(2000);
+    blink(blinkDel);
+    delay(random(1000));
+    blink(blinkDel);
+    blink(blinkDel);
+    delay(random(2000));
+    blink(blinkDel);
+    delay(random(2000));
+    blink(blinkDel);
+    blink(blinkDel);
+    delay(random(1000));
+    closeEyes(50);
+    delay(random(1000));
+    blink(blinkDel);
+    delay(5000);
+}
+
+int glowEyeFreddy(int del)
+{
+    for(int j=0; j<10; j++)
+    {
+        for(int i=30; i>0; i--)
+        {
+            drawPupils(75 / i, 0, 130 / i);
+            strip.show();
+            delay(20);
+        }
+
+        for(int i=1; i<30; i++)
+        {
+            drawPupils(75 / i, 0, 130 / i);
+            strip.show();
+            delay(20);
+        }
+    }
+}
+
+int drawHeartRow(int eye, int row, uint8_t r, uint8_t g, uint8_t b)
+{
+    int offset = 0;
+    if(eye != 0)
+        offset = EYE_PIXEL_COUNT;
+    int row0[] = {4, 5, 7, 8};
+    int row1[] = {9, 10, 11, 12, 13, 14};
+    int row2[] = {16, 17, 18, 19, 20};
+    int row3[] = {23, 24, 25, 26, 27, 28};
+    int row4[] = {31, 32, 33, 34, 35};
+    int row5[] = {38, 39, 40, 41};
+    int row6[] = {44, 45, 46};
+    int row7[] = {49, 50};
+
+    if(row == 0)
+        for(int i=0; i<ARRAYLEN(row0); i++)
+            strip.setPixelColor(row0[i] + offset, strip.Color(r, g, b));
+    else if(row == 1)
+        for(int i=0; i<ARRAYLEN(row1); i++)
+            strip.setPixelColor(row1[i] + offset, strip.Color(r, g, b));
+    else if(row == 2)
+        for(int i=0; i<ARRAYLEN(row2); i++)
+            strip.setPixelColor(row2[i] + offset, strip.Color(r, g, b));
+    else if(row == 3)
+        for(int i=0; i<ARRAYLEN(row3); i++)
+            strip.setPixelColor(row3[i] + offset, strip.Color(r, g, b));
+    else if(row == 4)
+        for(int i=0; i<ARRAYLEN(row4); i++)
+            strip.setPixelColor(row4[i] + offset, strip.Color(r, g, b));
+    else if(row == 5)
+        for(int i=0; i<ARRAYLEN(row5); i++)
+            strip.setPixelColor(row5[i] + offset, strip.Color(r, g, b));
+    else if(row == 6)
+        for(int i=0; i<ARRAYLEN(row6); i++)
+            strip.setPixelColor(row6[i] + offset, strip.Color(r, g, b));
+    else if(row == 7)
+        for(int i=0; i<ARRAYLEN(row7); i++)
+            strip.setPixelColor(row7[i] + offset, strip.Color(r, g, b));
+}
+
+int drawHeartEye(uint8_t r, uint8_t g, uint8_t b)
+{
+    for(int i=0; i<8; i++)
+    {
+        drawHeartRow(0, i, r, g, b);
+        drawHeartRow(1, i, r, g, b);
+    }
+    strip.show();
+}
+
+int heartEyeFreddy(uint8_t r, uint8_t g, uint8_t b)
+{
+    int del = 5;
+    for(int j=0; j<10; j++)
+    {
+        for(int k=0; k<2; k++)
+        {
+            for(int i=20; i>0; i--)
+            {
+                drawHeartEye(75 / i, 0, 130 / i);
+                strip.show();
+                delay(del);
+            }
+
+            for(int i=1; i<20; i++)
+            {
+                drawHeartEye(75 / i, 0, 130 / i);
+                strip.show();
+                delay(del);
+            }
+        }
+
+        delay(1000);
+    }
+
+    // for(int i=0; i<50; i++)
+    // {
+    //     drawHeartEye(random(128), random(128), random(128));
+    //     strip.show();
+    //     delay(60);
+    //     drawHeartEye(0, 0, 0);
+    //     strip.show();
+    //     delay(60);
+    // }
+
+    drawHeartEye(75, 0, 130);
+    strip.show();
+}
+
+int sparkleFreddy()
+{
+    closeEyes(100);
+    delay(1000);
+    blink(100);
+    closeEyes(100);
+    for(int j=0; j<100; j++)
+    {
+        int cnt = 10;
+        int pixNums[cnt];
+        for(int i=0; i<cnt; i++)
+        {
+            int pix = random(strip.numPixels());
+            pixNums[i] = pix;
+            strip.setPixelColor(pix, strip.Color(255,255,255));
+        }
+        strip.show();
+        delay(30);
+        for(int i=0; i<cnt; i++)
+        {
+            int pix = pixNums[i];
+            strip.setPixelColor(pix, strip.Color(255,0,0));
+        }
+        strip.show();
+        delay(30);
+    }
+    blink(100);
+    openEyes(100);
+    delay(2000);
+}
+
+int spiralFreddy(uint8_t r, uint8_t g, uint8_t b, uint8_t r1, uint8_t g1, uint8_t b1)
+{
+    int offset = EYE_PIXEL_COUNT;
+    int del = 50;
+
+    int order[] = {18, 25, 33, 26, 11, 24, 17, 32, 39, 40, 34, 27, 19, 12, 5, 10, 16, 31, 38, 44, 45, 46, 41, 35, 20, 13, 7, 6, 1, 0, 4, 9, 23, 37, 43, 48, 49, 50, 51, 47, 42, 28, 14, 8, 3, 2};
+    int order0[] = {18, 25, 33, 26};
+    int order1[] = {11, 17, 24, 32, 39, 40, 34, 27, 19, 12};
+    int order2[] = {5, 10, 16, 31, 38, 44, 45, 46, 41, 35, 20, 13, 7, 6};
+    int order3[] = {1, 0, 4, 9, 23, 37, 43, 48, 49, 50, 51, 47, 42, 28, 14, 8, 3, 2};
+    for(int i=0; i<ARRAYLEN(order0); i++)
+    {
+        strip.setPixelColor(order0[i], strip.Color(r, g, b));
+        strip.setPixelColor(order0[i] + offset, strip.Color(r, g, b));
+    }
+    strip.show();
+    delay(del);
+    for(int i=0; i<ARRAYLEN(order1); i++)
+    {
+        strip.setPixelColor(order1[i], strip.Color(r + 10, g + 10, b + 10));
+        strip.setPixelColor(order1[i] + offset, strip.Color(r + 10, g + 10, b + 10));
+    }
+    strip.show();
+    delay(del);
+    for(int i=0; i<ARRAYLEN(order2); i++)
+    {
+        strip.setPixelColor(order2[i], strip.Color(r + 20, g + 20, b + 20));
+        strip.setPixelColor(order2[i] + offset, strip.Color(r + 20, g + 20, b + 20));
+    }
+    strip.show();
+    delay(del);
+    for(int i=0; i<ARRAYLEN(order3); i++)
+    {
+        strip.setPixelColor(order3[i], strip.Color(r + 30, g + 30, b + 30));
+        strip.setPixelColor(order3[i] + offset, strip.Color(r + 30, g + 30, b + 30));
+    }
+    strip.show();
+    delay(del);
+
+
+    for(int i=0; i<ARRAYLEN(order3); i++)
+    {
+        strip.setPixelColor(order3[i], strip.Color(r1, g1, b1));
+        strip.setPixelColor(order3[i] + offset, strip.Color(r1, g1, b1));
+    }
+    strip.show();
+    delay(del);
+    for(int i=0; i<ARRAYLEN(order2); i++)
+    {
+        strip.setPixelColor(order2[i], strip.Color(r1, g1, b1));
+        strip.setPixelColor(order2[i] + offset, strip.Color(r1, g1, b1));
+    }
+    strip.show();
+    delay(del);
+    for(int i=0; i<ARRAYLEN(order1); i++)
+    {
+        strip.setPixelColor(order1[i], strip.Color(r1, g1, b1));
+        strip.setPixelColor(order1[i] + offset, strip.Color(r1, g1, b1));
+    }
+    strip.show();
+    delay(del);
+    for(int i=0; i<ARRAYLEN(order0); i++)
+    {
+        strip.setPixelColor(order0[i], strip.Color(r1, g1, b1));
+        strip.setPixelColor(order0[i] + offset, strip.Color(r1, g1, b1));
+    }
+    strip.show();
+    delay(del);
 }

 int setRGB(String rgb)
@@ -178,6 +1290,34 @@
   }
   strip.show();
   return 1;
+}
+
+int rainbow(int d) {
+  uint16_t i, j;
+
+  for(j=0; j<256; j++) {
+    for(i=0; i<strip.numPixels(); i++) {
+      strip.setPixelColor(i, Wheel((i+j) & MAX_COLOR));
+  }
+  strip.show();
+  delay(d);
+}
+return 1;
+}
+
+// Input a value 0 to MAX_COLOR to get a color value.
+// The colours are a transition r - g - b - back to r.
+uint32_t Wheel(byte WheelPos) {
+  int maxVal = MAX_COLOR;
+  if(WheelPos < 85) {
+     return strip.Color(WheelPos * 3, maxVal - WheelPos * 3, 0);
+ } else if(WheelPos < 170) {
+     WheelPos -= 85;
+     return strip.Color(maxVal - WheelPos * 3, 0, WheelPos * 3);
+ } else {
+     WheelPos -= 170;
+     return strip.Color(0, WheelPos * 3, maxVal - WheelPos * 3);
+ }
 }

 bool stringToBool(String s)
@@ -218,3 +1358,30 @@
     return strArr;
 }

+int fadeColor(uint8_t r1, uint8_t g1, uint8_t b1,
+  uint8_t r2, uint8_t g2, uint8_t b2,
+  int del, int duration)
+{
+
+    int16_t redDiff = r2 - r1;
+    int16_t greenDiff = g2 - g1;
+    int16_t blueDiff = b2 - b1;
+
+    int16_t steps = duration / del;
+
+    int16_t redValue, greenValue, blueValue;
+
+    for (int16_t i = steps; i >= 0; i--) {
+        redValue = r1 + (redDiff * i / steps);
+        greenValue = g1 + (greenDiff * i / steps);
+        blueValue = b1 + (blueDiff * i / steps);
+
+        for (uint16_t i = 0; i < strip.numPixels(); i++) {
+            strip.setPixelColor(i, strip.Color(redValue, greenValue, blueValue));
+        }
+        strip.show();
+        delay(del);
+    }
+
+    return 1;
+}


- Re-add loop, was inadvertently removed - Add second pixel strand, currently only has one pixel in it

--- Fireflies/Fireflies.ino
+++ Fireflies/Fireflies.ino
@@ -9,13 +9,17 @@
 // Which pin on the Arduino is connected to the NeoPixels?
 // On a Trinket or Gemma we suggest changing this to 1
 const int pinNeopixels = 5;
-const int numNeopixels = 6;
-const bool newPixelsAreRgb = false                                                                                ;
+const int numNeopixels = 5;
+const bool newPixelsAreRgb = false;
+const int pinNeopixels2 = 3;
+const int numNeopixels2 = 1;
+const bool newPixelsAreRgb2 = true;

 // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
 // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
 // example for more information on possible values.
 auto pixels = Adafruit_NeoPixel(numNeopixels, pinNeopixels, (newPixelsAreRgb ? NEO_RGB : NEO_GRB) + NEO_KHZ800);
+auto pixels2 = Adafruit_NeoPixel(numNeopixels2, pinNeopixels2, (newPixelsAreRgb2 ? NEO_RGB : NEO_GRB) + NEO_KHZ800);

 struct Firefly
 {
@@ -50,18 +54,12 @@
 #endif
   // End of trinket special code

-  pixels.begin(); // This initializes the NeoPixel library.
+  pixels.begin();
+  pixels2.begin();
 }

-void setPixels(Color3F c, int from, int to, bool show, int brightness = 255)
-{
-  for (int i = from; i < to; i++)
-  {
-    pixels.setPixelColor(i, c.R * brightness, c.G * brightness, c.B * brightness);
-  }
-
-  if (show)
-  {
+void loop()
+{
   bool anyFirefliesActive = false;
   for (int i = 0; i < numNeopixels; i++)
   {
@@ -96,12 +94,15 @@

     int s = sin((float)firefly.progress / firefly.lifetime * PI) * 255;
     auto color = firefly.active ? firefly.color * s : Color3Fs::Black();
-    color = Color3Fs::White() * 255;

     pixels.setPixelColor(i, color.R, color.G, color.B);
   }

   pixels.show();
+  auto glowScale = (sin((millis() % 2000) / 2000.f * 2 * PI) / 4 + 0.75);
+  auto color2 = Color3F(255, 255, 64) * glowScale;
+  pixels2.setPixelColor(0, color2.R, color2.G, color2.B);
+  pixels2.show();

   delay(10);
 }


Couple of typos.

Couple of typos.

--- MAX72xx/Demo2/Demo2.ino
+++ MAX72xx/Demo2/Demo2.ino
@@ -8,7 +8,6 @@
 int x, y;

 void setup() {
-  // put your setup code here, to run once:
     Serial.begin(9600);
      matrix.setIntensity(0);
 }
@@ -21,10 +20,10 @@
   Serial.print(" ");
   Serial.println(y, DEC);

-  int matrix_y = map(y, 377, 476, 7, 0); // Maps values in the range
+  int matrix_y = map(y, 378, 479, 7, 0); // Maps values in the range
                                          // 377 to 476 to the range
                                          // 7 to 0
-  int matrix_x = map(x, 382, 479, 7, 0);
+  int matrix_x = map(x, 378, 479, 0, 7);

   matrix.fillScreen(0);   //Clear the screen
   matrix.drawPixel(matrix_x, matrix_y, HIGH);


Start changing complex for loops into a reversable global array.

--- ArduinoMotionStairLights.ino
+++ ArduinoMotionStairLights.ino
@@ -1,3 +1,9 @@
+/*
+ * Description: Motion activated stair lights.
+ * Author: Dean Montgomery
+ * Version: 0.1 (Alpha)
+*/
+
 #include "FastLED.h"
 /*
  * Jenn's colors RGB  0 0 81  BLUE
@@ -11,19 +17,22 @@
  * red to blue
  */
 #define NUM_LEDS 26
-#define BRIGHTNESS  120  // 0...255
+#define LEDS_PER_STAIR 2        // Number of Leds per stair.
+#define BRIGHTNESS  120         // 0...255  ( needed ?)
 #define UPDATES_PER_SECOND 100
-#define PIN_LED 3
-#define PIN_PIR_DOWN 5
-#define PIN_PIR_UP 7
-#define STEP_DELAY 200  //ms = 1/5th second.
-
-uint8_t lightsOn = LOW; // track lights on/off
+#define PIN_LED 3               // LED Data pin
+#define PIN_PIR_DOWN 5          // PIR Downstairs Pin
+#define PIN_PIR_UP 7            // PIR Upstairs Pin
+#define STEP_DELAY 200          //ms = 1/5th second. ( needed ?)
+#define GO_UP -1                // Direction control - Arduino at top of stairs
+#define GO_DOWN 1               // Direction control - Arduino at top of stairs
+int8_t lightsOn = LOW;          // track lights on/off
 uint8_t gHue = 0;
-uint8_t gStair = 0;
+int8_t gStair = 0;
 uint8_t gBright = 0;
-uint8_t gStairStart = 0;
-uint8_t gStairEnd = 0;
+int8_t gStairStart = 0;
+int8_t gStairEnd = 0;
+uint8_t gUpDown[NUM_LEDS];      // directional array to walk/loop up or down stairs.

 CRGB leds[NUM_LEDS];

@@ -41,21 +50,9 @@
   digitalWrite(PIN_PIR_DOWN, LOW);
   digitalWrite(PIN_PIR_UP, LOW);
   Serial.println(" done");
-  // Sparkle rainbow welcome give delay to calibrate pir sensors.  This also indicates if program crashed.
-  for ( int i = 0; i < 500; i++ ){
-    rainbowWithGlitter();
-    FastLED.show();
-    FastLED.delay(8.3);
-    EVERY_N_MILLISECONDS( 20 ) { gHue++; }
-  }
-  for (int tick=0; tick < 64; tick++){
-    for ( uint8_t i = 0; i < NUM_LEDS; i++ ){
-      leds[i].fadeToBlackBy( 64 );
-      FastLED.show();
-      FastLED.delay(1);
-    }
-  }
-    Serial.println("SENSOR ACTIVE");
+  welcomeRainbow();  // rainbow - give time for PIR sensors.
+  setUpDown(GO_DOWN);
+  Serial.println("SENSOR ACTIVE");
 }

 // Main Loop track PIR sensors.
@@ -64,9 +61,11 @@
   if ( digitalRead(PIN_PIR_UP) == HIGH ){
     if ( lightsOn == LOW ) {
       lightsOn = HIGH;
-      //fade7(1);
+      setUpDown(GO_DOWN);
+      // TODO: Add random pattern picker.
+      fade7();
       //walk(1);
-      flicker(1);
+      //flicker(1);
       delay(50);
     }
   }
@@ -74,13 +73,56 @@
   if ( digitalRead(PIN_PIR_DOWN) == HIGH  ){
     if ( lightsOn == LOW ) {
       lightsOn = HIGH;
-      //fade7(-1); //Up
+      setUpDown(GO_UP);
+      fade7(); //Up
       //walk(-1); // Up
-      flicker(-1);
+      //flicker(-1);
       delay(50);
     }
   }
 }
+
+void setUpDown(int8_t upDownDir){
+  // setup walking gUpDown array in forward: 0,1,2,3... or reverse:  ...3,2,1,0
+  gStairStart = 0;
+  if (upDownDir == GO_UP){
+    for ( gStair = NUM_LEDS -1; gStair >= 0; gStair-- ){
+      gUpDown[gStair] = gStairStart++;
+    }
+  } else {
+    for ( gStair = 0; gStair <= NUM_LEDS; gStair++ ){
+      gUpDown[gStair] = gStairStart++;
+    }
+  }
+  //printUpDown();
+}
+
+void printUpDown(){
+  for (gStair = 0; gStair < NUM_LEDS; gStair++){
+    Serial.print (gStair);
+    Serial.print (" " );
+    Serial.println (gUpDown[gStair]);
+  }
+}
+
+void welcomeRainbow(){
+  // Sparkle rainbow welcome give delay to calibrate pir sensors.  This also indicates if program crashed.
+  for ( int i = 0; i < 500; i++ ){
+    rainbowWithGlitter();
+    FastLED.show();
+    FastLED.delay(8.3);
+    EVERY_N_MILLISECONDS( 20 ) { gHue++; }
+  }
+  for (int tick=0; tick < 64; tick++){
+    for ( uint8_t i = 0; i < NUM_LEDS; i++ ){
+      leds[i].fadeToBlackBy( 64 );
+      FastLED.show();
+      FastLED.delay(1);
+    }
+  }
+}
+
+

 void walk(int8_t dir) {
   Serial.print("Walk dir: ");
@@ -245,20 +287,20 @@

 // Fade7 effect.
-void fade7(int8_t dir){
-  setStartEnd(dir);
-  Serial.print("Fade7 dir: ");
-  Serial.println(dir);
+void fade7(){
+  //setStartEnd(dir);
+  Serial.println("Fade7");
+  //Serial.println(dir);
   const uint8_t mx = BRIGHTNESS;
   uint8_t r = mx;
   uint8_t g = 0;
   uint8_t b = 0;
   const uint8_t del = 25;
   boolean glitter = ( random8() < 120 );
-  for(gStair=gStairStart; (dir == 1 && gStair < gStairEnd ) || (dir == -1 && gStair >= gStairEnd && gStair <= gStairStart+1 ); gStair+=(2*dir)) {
+  for (gStair=0; gStair < NUM_LEDS; gStair+=2){
     for (r=0; r<mx; r+=2) {
-      leds[gStair] = CRGB( r, g, b );
-      leds[gStair + 1*dir] = CRGB( r, g, b );
+      leds[gUpDown[gStair]] = CRGB( r, g, b );
+      leds[gUpDown[gStair + 1]] = CRGB( r, g, b );
       FastLED.show();
       FastLED.delay(1);
     }
@@ -306,16 +348,16 @@
     FastLED.show();
     delay(del);
   }
-  for(gStair=gStairStart; (dir == 1 && gStair <= gStairEnd ) || (dir == -1 && gStair >= gStairEnd && gStair <= gStairStart+1 ); gStair+=(2*dir)) {
+  for (gStair=0; gStair < NUM_LEDS; gStair+=2){
     for (r=mx; r>1; r--) {
-      leds[gStair] = CRGB( r, g, b );
-      leds[gStair + 1*dir] = CRGB( r, g, b );
+      leds[gUpDown[gStair]] = CRGB( r, g, b );
+      leds[gUpDown[gStair + 1]] = CRGB( r, g, b );
       FastLED.show();
       FastLED.delay(1);
     }
     r = 0; g = 0; b = 0;
-    leds[gStair] = CRGB( r, g, b );
-    leds[gStair + 1*dir] = CRGB( r, g, b );
+    leds[gUpDown[gStair]] = CRGB( r, g, b );
+    leds[gUpDown[gStair + 1]] = CRGB( r, g, b );
     FastLED.show();
   }
   lightsOn = LOW;


Update intro text

Update intro text

--- sheild_sdlog_gps_color_v3/sheild_sdlog_gps_color_v3.ino
+++ sheild_sdlog_gps_color_v3/sheild_sdlog_gps_color_v3.ino
@@ -6,15 +6,18 @@
 #include <Adafruit_TCS34725.h>
 #include <avr/sleep.h>

-// Code hacked together by Nick Meehan nick@unsalted.nu -
+// Code hacked together by Nick Meehan - unsalted.nu
 // In association with: Art Center College of Design - Media Design Practices - MFA
 //
 // This code is a combination of two code sets:
 // https://github.com/adafruit/Adafruit-GPS-Library/tree/master/examples/shield_sdlog
 // https://github.com/adafruit/Adafruit_TCS34725/tree/master/examples/tcs34725
 //
-// With additional help from: http://www.instructables.com/id/Personal-Black-Box-Arduino-Mega-Ultimate-GPS-Shiel/
-// The goal of this code is to map coordinates with color data taken by TCS34725
+// With additional help from:
+// http://www.instructables.com/id/Personal-Black-Box-Arduino-Mega-Ultimate-GPS-Shiel/
+//
+// The goal of this code was to map coordinates with color data taken by the TCS34725
+// to log street lamp types in Los Angeles.
 //
 //
 // Developed on the Adafruit Ultimate GPS + Logging Shield & TCS34725 RGB Color Sensor


switched naming scheme of receiving commands to directives (dir prefix) increased transfer rate by 150ms, gps back to 5hz update

--- onboard_controller/onboard_controller.ino
+++ onboard_controller/onboard_controller.ino
@@ -16,10 +16,12 @@
 #define FLAG_GPS_FIX 0b00000001
 #define FLAG_PAYLOAD 0b00000010

+//directives received from ground station
 //make sure these match on the sending end
-#define FLAG_PAYLOAD 0xAB
-
-#define PIN_PAYLOAD 13
+#define DIR_TEST 0xAB
+#define DIR_PAYLOAD 0xACDIR_TEST
+
+#define PIN_TEST 13

 //Payload variables
 #define MAX_BUF 16  // Maximum payload size
@@ -52,7 +54,7 @@

 void setup()
 {
-  pinMode(PIN_PAYLOAD, OUTPUT);
+  pinMode(PIN_TEST, OUTPUT);

   //Make sure Serial baud matches hardware config
   Serial1.begin(57600); //XBee baud rate
@@ -67,7 +69,7 @@
   //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);

   // Set update rate
-  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1/5 Hz
+  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ);   // 1/5 Hz

   // Request updates on antenna status
   GPS.sendCommand(PGCMD_ANTENNA);
@@ -102,13 +104,13 @@
   if (Serial1.available()) {
     byte receivedPayload = Serial1.read();
     switch (receivedPayload) {
-      case FLAG_PAYLOAD:
-        if ( digitalRead(PIN_PAYLOAD) == HIGH )
-          digitalWrite(PIN_PAYLOAD,LOW);
-        else digitalWrite(PIN_PAYLOAD,HIGH);
+      case DIR_TEST:
+        if ( digitalRead(PIN_TEST) == HIGH )
+          digitalWrite(PIN_TEST,LOW);
+        else digitalWrite(PIN_TEST,HIGH);
         break;
       default:
-        digitalWrite(PIN_PAYLOAD,LOW);
+        digitalWrite(PIN_TEST,LOW);
         break;
     }
     #ifdef readDebug
@@ -120,7 +122,7 @@

   // if millis() or timer wraps around, reset
   if (timer > millis())  timer = millis();
-  if (millis() - timer > 400) {
+  if (millis() - timer > 250) {
     timer = millis(); // reset the timer

     #ifdef fakeGPS //fake gps data
@@ -160,10 +162,9 @@

       //buffer size is the difference between the current and start pointers
       buf_size = buf_curr - buf_start;
-
+
+      //arduino is little endian (LSB first)
       Serial1.write(buf_start, buf_size);
-       delayMicroseconds(50);
-      //arduino is little endian (LSB first)

       #ifdef writeDebug
         //check that buffer size did not exceed allocated size


Working version of microcontroller sketch.

--- arduino/bubbles_controller/bubbles_controller.ino
+++ arduino/bubbles_controller/bubbles_controller.ino
@@ -7,7 +7,7 @@
 *  while tweet-contoller.py runs on the Linino.
 *
 *  Bubbles are triggered through following ways:
-*  1. A tweet has the hashtag #teambubble
+*  1. A tweet has the hashtag #teambubbles
 *  2. It has been 15 minutes since the last tweet
 *       (need to keep water moving)
 */
@@ -24,13 +24,24 @@
 int bubbleTime = 150;
 int bubbleThrottle = 5000;

-char tweetValue[2];    // incoming storage of tweet
+char tweetValue[4];    // incoming storage of tweet
 int lastTweetCount = 0; // keep track of number of tweets
-unsigned long lastBubble;
+unsigned long lastBubble;
+char tweetText[141];
+
+boolean debugMode = true;

 //---------------------------------------------
 void setup() {
   Bridge.begin();    // initialise Bridge
+
+  if(debugMode) {
+  // we don't want Serial when deployed
+  // it will make the microcontroller hang
+  // waiting for a response
+  Serial.begin(9600);
+  while ( !Serial );
+  }

   // set up pin modes
   pinMode( greenStatusLED, OUTPUT );
@@ -38,47 +49,61 @@
   pinMode( relay1, OUTPUT );
   pinMode( relay2, OUTPUT );

-  // initialise the timer for the last bubble
-  lastBubble = millis();
+  // startup bubble
+  // also initialises bubble timer
+  bubble();
 }

 //---------------------------------------------
 void loop() {
   // Read command output
-  Bridge.get("tweets", tweetValue, 2);
+  Bridge.get("tweets", tweetValue, 4);
+  Bridge.get("text", tweetText, 141);
   int tweets = atoi(tweetValue);
+  if(debugMode) {
+    Serial.println( tweets );
+    Serial.println( tweetText );
+  }
+
+  unsigned long currTime = millis();
+
+  // if new tweets or has been 15 minutes
+  if ( tweets != lastTweetCount ||
+        currTime - lastBubble > (1000*60*15) ) {
+    bubble();
+    lastTweetCount = tweets;
+  }
+  delay(1000);  // wait 1 second before you do it again

-
-  delay(5000);  // wait 5 seconds before you do it again
-
-  // startup bubble
-  bubble();
 }

 //---------------------------------------------
 void bubble() {
+  if(debugMode){
+    Serial.println("Bubbles!");
+  }
   // turn on status LED
   digitalWrite( greenStatusLED, HIGH );
   digitalWrite( yellowStatusLED, LOW );
-
+
   // trigger relay
   digitalWrite( relay1, HIGH );
   digitalWrite( relay2, HIGH );
-
+
   // wait to create bubbles
   delay( bubbleTime );
-
+
   // stop relay
   digitalWrite( relay1, LOW );
   digitalWrite( relay2, LOW );
-
+
   // update status LEDs
   digitalWrite( greenStatusLED, LOW);
   digitalWrite( yellowStatusLED, HIGH);
-
+
   // wait to throttle bubbling
   delay( bubbleThrottle );
-
-  // initialise the timer for the last bubble
+
+  // reset the timer for the last bubble
   lastBubble = millis();
 }


improved streaming code

improved streaming code

* whitespace fixes
* removed dead code
* ensure current is not negative
* removed “solar” from keys
* changed current to mA
* removed error strings
* stream rate increased to 125ms

--- Arduino/Combination_Readings/Combination_Readings.ino
+++ Arduino/Combination_Readings/Combination_Readings.ino
@@ -1,13 +1,8 @@
 #include <Wire.h>
-
 #include <Adafruit_10DOF.h>
-
 #include <Adafruit_Sensor.h>
-
 #include <Adafruit_L3GD20_U.h>
-
 #include <Adafruit_LSM303_U.h>
-
 #include <Adafruit_BMP085_U.h>

 Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
@@ -19,37 +14,16 @@
 const double smallR = 1.8;
 const int bigR = 18;

-void displaySensorDetails(void)
-{
-  sensor_t sensor;
-  accel.getSensor(&sensor);
-  /*Serial.println("------------------------------------");
-  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
-  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
-  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
-  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" m/s^2");
-  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" m/s^2");
-  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" m/s^2");
-  Serial.println("------------------------------------");
-  Serial.println("");*/
-  delay(500);
-}
-
 void setup(void) {
   Serial.begin(9600);
-  /*Serial.println("Sensor Test");
-  Serial.println("");*/
-
-  displaySensorDetails();

-  if (!bmp.begin() || !mag.begin() || !accel.begin())
-  {
+  if (!bmp.begin() || !mag.begin() || !accel.begin()) {
     Serial.print("Ooops, no BMP085 or LSM303 detected");
     while(1);
   }
 }
+
 void loop() {
-
   sensors_event_t eventP;
   sensors_event_t eventM;
   sensors_event_t eventA;
@@ -73,64 +47,42 @@
     heading = 360 + heading;
   }
   Serial.print("{");
-  Serial.print("\"solarpanelcurrent\": ");
-  Serial.print(current*1000,6);
+
+  Serial.print("\"current\": ");
+  Serial.print(current*1000);
   Serial.print(", ");
-  Serial.print("\"solarpanelpower\": ");
+
+  Serial.print("\"power\": ");
   Serial.print(power,6);
   Serial.print(", ");
+
   Serial.print("\"pressure\": ");
-  if (eventP.pressure)
-  {
-    Serial.print(eventP.pressure);
-  }
-  else
-  {
-    Serial.print("\"error\"");
-  }
-    Serial.print(", ");
-  if (temperature)
-  {
-    Serial.print("\"temperature\": ");
-    Serial.print(temperature);
-  }
-  else
-  {
-    Serial.println("\"error\"");
-  }
+  Serial.print(eventP.pressure);
   Serial.print(", ");
+
+  Serial.print("\"temperature\": ");
+  Serial.print(temperature);
+  Serial.print(", ");
+
   Serial.print("\"compass\": ");
-   if (heading)
-  {
-    Serial.print("[");
-    Serial.print(eventM.magnetic.y);
-    Serial.print(", ");
-    Serial.print(eventM.magnetic.x);
-    Serial.print(", ");
-    Serial.print(heading);
-    Serial.print("] ");
-  }
-  else
-  {
-    Serial.print("error");
-  }
+  Serial.print("[");
+  Serial.print(eventM.magnetic.y);
+  Serial.print(", ");
+  Serial.print(eventM.magnetic.x);
+  Serial.print(", ");
+  Serial.print(heading);
+  Serial.print("]");
   Serial.print(", ");
   Serial.print("\"accelerometer\": ");
-  if (1)
-  {
-    Serial.print("[");
-    Serial.print(eventA.acceleration.x);
-    Serial.print(",");
-    Serial.print(eventA.acceleration.y);
-    Serial.print(",");
-    Serial.print(eventA.acceleration.z);
-    Serial.print("]");
-  }
-  else
-  {
-    Serial.print("\"error\"");
-  }
-  Serial.print("}");
-   delay(1000);
+  Serial.print("[");
+  Serial.print(eventA.acceleration.x);
+  Serial.print(",");
+  Serial.print(eventA.acceleration.y);
+  Serial.print(",");
+  Serial.print(eventA.acceleration.z);
+  Serial.print("]");
+
+  Serial.print("}\n");

+  delay(125);
 }


Fixed filename

Fixed filename

--- controller-basestation/controller_basestation.ino
+++ controller-basestation/controller_basestation.ino
@@ -1,182 +0,0 @@
-
-/*
-This code handles reading the 3 controllers from the operator's station, and then transmits the results to an MQTT broker.
-
-From there, the controlled sharks will get the information, and respond approprately.
-
-  AN IMPORTANT NOTE: This uses the PubSub library from
-  https://github.com/Imroy/pubsubclient
-  This library has been updated to operate with the ESP2866, which is the target platform for this code
-*/
-
-#include <ESP8266WiFi.h>
-#include <PubSubClient.h>
-#include <elapsedMillis.h>
-#include <Streaming.h>
-#include "controller.h"
-#include <SPI.h>
-
-
-/*
-  Configure wifi and MQTT Server
-*/
-
-const char *ssid =	"HOME-1972";		// cannot be longer than 32 characters!
-const char *pass =	"9BC5A011D3345830";		//
-
-// Update these with values suitable for your network.
-IPAddress server(10, 0, 0, 15);
-
-WiFiClient wclient;
-PubSubClient client(wclient, server);
-
-
-
-/*
-  MQTT Recieve handling
-*/
-
-void callback(const MQTT::Publish& pub) {
-  // handle message arrived
-  Serial<<"Recieved message in : " << pub.topic() << " :: " << pub.payload_string() << endl;
-}
-
-/*
-  Create instances for all the controllers
-*/
-SPIController controller1(1,4);
-SPIController controller2(2,5);
-SPIController controller3(3,2);
-
-
-void setup()
-{
-  // Setup console
-  Serial.begin(115200);
-  delay(10);
-  Serial.println();
-  Serial.println();
-
-  client.set_callback(callback);
-
-  WiFi.begin(ssid, pass);
-
-  int retries = 0;
-  while ((WiFi.status() != WL_CONNECTED) && (retries < 10)) {
-    retries++;
-    delay(500);
-    Serial.print(".");
-  }
-  if (WiFi.status() == WL_CONNECTED) {
-    Serial.println("");
-    Serial.println("WiFi connected");
-  }
-
-  if (client.connect("arduinoClient")) {
-    Serial<<"Shark 1 connected to MQTT"<<endl;
-    client.publish("/landshark/basestation", "Basestation online");
-    client.subscribe("/landshark/+/status");
-  }
-}
-
-
-elapsedMillis printer;
-
-void loop()
-{
-  //Update the MQTT
-  client.loop();
-
-  //grab new data from the controllers
-  controller1.update();
-  controller2.update();
-  controller3.update();
-
-
-
-  //update our shark with any relevant button updates
-  if(controller1.upUpdated()){
-    client.publish("/landshark/1/input/up",controller1.upPressed()?"true":"false");
-  }
-  if(controller1.downUpdated()){
-    client.publish("/landshark/1/input/down",controller1.downPressed()?"true":"false");
-  }
-  if(controller1.leftUpdated()){
-    client.publish("/landshark/1/input/left",controller1.leftPressed()?"true":"false");
-  }
-  if(controller1.rightUpdated()){
-    client.publish("/landshark/1/input/right",controller1.rightPressed()?"true":"false");
-  }
-  if(controller1.biteUpdated()){
-    client.publish("/landshark/1/input/bite",controller1.bitePressed()?"true":"false");
-  }
-  if(controller1.danceUpdated()){
-    client.publish("/landshark/1/input/dance",controller1.dancePressed()?"true":"false");
-  }
-
-
-  //update our shark with any relevant button updates
-  if(controller2.upUpdated()){
-    client.publish("/landshark/2/input/up",controller2.upPressed()?"true":"false");
-  }
-  if(controller2.downUpdated()){
-    client.publish("/landshark/2/input/down",controller2.downPressed()?"true":"false");
-  }
-  if(controller2.leftUpdated()){
-    client.publish("/landshark/2/input/left",controller2.leftPressed()?"true":"false");
-  }
-  if(controller2.rightUpdated()){
-    client.publish("/landshark/2/input/right",controller2.rightPressed()?"true":"false");
-  }
-  if(controller2.biteUpdated()){
-    client.publish("/landshark/2/input/bite",controller2.bitePressed()?"true":"false");
-  }
-  if(controller2.danceUpdated()){
-    client.publish("/landshark/2/input/dance",controller2.dancePressed()?"true":"false");
-  }
-
-
-    //update our shark with any relevant button updates
-  if(controller3.upUpdated()){
-    client.publish("/landshark/3/input/up",controller3.upPressed()?"true":"false");
-  }
-  if(controller3.downUpdated()){
-    client.publish("/landshark/3/input/down",controller3.downPressed()?"true":"false");
-  }
-  if(controller3.leftUpdated()){
-    client.publish("/landshark/3/input/left",controller3.leftPressed()?"true":"false");
-  }
-  if(controller3.rightUpdated()){
-    client.publish("/landshark/3/input/right",controller3.rightPressed()?"true":"false");
-  }
-  if(controller3.biteUpdated()){
-    client.publish("/landshark/3/input/bite",controller3.bitePressed()?"true":"false");
-  }
-  if(controller3.danceUpdated()){
-    client.publish("/landshark/3/input/dance",controller3.dancePressed()?"true":"false");
-  }
-
-
-
-
-
-
-  //print some human readable things
-  if (printer > 3000) {
-    printer = 0;
-
-
-
-    //int c=controller1.readByte();
-    Serial.print("Controller status: ");
-    //Serial.println(c);
-
-    String s=String(millis()) ;
-    client.publish("/landshark/1/status",s );
-
-  }
-
-
-}
-
-


change pressure to mbar

change pressure to mbar

--- ScoutWeatherStation/scout_weather_station.ino
+++ ScoutWeatherStation/scout_weather_station.ino
@@ -156,10 +156,10 @@

 ////////////////////////////////////////////////////
 //
-// pascals_to_mbar convert from pascals to mbar
-//
-float pascals_to_mbar(float pascals) {
-  return (pascals / 100.0);
+// hpascals_to_mbar convert from pascals to mbar
+//
+float hpascals_to_mbar(float hpascals) {
+  return hpascals / 100.0;
 }

 ////////////////////////////////////////////////////
@@ -250,8 +250,8 @@
   Serial.print("Pressure: ");
   Serial.print(pressure);
   Serial.println("hPa");
-  Serial.print(hpascals_to_inhg(pressure));
-  Serial.println("inHg");
+  Serial.print(hpascals_to_mbar(pressure));
+  Serial.println("mbar");

 #if MY_DISPLAY == USING_LCD
   display.clear();
@@ -295,16 +295,16 @@
 #if SENSOR == USING_BME
   display.setCursor(18, 48);
   display.print("Pres: ");
-  display.print(hpascals_to_inhg(pressure));
-  display.println("inHg");
+  display.print(hpascals_to_mbar(pressure));
+  display.println("mbar");

 #endif // BME

 #if SENSOR == USING_BMP
   display.setCursor(18, 48);
   display.print("Pres: ");
-  display.print(hpascals_to_inhg(pressure));
-  display.println("inHg");
+  display.print(hpascals_to_mbar(pressure));
+  display.println("mbar");

 #endif // BMP

@@ -554,4 +554,4 @@
 #endif // USING_WIRELESS
 #endif // USE_ESP
    }
-}+}


Update K_Nearest_Neighbors_Cups.ino

Update K_Nearest_Neighbors_Cups.ino

--- K_Nearest_Neighbors_Cups/K_Nearest_Neighbors_Cups.ino
+++ K_Nearest_Neighbors_Cups/K_Nearest_Neighbors_Cups.ino
@@ -66,7 +66,7 @@
 Object knownObjects[NUM_OF_KNOWN_OBJECTS];

 /*
-    Known Objects Preperation
+    Known Objects Preparation
 */

 // Rescale a value to 0-1 range
@@ -386,4 +386,4 @@

     delay(1000);
     */
-}+}


changed order of IF

changed order of IF

--- linefollower/linefollower.ino
+++ linefollower/linefollower.ino
@@ -24,7 +24,7 @@
 int lastAction = 0;

 // Variable that works as a factor regulating the turn speed. i.e 1.8*spedVal = turnspeed
-float turnMulti = 1.7;
+float turnMulti = 1.6;

 int loopDelay = 0;

@@ -44,26 +44,26 @@

   readSensors();

+  // if the right sensor is the only sensor that have the value 1, the bot need to compensate by turning right
+  if((leftSensor == 0 && middleSensor == 0 && rightSensor == 1))
+  {
+    steerRight();
+    Serial.println("SteerLeft");
+    lastAction = 2;
+  }
+  // if the left sensor is the only sensor that have the value 1, the bot need to compensate by turning left
+  else if((leftSensor == 1 && middleSensor == 0 && rightSensor == 0))
+  {
+    steerLeft();
+    Serial.println("SteerRight");
+    lastAction = 3;
+  }
   // if sensor value = 1, then the sensor is on track
   if((leftSensor == 0 && middleSensor == 1 && rightSensor == 0))
   {
     fwd();
     Serial.println("Forward");
     lastAction = 1;
-  }
-  // if the right sensor is the only sensor that have the value 1, the bot need to compensate by turning right
-  else if((leftSensor == 0 && middleSensor == 0 && rightSensor == 1))
-  {
-    steerLeft();
-    Serial.println("SteerLeft");
-    lastAction = 2;
-  }
-  // if the left sensor is the only sensor that have the value 1, the bot need to compensate by turning left
-  else if((leftSensor == 1 && middleSensor == 0 && rightSensor == 0))
-  {
-    steerRight();
-    Serial.println("SteerRight");
-    lastAction = 3;
   }
   else
   {
@@ -97,22 +97,27 @@
 void fwd(){
   Motors.runMotor(1,FORWARD,speedVal);
   Motors.runMotor(2,FORWARD,speedVal);
+  delay(delVal);
 }
 void rev(){
   Motors.runMotor(1,BACKWARD,speedVal);
   Motors.runMotor(2,BACKWARD,speedVal);
+  delay(delVal);
 }
 void stop(){
   Motors.runMotor(1,FORWARD,0);
   Motors.runMotor(2,FORWARD,0);
+  delay(delVal);
 }
 void steerRight(){
   Motors.runMotor(1,FORWARD,speedVal*turnMulti);
   Motors.runMotor(2,FORWARD,speedVal);
+  delay(delVal);
 }
 void steerLeft(){
   Motors.runMotor(1,FORWARD,speedVal);
   Motors.runMotor(2,FORWARD,speedVal*turnMulti);
+  delay(delVal);
 }
 void turnLeft(){  // Turn 90 degree LEFT
   Motors.runMotor(1,BACKWARD,speedVal);


_05_kidSerie_sketch_05.Adafruit_First_Try.ino 05#kidSerie

_05_kidSerie_sketch_05.Adafruit_First_Try.ino 05#kidSerie

--- _05_kidSerie_sketch_05.Adafruit_First_Try.ino
+++ _05_kidSerie_sketch_05.Adafruit_First_Try.ino
@@ -21,7 +21,7 @@
    DHT11:                PRODUCT ID: 386               https://www.adafruit.com/product/386

    Connections:
-      See Official youtube channel vids:
+      See Official youtube channel vids: https://youtu.be/cwYix_Oyui4
    Based on:   Tony DiCola for Adafruit Industries - see below!

    This program is free software: you can redistribute it and/or modify


Debug Mode.

Debug Mode.

--- monitor_client/monitor_client.ino
+++ monitor_client/monitor_client.ino
@@ -19,86 +19,96 @@

 //SIM900
 GPRS gprs(7, 8, 9600,"cmnet");
-char target_url[66];
 char buffer[128];
+//Debug in PC
+bool is_debug = true;

 void setup(){

-	Serial.begin(9600);
-        //DSM init
-        pinMode(3,INPUT);
-        starttime = millis();
-
-	gprs.init();
-	// attempt DHCP
-	while(false == gprs.join()) {
-		Serial.println("gprs join network error");
-		delay(2000);
-	}
-
-	// successful DHCP
-	Serial.print("IP Address is ");
-	Serial.println(gprs.getIPAddress());
+    Serial.begin(9600);
+    //DSM init
+    pinMode(3,INPUT);
+    starttime = millis();
+    if(!is_debug){
+        gprs.init();
+        // attempt DHCP
+        while(false == gprs.join()) {
+            Serial.println("gprs join network error");
+            delay(2000);
+        }
+
+        // successful DHCP
+        Serial.print("IP Address is ");
+        Serial.println(gprs.getIPAddress());
+    }
 }

 void loop(){
-
-  	Serial.print("Temperature (oC): ");
-	Serial.println((float)DHT11.temperature, 2);
-	Serial.print("Humidity (%): ");
-	Serial.println((float)DHT11.humidity, 2);
-
-        duration = pulseIn(pin, LOW);
-        lowpulseoccupancy = lowpulseoccupancy+duration;
+/*
+    Serial.print("Temperature (oC): ");
+    Serial.println((float)DHT11.temperature, 2);
+    Serial.print("Humidity (%): ");
+    Serial.println((float)DHT11.humidity, 2);
+*/
+    duration = pulseIn(pin, LOW);
+    lowpulseoccupancy = lowpulseoccupancy+duration;

-        if ((millis()-starttime) > sampletime_ms)
-        {
-                ratio = lowpulseoccupancy/(sampletime_ms*10.0);  // Integer percentage 0=>100
-                concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve
-                //Serial.print(lowpulseoccupancy);
-                // Serial.print(",");
-                Serial.print(ratio);
-                Serial.print(",");
-                Serial.println(concentration);
-                lowpulseoccupancy = 0;
-                starttime = millis();
+    if ((millis()-starttime) > sampletime_ms)
+    {
+        ratio = lowpulseoccupancy/(sampletime_ms*10.0);  // Integer percentage 0=>100
+        concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve
+        //Serial.print(lowpulseoccupancy);
+        // Serial.print(",");
+        Serial.print(ratio);
+        Serial.print(",");
+        //Serial.println(concentration);
+        lowpulseoccupancy = 0;
+        starttime = millis();
+
+
+    //snprintf(http_cmd,sizeof(http_cmd),"GET monitor.ourjnu.com/submit.php?device_index=13726247339&longitude=113.540718&latitude=22.256467&temperature=%03d&humidity=%03d&particulate_matter=25 HTTP/1.0\r\n\r\n",DHT11.temperature,DHT11.humidity);
+    //sprintf(http_cmd,"GET /submit.php?device_index=13726247339&longitude=113.540718&latitude=22.256467&temperature=%03d&humidity=%03d&particulate_matter=25 HTTP/1.0\r\n\r\n",DHT11.temperature,DHT11.humidity);
+    //Serial.println(http_cmd);
+    if(!is_debug){
+        //Use rewrited url to prevent memory overflow
+        char target_url[66];
+        snprintf(target_url, sizeof(target_url), "GET /13726247339-113.540718-22.256467-%03d-%03d-%07.2f HTTP/1.0\r\n\r\n",DHT11.temperature, DHT11.humidity, ratio);
+        Serial.println(target_url);
+
+        if(false == gprs.connect(TCP,"monitor.ourjnu.com", 80)) {
+            Serial.println("connect error");
+            }else{
+            Serial.println("connect monitor.ourjnu.com success");
         }
-
-	//snprintf(http_cmd,sizeof(http_cmd),"GET monitor.ourjnu.com/submit.php?device_index=13726247339&longitude=113.540718&latitude=22.256467&temperature=%03d&humidity=%03d&particulate_matter=25 HTTP/1.0\r\n\r\n",DHT11.temperature,DHT11.humidity);
-	//sprintf(http_cmd,"GET /submit.php?device_index=13726247339&longitude=113.540718&latitude=22.256467&temperature=%03d&humidity=%03d&particulate_matter=25 HTTP/1.0\r\n\r\n",DHT11.temperature,DHT11.humidity);
-	//Serial.println(http_cmd);
-	//Use rewrited url to prevent memory overflow
-	snprintf(target_url, sizeof(target_url), "GET /13726247339-113.540718-22.256467-%03d-%03d-%07.2f HTTP/1.0\r\n\r\n",DHT11.temperature, DHT11.humidity, ratio);
-	Serial.println(target_url);
-
-	if(false == gprs.connect(TCP,"monitor.ourjnu.com", 80)) {
-		Serial.println("connect error");
-		}else{
-		Serial.println("connect monitor.ourjnu.com success");
-	}
-
-	Serial.println("waiting to fetch...");
-	gprs.send(target_url, sizeof(target_url)-1);
-	while (true) {
-		int ret = gprs.recv(buffer, sizeof(buffer)-1);
-		if (ret <= 0){
-			Serial.println("fetch over...");
-			break;
-		}
-		buffer[ret] = '\0';
-		Serial.print("Recv: ");
-		Serial.print(ret);
-		Serial.print(" bytes: ");
-		Serial.println(buffer);
-	}
-	//gprs.close();
-	//gprs.disconnect();
-
-	/*
-	while(!gprs.available()) {
-	gprs.write("AT+CGATT?");
-	delay(2000);
-	}
-	Serial.println(gprs.read());*/
-	delay(30000);
+
+        Serial.println("waiting to fetch...");
+        gprs.send(target_url, sizeof(target_url)-1);
+        while (true) {
+            int ret = gprs.recv(buffer, sizeof(buffer)-1);
+            if (ret <= 0){
+                Serial.println("fetch over...");
+                break;
+            }
+            buffer[ret] = '\0';
+            Serial.print("Recv: ");
+            Serial.print(ret);
+            Serial.print(" bytes: ");
+            Serial.println(buffer);
+        }
+        //gprs.close();
+        //gprs.disconnect();
+    }else{
+        Serial.print((float)DHT11.temperature, 2);
+        Serial.print(",");
+        Serial.println((float)DHT11.humidity, 2);
+    }
+
+    }
+    /*
+    while(!gprs.available()) {
+    gprs.write("AT+CGATT?");
+    delay(2000);
+    }
+    Serial.println(gprs.read());
+    */
 }


send receiver readings to host only when changed

--- Arduino/firmware/firmware.ino
+++ Arduino/firmware/firmware.ino
@@ -226,7 +226,7 @@
     rc_inputs_steering = microseconds2PWM(steeringIn);

     // send readings to the host only when changed
-    if ((1 < abs(last_throttleIn - throttleIn)) || (1 < abs(last_steeringIn - steeringIn))) {
+    if ((0 < abs(last_throttleIn - throttleIn)) || (0< abs(last_steeringIn - steeringIn))) {
       // send readings to the host
       if (rawOutput) {
         Serial.print(throttleIn);


arduinofile

arduinofile

--- Arduino_code/Arduino_code.ino
+++ Arduino_code/Arduino_code.ino
@@ -1,11 +1,14 @@
 #include <Filters.h>
 int idea = 0;
+int idea2 = 0;
 float testFrequency = 60;                     // test signal frequency (Hz)
 float windowLength = 20.0/testFrequency;     // how long to average the signal, for statistist
 int sensorValue = 0;
+int sensorValue1 = 0;
 float intercept = 0.0257; // to be adjusted based on calibration testing
 float slope = 0.0312; // to be adjusted based on calibration testing
 float current_amps; // estimated actual current in amps
+float current_amps1; // estimated actual current in amps

 unsigned long printPeriod = 1000; // in milliseconds
 // Track time in milliseconds since last reading
@@ -22,6 +25,7 @@
   while( true ) {
     sensorValue = analogRead(A0);  // read the analog in value:
     inputStats.input(sensorValue);  // log to Stats function
+    sensorValue1 = analogRead(A1);  // read the analog in value:

     if((unsigned long)(millis() - previousMillis) >= printPeriod) {
       previousMillis = millis();   // update time
@@ -32,8 +36,27 @@
       if (inputStats.sigma() < 5){
         current_amps = 0;
       }
-      idea = 100 * (current_amps);
-      Serial.println( idea );
+      idea = 100 * (current_amps);
+      idea2 = 1 * (sensorValue1);
+      Serial.println(idea);
+      Serial.println(idea2);
     }
+
+//    sensorValue1 = analogRead(A1);  // read the analog in value:
+//    inputStats.input(sensorValue1);  // log to Stats function
+//
+//    if((unsigned long)(millis() - previousMillis) >= printPeriod) {
+//      previousMillis = millis();   // update time
+//
+//      // display current values to the screen
+//      // convert signal sigma value to current in amps
+//      current_amps1 = intercept + slope * inputStats.sigma();
+//      if (inputStats.sigma() < 5){
+//        current_amps1 = 0;
+//      }
+//      idea2 = 100 * (current_amps1);
+//      Serial.println( idea2 );
+//      Serial.println( sensorValue);
+//    }
   }
 }


updates

updates

--- CRC_VCNL4200/CRC_VCNL4200.ino
+++ CRC_VCNL4200/CRC_VCNL4200.ino
@@ -54,7 +54,7 @@
 	//Serial.print("Proximity: ");
 	//Serial.println(value);

-	//int reg2 = 0x9; //Proximity Sensor (PS) output
+	//int reg2 = 0x9; //Ambient Light Sensor (ALS) output
 	//Wire.beginTransmission(SENSOR_ADDR);
 	//Wire.write(reg2);
 	//Wire.endTransmission(false);


drop to 256 buckets

drop to 256 buckets

--- DanceFeather/DanceFeather.ino
+++ DanceFeather/DanceFeather.ino
@@ -11,9 +11,14 @@
 #include <PDM.h>
 #include <KickFFT.h>

-#define ACC_SIZE 64
-#define FFT_SIZE 512
-#define HANN_SIZE 60
+// works but slow
+//#define ACC_SIZE 64
+//#define FFT_SIZE 512
+//#define HANN_SIZE 60
+
+#define ACC_SIZE 128
+#define FFT_SIZE 256
+#define HANN_SIZE 30
 #define FS (16000.0 / ACC_SIZE)
 #define F2 3.5f
 #define END_INDEX ((uint16_t) (F2 / (FS / FFT_SIZE)))
@@ -243,14 +248,11 @@
 float phaseRateAverage[END_INDEX];
 float magAvg[END_INDEX];

-bool updatePhase(const float mag[], const float phases[], uint16_t startIndex, uint16_t endIndex) {
+float updatePhase(const float mag[], const float phases[], uint16_t startIndex, uint16_t endIndex) {
     float maxMag = -1000;
     uint16_t maxIndex = startIndex;
-    bool ret = false;
+    bool ret = 0;
     for (int i = startIndex; i < endIndex; i++) {
-        if (i <= 0) {
-          continue;
-        }
         float magnitude = mag[i];
         magAvg[i] = magAvg[i] * 0.99 + magnitude * 0.01;
         if (magAvg[i] > maxMag && i > 0) {
@@ -282,18 +284,15 @@
         phaseAvg[i] = norm_rads(phaseAvg[i]);
         // Serial.print("Phase    : "); Serial.println(phase);
         // Serial.print("Phase: "); Serial.println(_phase_avg);
-        if (i == winningIndex && abs(phaseAvg[i]) < 0.1) {
-          ret = true;
-        }
-    }
-
+    }
+
+    winningIndex = maxIndex;
     //if (_phase_avg > 0) {
     //  digitalWrite(LED_PIN, LOW);
     //} else {
     //  digitalWrite(LED_PIN, HIGH);
     //}

-    winningIndex = maxIndex;
     return ret;
 }

@@ -326,10 +325,18 @@
   uint16_t startIndex, endIndex;
   // KickFFT<int32_t>::fft(fs, 0, 4, FFT_SIZE, fftBuffer, mag, startIndex, endIndex);
   fft_phase(FS, 0, F2, FFT_SIZE, fftBuffer, mag, phase, startIndex, endIndex);
-  bool phaseNearZero = updatePhase(mag, phase, startIndex, endIndex);
-  if (diff > 0 && !phaseNearZero) {
+  updatePhase(mag, phase, startIndex, endIndex);
+  bool phaseNearZero = false;
+  for (int i = startIndex; i < endIndex; i++) {
+      if (i == winningIndex && abs(phaseAvg[i]) < 0.1) {
+        phaseNearZero = true;
+      }
+  }
+
+  if (diff > magAvg[0]) {
     digitalWrite(LED_PIN, LOW);

+    Serial.print("Diff:\t"); Serial.println(diff);
     Serial.print("Phase:\t");
     for (int i = 0; i < endIndex; i++) {
       float phase = phaseAvg[i];
@@ -338,7 +345,10 @@
     }
     Serial.println("");

-  } else if (diff > 0 && phaseNearZero) {
+  }
+
+  if (diff > magAvg[0] && phaseNearZero) {
+    Serial.print("Diff:\t"); Serial.println(diff);
     digitalWrite(LED_PIN, HIGH);

     Serial.print("BPM:\t");
@@ -350,7 +360,7 @@
     }
     Serial.println("");

-    Serial.print("Magnitude:\t");
+    Serial.print("Mag:\t");
     for (int i = 0; i < endIndex; i++) {
       float mag = magAvg[i];
       Serial.print(mag);
@@ -400,6 +410,7 @@
       yield();
       continue;
     }
+    uint32_t start = micros();
     for (int i = 0; i < samplesRead; i++) {
       float newVal = tempBuffer[i];
       //acc += newVal * newVal;
@@ -416,6 +427,10 @@
       //samples--;
     }
     // clear the read count
+    uint32_t duration = micros() - start;
+    //Serial.print("micros: "); Serial.println(duration);
+    //Serial.print("samples: "); Serial.println(samplesRead);
+
     samplesRead = 0;
   }
   Serial.print("max: ");


faster filter on non-winners

faster filter on non-winners

--- DanceFeather/DanceFeather.ino
+++ DanceFeather/DanceFeather.ino
@@ -259,6 +259,8 @@
     for (int i = startIndex; i < endIndex; i++) {
         float magnitude = mag[i];
         magAvg[i] = magAvg[i] * 0.9 + magnitude * 0.1;
+        // We look for the beat in 2-7, we can also check i*2 to verify
+        // usually the overtones are synced up as well
         if (magAvg[i] > maxMag && i > 1 && i < 7) {
             maxMag = magAvg[i];
             maxIndex = i;
@@ -274,7 +276,12 @@

         float phaseDiff = norm_rads(phase - old_phase);

-        phaseRateAverage[i] = phaseRateAverage[i] * 0.98 + phaseDiff * 0.02;
+        if (winningIndex == i) {
+          phaseRateAverage[i] = phaseRateAverage[i] * 0.98 + phaseDiff * 0.02;
+        } else {
+          phaseRateAverage[i] = phaseRateAverage[i] * 0.9 + phaseDiff * 0.1;
+        }
+
         // Serial.print("PhaseRateAvg: "); Serial.println(phaseRateAverage);
         // Serial.print("PhaseDiff: "); Serial.println(phaseDiff);

@@ -284,7 +291,12 @@
             phase -= 2*PI;
         }

-        phaseAvg[i] = phaseAvg[i] * 0.99 + phase * 0.01;
+        if (winningIndex == i) {
+          phaseAvg[i] = phaseAvg[i] * 0.99 + phase * 0.01;
+        } else {
+          // aggressively converge for losers
+          phaseAvg[i] = phaseAvg[i] * 0.9 + phase * 0.1;
+        }
         phaseAvg[i] = norm_rads(phaseAvg[i]);
         // Serial.print("Phase    : "); Serial.println(phase);
         // Serial.print("Phase: "); Serial.println(_phase_avg);


tune it up

tune it up

--- DanceFeather/DanceFeather.ino
+++ DanceFeather/DanceFeather.ino
@@ -15,7 +15,7 @@
 #define FFT_SIZE 512
 #define HANN_SIZE 40
 #define FS (16000.0 / ACC_SIZE)
-#define F2 4.0f
+#define F2 3.5f
 #define END_INDEX ((uint16_t) (F2 / (FS / FFT_SIZE)))

 #define LED_PIN 13
@@ -231,9 +231,8 @@

                 float phaseRad = atan2(imag, real);

-		//calculating magnitude of the data by taking the square root of the
-		//sum of the squares of the real and imaginary component of each signal
-                mag[i] = log2(sqrt(real * real + imag * imag));
+                // mag[i] = log2(sqrt(real * real + imag * imag));
+                mag[i] = sqrt(real * real + imag * imag);
 		phase[i] = phaseRad;
 	}
 }
@@ -242,17 +241,20 @@
 uint16_t _old_max_index = 0;
 float phaseAvg[END_INDEX];
 float phaseRateAverage[END_INDEX];
-
-void updatePhase(const float mag[], const float phases[], uint16_t startIndex, uint16_t endIndex) {
-    float maxValue = -1000;
+float magAvg[END_INDEX];
+
+bool updatePhase(const float mag[], const float phases[], uint16_t startIndex, uint16_t endIndex) {
+    float maxMag = -1000;
     uint16_t maxIndex = startIndex;
+    bool ret = false;
     for (int i = startIndex; i < endIndex; i++) {
         if (i <= 0) {
           continue;
         }
-        float val = mag[i];
-        if (val > maxValue) {
-            maxValue = val;
+        float magnitude = mag[i];
+        magAvg[i] = magAvg[i] * 0.99 + magnitude * 0.01;
+        if (magnitude > maxMag) {
+            maxMag = magnitude;
             maxIndex = i;
         }

@@ -266,8 +268,7 @@

         float phaseDiff = norm_rads(phase - old_phase);

-        // Only update the rate if we are in the same fht bucket.
-        phaseRateAverage[i] = phaseRateAverage[i] * 0.99 + phaseDiff * 0.01;
+        phaseRateAverage[i] = phaseRateAverage[i] * 0.98 + phaseDiff * 0.02;
         // Serial.print("PhaseRateAvg: "); Serial.println(phaseRateAverage);
         // Serial.print("PhaseDiff: "); Serial.println(phaseDiff);

@@ -277,10 +278,13 @@
             phase -= 2*PI;
         }

-        phaseAvg[i] = phaseAvg[i] * 0.9 + phase * 0.1;
+        phaseAvg[i] = phaseAvg[i] * 0.99 + phase * 0.01;
         phaseAvg[i] = norm_rads(phaseAvg[i]);
         // Serial.print("Phase    : "); Serial.println(phase);
         // Serial.print("Phase: "); Serial.println(_phase_avg);
+        if (2 <= i && i <= 4 && abs(phaseAvg[i]) < 0.1) {
+          ret = true;
+        }
     }

     //if (_phase_avg > 0) {
@@ -290,6 +294,7 @@
     //}

     _old_max_index = maxIndex;
+    return ret;
 }

@@ -321,17 +326,34 @@
   uint16_t startIndex, endIndex;
   // KickFFT<int32_t>::fft(fs, 0, 4, FFT_SIZE, fftBuffer, mag, startIndex, endIndex);
   fft_phase(FS, 0, F2, FFT_SIZE, fftBuffer, mag, phase, startIndex, endIndex);
-  updatePhase(mag, phase, startIndex, endIndex);
-
-  if (diff > 0) {
-    Serial.print("BPM:\t");
-    for (int i = 0; i < endIndex; i++) {
-      float hz = FS * phaseRateAverage[i] / 2 / PI;
-      float bpm = hz * 60;
-      Serial.print(bpm);
-      Serial.print("\t");
-    }
-    Serial.println("");
+  bool phaseNearZero = updatePhase(mag, phase, startIndex, endIndex);
+  if (diff > 0 && phaseNearZero) {
+
+  // Serial.print("BPM:\t");
+  // for (int i = 0; i < endIndex; i++) {
+  //   float hz = FS * phaseRateAverage[i] / 2 / PI;
+  //   float bpm = hz * 60;
+  //   Serial.print(bpm);
+  //   Serial.print("\t");
+  // }
+  // Serial.println("");
+
+  // Serial.print("Phase:\t");
+  // for (int i = 0; i < endIndex; i++) {
+  //   float phase = phaseAvg[i];
+  //   Serial.print(phase);
+  //   Serial.print("\t");
+  // }
+  // Serial.println("");
+
+  Serial.print("Magnitude:\t");
+  for (int i = 0; i < endIndex; i++) {
+    float mag = magAvg[i];
+    Serial.print(mag);
+    Serial.print("\t");
+  }
+  Serial.println("");
+
   }

   // float hz = FS * phaseRateAverage / 2 / PI;
@@ -380,7 +402,7 @@
           float value = acc / ACC_SIZE;
           acc = 0;
           numInAcc = 0;
-          addToFFT(value * value);
+          addToFFT(value);
           // addToFFT(value);
       }