Add underwater metod

Add underwater metod

At this point the water mode is hardcoded to use for a party. This also
means that it is not possible to change mode. This will be fixed later,
but if you need a working version, you should take the commit before
this one.

--- src/RGB_lamps.ino
+++ src/RGB_lamps.ino
@@ -10,7 +10,11 @@
 RGBLamp lamps[4];
 int colors[216][3];
 int dayCols[20][3];
+int waterCols[748][3];
 float cycleFade[4] = {0,0,0,0};
+int waterTime = 100;
+unsigned int water[4] = {waterTime,waterTime,waterTime,waterTime};
+unsigned short waterCur[4] = {0,0,0,0};

 void setup() {

@@ -30,7 +34,8 @@
   setColors();

   for (int lamp = 0; lamp < 4; lamp++) {
-    lamps[lamp].fade(2000, dayCols[10]);
+    //lamps[lamp].fade(2000, dayCols[10]);
+    lamps[lamp].setColor(waterCols[0]);
   }
 }

@@ -50,6 +55,13 @@
     if (cycleFade[lamp] != 0) {
       if (!lamps[lamp].fade()) {
         lamps[lamp].fade(cycleFade[lamp], colors[random(0, 215)]);
+      }
+    }
+    else if(water[lamp] != 0) {
+      if(millis() > water[lamp]) {
+        waterCur[lamp] = (waterCur[lamp] + 1) % 748;
+        lamps[lamp].setColor(waterCols[waterCur[lamp]]);
+        water[lamp] += 100;
       }
     }
   }
@@ -306,6 +318,2257 @@
   dayCols[19][1] = 49;
   dayCols[19][2] = 83;

+waterCols[0][0] = 21;
+waterCols[0][1] = 89;
+waterCols[0][2] = 119;
+waterCols[1][0] = 22;
+waterCols[1][1] = 90;
+waterCols[1][2] = 120;
+waterCols[2][0] = 23;
+waterCols[2][1] = 91;
+waterCols[2][2] = 121;
+waterCols[3][0] = 23;
+waterCols[3][1] = 91;
+waterCols[3][2] = 121;
+waterCols[4][0] = 26;
+waterCols[4][1] = 89;
+waterCols[4][2] = 118;
+waterCols[5][0] = 25;
+waterCols[5][1] = 86;
+waterCols[5][2] = 116;
+waterCols[6][0] = 22;
+waterCols[6][1] = 80;
+waterCols[6][2] = 111;
+waterCols[7][0] = 22;
+waterCols[7][1] = 78;
+waterCols[7][2] = 110;
+waterCols[8][0] = 17;
+waterCols[8][1] = 73;
+waterCols[8][2] = 105;
+waterCols[9][0] = 19;
+waterCols[9][1] = 70;
+waterCols[9][2] = 103;
+waterCols[10][0] = 18;
+waterCols[10][1] = 64;
+waterCols[10][2] = 97;
+waterCols[11][0] = 17;
+waterCols[11][1] = 63;
+waterCols[11][2] = 96;
+waterCols[12][0] = 18;
+waterCols[12][1] = 58;
+waterCols[12][2] = 90;
+waterCols[13][0] = 16;
+waterCols[13][1] = 56;
+waterCols[13][2] = 88;
+waterCols[14][0] = 18;
+waterCols[14][1] = 58;
+waterCols[14][2] = 90;
+waterCols[15][0] = 16;
+waterCols[15][1] = 59;
+waterCols[15][2] = 88;
+waterCols[16][0] = 16;
+waterCols[16][1] = 56;
+waterCols[16][2] = 86;
+waterCols[17][0] = 19;
+waterCols[17][1] = 57;
+waterCols[17][2] = 88;
+waterCols[18][0] = 19;
+waterCols[18][1] = 54;
+waterCols[18][2] = 86;
+waterCols[19][0] = 18;
+waterCols[19][1] = 53;
+waterCols[19][2] = 85;
+waterCols[20][0] = 18;
+waterCols[20][1] = 53;
+waterCols[20][2] = 83;
+waterCols[21][0] = 17;
+waterCols[21][1] = 55;
+waterCols[21][2] = 84;
+waterCols[22][0] = 21;
+waterCols[22][1] = 59;
+waterCols[22][2] = 90;
+waterCols[23][0] = 22;
+waterCols[23][1] = 61;
+waterCols[23][2] = 96;
+waterCols[24][0] = 21;
+waterCols[24][1] = 67;
+waterCols[24][2] = 100;
+waterCols[25][0] = 20;
+waterCols[25][1] = 69;
+waterCols[25][2] = 101;
+waterCols[26][0] = 22;
+waterCols[26][1] = 71;
+waterCols[26][2] = 105;
+waterCols[27][0] = 19;
+waterCols[27][1] = 73;
+waterCols[27][2] = 105;
+waterCols[28][0] = 22;
+waterCols[28][1] = 76;
+waterCols[28][2] = 108;
+waterCols[29][0] = 21;
+waterCols[29][1] = 77;
+waterCols[29][2] = 107;
+waterCols[30][0] = 19;
+waterCols[30][1] = 73;
+waterCols[30][2] = 103;
+waterCols[31][0] = 19;
+waterCols[31][1] = 73;
+waterCols[31][2] = 103;
+waterCols[32][0] = 21;
+waterCols[32][1] = 73;
+waterCols[32][2] = 101;
+waterCols[33][0] = 19;
+waterCols[33][1] = 70;
+waterCols[33][2] = 101;
+waterCols[34][0] = 20;
+waterCols[34][1] = 69;
+waterCols[34][2] = 101;
+waterCols[35][0] = 21;
+waterCols[35][1] = 68;
+waterCols[35][2] = 98;
+waterCols[36][0] = 18;
+waterCols[36][1] = 65;
+waterCols[36][2] = 93;
+waterCols[37][0] = 18;
+waterCols[37][1] = 61;
+waterCols[37][2] = 90;
+waterCols[38][0] = 18;
+waterCols[38][1] = 58;
+waterCols[38][2] = 88;
+waterCols[39][0] = 15;
+waterCols[39][1] = 53;
+waterCols[39][2] = 82;
+waterCols[40][0] = 15;
+waterCols[40][1] = 50;
+waterCols[40][2] = 82;
+waterCols[41][0] = 17;
+waterCols[41][1] = 52;
+waterCols[41][2] = 84;
+waterCols[42][0] = 19;
+waterCols[42][1] = 54;
+waterCols[42][2] = 88;
+waterCols[43][0] = 20;
+waterCols[43][1] = 53;
+waterCols[43][2] = 88;
+waterCols[44][0] = 18;
+waterCols[44][1] = 53;
+waterCols[44][2] = 87;
+waterCols[45][0] = 18;
+waterCols[45][1] = 52;
+waterCols[45][2] = 89;
+waterCols[46][0] = 15;
+waterCols[46][1] = 52;
+waterCols[46][2] = 88;
+waterCols[47][0] = 16;
+waterCols[47][1] = 53;
+waterCols[47][2] = 89;
+waterCols[48][0] = 18;
+waterCols[48][1] = 52;
+waterCols[48][2] = 89;
+waterCols[49][0] = 19;
+waterCols[49][1] = 57;
+waterCols[49][2] = 90;
+waterCols[50][0] = 21;
+waterCols[50][1] = 58;
+waterCols[50][2] = 94;
+waterCols[51][0] = 21;
+waterCols[51][1] = 60;
+waterCols[51][2] = 95;
+waterCols[52][0] = 21;
+waterCols[52][1] = 58;
+waterCols[52][2] = 94;
+waterCols[53][0] = 19;
+waterCols[53][1] = 58;
+waterCols[53][2] = 93;
+waterCols[54][0] = 18;
+waterCols[54][1] = 58;
+waterCols[54][2] = 90;
+waterCols[55][0] = 16;
+waterCols[55][1] = 54;
+waterCols[55][2] = 87;
+waterCols[56][0] = 18;
+waterCols[56][1] = 53;
+waterCols[56][2] = 87;
+waterCols[57][0] = 17;
+waterCols[57][1] = 52;
+waterCols[57][2] = 84;
+waterCols[58][0] = 15;
+waterCols[58][1] = 53;
+waterCols[58][2] = 84;
+waterCols[59][0] = 17;
+waterCols[59][1] = 55;
+waterCols[59][2] = 88;
+waterCols[60][0] = 18;
+waterCols[60][1] = 58;
+waterCols[60][2] = 90;
+waterCols[61][0] = 18;
+waterCols[61][1] = 61;
+waterCols[61][2] = 92;
+waterCols[62][0] = 19;
+waterCols[62][1] = 62;
+waterCols[62][2] = 93;
+waterCols[63][0] = 21;
+waterCols[63][1] = 66;
+waterCols[63][2] = 97;
+waterCols[64][0] = 20;
+waterCols[64][1] = 70;
+waterCols[64][2] = 99;
+waterCols[65][0] = 19;
+waterCols[65][1] = 73;
+waterCols[65][2] = 103;
+waterCols[66][0] = 18;
+waterCols[66][1] = 74;
+waterCols[66][2] = 104;
+waterCols[67][0] = 22;
+waterCols[67][1] = 78;
+waterCols[67][2] = 108;
+waterCols[68][0] = 21;
+waterCols[68][1] = 83;
+waterCols[68][2] = 108;
+waterCols[69][0] = 24;
+waterCols[69][1] = 85;
+waterCols[69][2] = 113;
+waterCols[70][0] = 23;
+waterCols[70][1] = 86;
+waterCols[70][2] = 113;
+waterCols[71][0] = 23;
+waterCols[71][1] = 89;
+waterCols[71][2] = 115;
+waterCols[72][0] = 23;
+waterCols[72][1] = 89;
+waterCols[72][2] = 115;
+waterCols[73][0] = 24;
+waterCols[73][1] = 90;
+waterCols[73][2] = 116;
+waterCols[74][0] = 24;
+waterCols[74][1] = 90;
+waterCols[74][2] = 116;
+waterCols[75][0] = 23;
+waterCols[75][1] = 89;
+waterCols[75][2] = 117;
+waterCols[76][0] = 22;
+waterCols[76][1] = 91;
+waterCols[76][2] = 118;
+waterCols[77][0] = 22;
+waterCols[77][1] = 91;
+waterCols[77][2] = 118;
+waterCols[78][0] = 22;
+waterCols[78][1] = 91;
+waterCols[78][2] = 118;
+waterCols[79][0] = 22;
+waterCols[79][1] = 91;
+waterCols[79][2] = 118;
+waterCols[80][0] = 21;
+waterCols[80][1] = 90;
+waterCols[80][2] = 117;
+waterCols[81][0] = 21;
+waterCols[81][1] = 90;
+waterCols[81][2] = 117;
+waterCols[82][0] = 24;
+waterCols[82][1] = 87;
+waterCols[82][2] = 116;
+waterCols[83][0] = 24;
+waterCols[83][1] = 87;
+waterCols[83][2] = 116;
+waterCols[84][0] = 23;
+waterCols[84][1] = 85;
+waterCols[84][2] = 117;
+waterCols[85][0] = 23;
+waterCols[85][1] = 85;
+waterCols[85][2] = 117;
+waterCols[86][0] = 23;
+waterCols[86][1] = 85;
+waterCols[86][2] = 117;
+waterCols[87][0] = 23;
+waterCols[87][1] = 85;
+waterCols[87][2] = 117;
+waterCols[88][0] = 24;
+waterCols[88][1] = 85;
+waterCols[88][2] = 115;
+waterCols[89][0] = 23;
+waterCols[89][1] = 85;
+waterCols[89][2] = 117;
+waterCols[90][0] = 23;
+waterCols[90][1] = 85;
+waterCols[90][2] = 117;
+waterCols[91][0] = 23;
+waterCols[91][1] = 85;
+waterCols[91][2] = 117;
+waterCols[92][0] = 21;
+waterCols[92][1] = 83;
+waterCols[92][2] = 115;
+waterCols[93][0] = 21;
+waterCols[93][1] = 83;
+waterCols[93][2] = 115;
+waterCols[94][0] = 21;
+waterCols[94][1] = 83;
+waterCols[94][2] = 115;
+waterCols[95][0] = 22;
+waterCols[95][1] = 82;
+waterCols[95][2] = 115;
+waterCols[96][0] = 22;
+waterCols[96][1] = 82;
+waterCols[96][2] = 115;
+waterCols[97][0] = 21;
+waterCols[97][1] = 81;
+waterCols[97][2] = 114;
+waterCols[98][0] = 20;
+waterCols[98][1] = 81;
+waterCols[98][2] = 111;
+waterCols[99][0] = 17;
+waterCols[99][1] = 73;
+waterCols[99][2] = 105;
+waterCols[100][0] = 19;
+waterCols[100][1] = 70;
+waterCols[100][2] = 103;
+waterCols[101][0] = 19;
+waterCols[101][1] = 70;
+waterCols[101][2] = 103;
+waterCols[102][0] = 19;
+waterCols[102][1] = 67;
+waterCols[102][2] = 104;
+waterCols[103][0] = 19;
+waterCols[103][1] = 62;
+waterCols[103][2] = 101;
+waterCols[104][0] = 21;
+waterCols[104][1] = 64;
+waterCols[104][2] = 103;
+waterCols[105][0] = 18;
+waterCols[105][1] = 63;
+waterCols[105][2] = 101;
+waterCols[106][0] = 19;
+waterCols[106][1] = 62;
+waterCols[106][2] = 101;
+waterCols[107][0] = 16;
+waterCols[107][1] = 59;
+waterCols[107][2] = 98;
+waterCols[108][0] = 16;
+waterCols[108][1] = 59;
+waterCols[108][2] = 98;
+waterCols[109][0] = 16;
+waterCols[109][1] = 59;
+waterCols[109][2] = 98;
+waterCols[110][0] = 16;
+waterCols[110][1] = 59;
+waterCols[110][2] = 98;
+waterCols[111][0] = 16;
+waterCols[111][1] = 60;
+waterCols[111][2] = 96;
+waterCols[112][0] = 16;
+waterCols[112][1] = 60;
+waterCols[112][2] = 96;
+waterCols[113][0] = 18;
+waterCols[113][1] = 60;
+waterCols[113][2] = 96;
+waterCols[114][0] = 18;
+waterCols[114][1] = 60;
+waterCols[114][2] = 96;
+waterCols[115][0] = 19;
+waterCols[115][1] = 58;
+waterCols[115][2] = 95;
+waterCols[116][0] = 19;
+waterCols[116][1] = 56;
+waterCols[116][2] = 92;
+waterCols[117][0] = 17;
+waterCols[117][1] = 54;
+waterCols[117][2] = 90;
+waterCols[118][0] = 17;
+waterCols[118][1] = 54;
+waterCols[118][2] = 90;
+waterCols[119][0] = 19;
+waterCols[119][1] = 56;
+waterCols[119][2] = 92;
+waterCols[120][0] = 19;
+waterCols[120][1] = 58;
+waterCols[120][2] = 93;
+waterCols[121][0] = 20;
+waterCols[121][1] = 59;
+waterCols[121][2] = 94;
+waterCols[122][0] = 18;
+waterCols[122][1] = 62;
+waterCols[122][2] = 96;
+waterCols[123][0] = 19;
+waterCols[123][1] = 63;
+waterCols[123][2] = 97;
+waterCols[124][0] = 18;
+waterCols[124][1] = 64;
+waterCols[124][2] = 97;
+waterCols[125][0] = 18;
+waterCols[125][1] = 64;
+waterCols[125][2] = 97;
+waterCols[126][0] = 16;
+waterCols[126][1] = 65;
+waterCols[126][2] = 97;
+waterCols[127][0] = 18;
+waterCols[127][1] = 67;
+waterCols[127][2] = 99;
+waterCols[128][0] = 20;
+waterCols[128][1] = 69;
+waterCols[128][2] = 101;
+waterCols[129][0] = 23;
+waterCols[129][1] = 77;
+waterCols[129][2] = 107;
+waterCols[130][0] = 24;
+waterCols[130][1] = 78;
+waterCols[130][2] = 108;
+waterCols[131][0] = 19;
+waterCols[131][1] = 82;
+waterCols[131][2] = 109;
+waterCols[132][0] = 19;
+waterCols[132][1] = 82;
+waterCols[132][2] = 109;
+waterCols[133][0] = 21;
+waterCols[133][1] = 79;
+waterCols[133][2] = 110;
+waterCols[134][0] = 20;
+waterCols[134][1] = 74;
+waterCols[134][2] = 106;
+waterCols[135][0] = 19;
+waterCols[135][1] = 70;
+waterCols[135][2] = 101;
+waterCols[136][0] = 18;
+waterCols[136][1] = 67;
+waterCols[136][2] = 99;
+waterCols[137][0] = 18;
+waterCols[137][1] = 67;
+waterCols[137][2] = 99;
+waterCols[138][0] = 20;
+waterCols[138][1] = 66;
+waterCols[138][2] = 99;
+waterCols[139][0] = 19;
+waterCols[139][1] = 68;
+waterCols[139][2] = 100;
+waterCols[140][0] = 19;
+waterCols[140][1] = 68;
+waterCols[140][2] = 100;
+waterCols[141][0] = 20;
+waterCols[141][1] = 69;
+waterCols[141][2] = 101;
+waterCols[142][0] = 22;
+waterCols[142][1] = 68;
+waterCols[142][2] = 101;
+waterCols[143][0] = 20;
+waterCols[143][1] = 66;
+waterCols[143][2] = 99;
+waterCols[144][0] = 19;
+waterCols[144][1] = 63;
+waterCols[144][2] = 97;
+waterCols[145][0] = 19;
+waterCols[145][1] = 63;
+waterCols[145][2] = 97;
+waterCols[146][0] = 21;
+waterCols[146][1] = 63;
+waterCols[146][2] = 97;
+waterCols[147][0] = 20;
+waterCols[147][1] = 63;
+waterCols[147][2] = 94;
+waterCols[148][0] = 19;
+waterCols[148][1] = 63;
+waterCols[148][2] = 97;
+waterCols[149][0] = 20;
+waterCols[149][1] = 67;
+waterCols[149][2] = 97;
+waterCols[150][0] = 19;
+waterCols[150][1] = 69;
+waterCols[150][2] = 96;
+waterCols[151][0] = 21;
+waterCols[151][1] = 68;
+waterCols[151][2] = 96;
+waterCols[152][0] = 20;
+waterCols[152][1] = 67;
+waterCols[152][2] = 95;
+waterCols[153][0] = 18;
+waterCols[153][1] = 63;
+waterCols[153][2] = 92;
+waterCols[154][0] = 16;
+waterCols[154][1] = 61;
+waterCols[154][2] = 90;
+waterCols[155][0] = 16;
+waterCols[155][1] = 59;
+waterCols[155][2] = 90;
+waterCols[156][0] = 16;
+waterCols[156][1] = 56;
+waterCols[156][2] = 86;
+waterCols[157][0] = 19;
+waterCols[157][1] = 64;
+waterCols[157][2] = 95;
+waterCols[158][0] = 20;
+waterCols[158][1] = 66;
+waterCols[158][2] = 99;
+waterCols[159][0] = 19;
+waterCols[159][1] = 70;
+waterCols[159][2] = 101;
+waterCols[160][0] = 19;
+waterCols[160][1] = 73;
+waterCols[160][2] = 103;
+waterCols[161][0] = 22;
+waterCols[161][1] = 78;
+waterCols[161][2] = 108;
+waterCols[162][0] = 22;
+waterCols[162][1] = 78;
+waterCols[162][2] = 110;
+waterCols[163][0] = 20;
+waterCols[163][1] = 76;
+waterCols[163][2] = 108;
+waterCols[164][0] = 21;
+waterCols[164][1] = 77;
+waterCols[164][2] = 109;
+waterCols[165][0] = 20;
+waterCols[165][1] = 78;
+waterCols[165][2] = 109;
+waterCols[166][0] = 21;
+waterCols[166][1] = 79;
+waterCols[166][2] = 110;
+waterCols[167][0] = 21;
+waterCols[167][1] = 79;
+waterCols[167][2] = 110;
+waterCols[168][0] = 21;
+waterCols[168][1] = 79;
+waterCols[168][2] = 110;
+waterCols[169][0] = 22;
+waterCols[169][1] = 80;
+waterCols[169][2] = 111;
+waterCols[170][0] = 21;
+waterCols[170][1] = 79;
+waterCols[170][2] = 110;
+waterCols[171][0] = 21;
+waterCols[171][1] = 79;
+waterCols[171][2] = 110;
+waterCols[172][0] = 21;
+waterCols[172][1] = 77;
+waterCols[172][2] = 109;
+waterCols[173][0] = 21;
+waterCols[173][1] = 77;
+waterCols[173][2] = 109;
+waterCols[174][0] = 20;
+waterCols[174][1] = 76;
+waterCols[174][2] = 108;
+waterCols[175][0] = 20;
+waterCols[175][1] = 76;
+waterCols[175][2] = 108;
+waterCols[176][0] = 23;
+waterCols[176][1] = 79;
+waterCols[176][2] = 111;
+waterCols[177][0] = 22;
+waterCols[177][1] = 80;
+waterCols[177][2] = 111;
+waterCols[178][0] = 24;
+waterCols[178][1] = 80;
+waterCols[178][2] = 112;
+waterCols[179][0] = 24;
+waterCols[179][1] = 81;
+waterCols[179][2] = 115;
+waterCols[180][0] = 23;
+waterCols[180][1] = 85;
+waterCols[180][2] = 117;
+waterCols[181][0] = 21;
+waterCols[181][1] = 83;
+waterCols[181][2] = 115;
+waterCols[182][0] = 21;
+waterCols[182][1] = 83;
+waterCols[182][2] = 115;
+waterCols[183][0] = 20;
+waterCols[183][1] = 82;
+waterCols[183][2] = 114;
+waterCols[184][0] = 22;
+waterCols[184][1] = 80;
+waterCols[184][2] = 111;
+waterCols[185][0] = 23;
+waterCols[185][1] = 77;
+waterCols[185][2] = 109;
+waterCols[186][0] = 20;
+waterCols[186][1] = 76;
+waterCols[186][2] = 106;
+waterCols[187][0] = 21;
+waterCols[187][1] = 70;
+waterCols[187][2] = 102;
+waterCols[188][0] = 21;
+waterCols[188][1] = 67;
+waterCols[188][2] = 100;
+waterCols[189][0] = 21;
+waterCols[189][1] = 67;
+waterCols[189][2] = 102;
+waterCols[190][0] = 21;
+waterCols[190][1] = 65;
+waterCols[190][2] = 101;
+waterCols[191][0] = 20;
+waterCols[191][1] = 63;
+waterCols[191][2] = 94;
+waterCols[192][0] = 19;
+waterCols[192][1] = 58;
+waterCols[192][2] = 93;
+waterCols[193][0] = 19;
+waterCols[193][1] = 56;
+waterCols[193][2] = 92;
+waterCols[194][0] = 17;
+waterCols[194][1] = 54;
+waterCols[194][2] = 90;
+waterCols[195][0] = 16;
+waterCols[195][1] = 54;
+waterCols[195][2] = 87;
+waterCols[196][0] = 17;
+waterCols[196][1] = 55;
+waterCols[196][2] = 88;
+waterCols[197][0] = 16;
+waterCols[197][1] = 56;
+waterCols[197][2] = 88;
+waterCols[198][0] = 16;
+waterCols[198][1] = 56;
+waterCols[198][2] = 88;
+waterCols[199][0] = 19;
+waterCols[199][1] = 57;
+waterCols[199][2] = 90;
+waterCols[200][0] = 17;
+waterCols[200][1] = 55;
+waterCols[200][2] = 88;
+waterCols[201][0] = 19;
+waterCols[201][1] = 56;
+waterCols[201][2] = 92;
+waterCols[202][0] = 16;
+waterCols[202][1] = 55;
+waterCols[202][2] = 90;
+waterCols[203][0] = 19;
+waterCols[203][1] = 58;
+waterCols[203][2] = 93;
+waterCols[204][0] = 19;
+waterCols[204][1] = 54;
+waterCols[204][2] = 88;
+waterCols[205][0] = 15;
+waterCols[205][1] = 53;
+waterCols[205][2] = 84;
+waterCols[206][0] = 15;
+waterCols[206][1] = 53;
+waterCols[206][2] = 84;
+waterCols[207][0] = 14;
+waterCols[207][1] = 52;
+waterCols[207][2] = 83;
+waterCols[208][0] = 15;
+waterCols[208][1] = 53;
+waterCols[208][2] = 84;
+waterCols[209][0] = 17;
+waterCols[209][1] = 52;
+waterCols[209][2] = 84;
+waterCols[210][0] = 16;
+waterCols[210][1] = 51;
+waterCols[210][2] = 83;
+waterCols[211][0] = 17;
+waterCols[211][1] = 52;
+waterCols[211][2] = 84;
+waterCols[212][0] = 18;
+waterCols[212][1] = 53;
+waterCols[212][2] = 85;
+waterCols[213][0] = 17;
+waterCols[213][1] = 55;
+waterCols[213][2] = 86;
+waterCols[214][0] = 19;
+waterCols[214][1] = 57;
+waterCols[214][2] = 88;
+waterCols[215][0] = 19;
+waterCols[215][1] = 57;
+waterCols[215][2] = 88;
+waterCols[216][0] = 19;
+waterCols[216][1] = 62;
+waterCols[216][2] = 93;
+waterCols[217][0] = 19;
+waterCols[217][1] = 64;
+waterCols[217][2] = 95;
+waterCols[218][0] = 21;
+waterCols[218][1] = 66;
+waterCols[218][2] = 97;
+waterCols[219][0] = 21;
+waterCols[219][1] = 68;
+waterCols[219][2] = 98;
+waterCols[220][0] = 20;
+waterCols[220][1] = 70;
+waterCols[220][2] = 99;
+waterCols[221][0] = 21;
+waterCols[221][1] = 71;
+waterCols[221][2] = 100;
+waterCols[222][0] = 21;
+waterCols[222][1] = 70;
+waterCols[222][2] = 102;
+waterCols[223][0] = 21;
+waterCols[223][1] = 70;
+waterCols[223][2] = 102;
+waterCols[224][0] = 21;
+waterCols[224][1] = 70;
+waterCols[224][2] = 102;
+waterCols[225][0] = 21;
+waterCols[225][1] = 70;
+waterCols[225][2] = 102;
+waterCols[226][0] = 21;
+waterCols[226][1] = 70;
+waterCols[226][2] = 102;
+waterCols[227][0] = 21;
+waterCols[227][1] = 70;
+waterCols[227][2] = 102;
+waterCols[228][0] = 20;
+waterCols[228][1] = 69;
+waterCols[228][2] = 101;
+waterCols[229][0] = 21;
+waterCols[229][1] = 70;
+waterCols[229][2] = 102;
+waterCols[230][0] = 21;
+waterCols[230][1] = 70;
+waterCols[230][2] = 102;
+waterCols[231][0] = 22;
+waterCols[231][1] = 71;
+waterCols[231][2] = 103;
+waterCols[232][0] = 21;
+waterCols[232][1] = 72;
+waterCols[232][2] = 103;
+waterCols[233][0] = 21;
+waterCols[233][1] = 72;
+waterCols[233][2] = 103;
+waterCols[234][0] = 21;
+waterCols[234][1] = 72;
+waterCols[234][2] = 103;
+waterCols[235][0] = 19;
+waterCols[235][1] = 73;
+waterCols[235][2] = 103;
+waterCols[236][0] = 19;
+waterCols[236][1] = 73;
+waterCols[236][2] = 103;
+waterCols[237][0] = 20;
+waterCols[237][1] = 74;
+waterCols[237][2] = 104;
+waterCols[238][0] = 20;
+waterCols[238][1] = 74;
+waterCols[238][2] = 104;
+waterCols[239][0] = 22;
+waterCols[239][1] = 73;
+waterCols[239][2] = 104;
+waterCols[240][0] = 21;
+waterCols[240][1] = 73;
+waterCols[240][2] = 101;
+waterCols[241][0] = 20;
+waterCols[241][1] = 72;
+waterCols[241][2] = 100;
+waterCols[242][0] = 20;
+waterCols[242][1] = 72;
+waterCols[242][2] = 100;
+waterCols[243][0] = 20;
+waterCols[243][1] = 72;
+waterCols[243][2] = 100;
+waterCols[244][0] = 20;
+waterCols[244][1] = 72;
+waterCols[244][2] = 100;
+waterCols[245][0] = 21;
+waterCols[245][1] = 72;
+waterCols[245][2] = 103;
+waterCols[246][0] = 21;
+waterCols[246][1] = 70;
+waterCols[246][2] = 102;
+waterCols[247][0] = 20;
+waterCols[247][1] = 70;
+waterCols[247][2] = 99;
+waterCols[248][0] = 18;
+waterCols[248][1] = 63;
+waterCols[248][2] = 94;
+waterCols[249][0] = 18;
+waterCols[249][1] = 63;
+waterCols[249][2] = 94;
+waterCols[250][0] = 17;
+waterCols[250][1] = 64;
+waterCols[250][2] = 94;
+waterCols[251][0] = 17;
+waterCols[251][1] = 62;
+waterCols[251][2] = 93;
+waterCols[252][0] = 19;
+waterCols[252][1] = 64;
+waterCols[252][2] = 95;
+waterCols[253][0] = 20;
+waterCols[253][1] = 70;
+waterCols[253][2] = 99;
+waterCols[254][0] = 20;
+waterCols[254][1] = 71;
+waterCols[254][2] = 102;
+waterCols[255][0] = 19;
+waterCols[255][1] = 73;
+waterCols[255][2] = 103;
+waterCols[256][0] = 21;
+waterCols[256][1] = 72;
+waterCols[256][2] = 103;
+waterCols[257][0] = 22;
+waterCols[257][1] = 69;
+waterCols[257][2] = 99;
+waterCols[258][0] = 20;
+waterCols[258][1] = 70;
+waterCols[258][2] = 99;
+waterCols[259][0] = 18;
+waterCols[259][1] = 68;
+waterCols[259][2] = 97;
+waterCols[260][0] = 19;
+waterCols[260][1] = 62;
+waterCols[260][2] = 91;
+waterCols[261][0] = 20;
+waterCols[261][1] = 60;
+waterCols[261][2] = 92;
+waterCols[262][0] = 19;
+waterCols[262][1] = 59;
+waterCols[262][2] = 91;
+waterCols[263][0] = 19;
+waterCols[263][1] = 57;
+waterCols[263][2] = 90;
+waterCols[264][0] = 19;
+waterCols[264][1] = 54;
+waterCols[264][2] = 88;
+waterCols[265][0] = 21;
+waterCols[265][1] = 56;
+waterCols[265][2] = 90;
+waterCols[266][0] = 17;
+waterCols[266][1] = 52;
+waterCols[266][2] = 86;
+waterCols[267][0] = 19;
+waterCols[267][1] = 54;
+waterCols[267][2] = 88;
+waterCols[268][0] = 18;
+waterCols[268][1] = 53;
+waterCols[268][2] = 87;
+waterCols[269][0] = 17;
+waterCols[269][1] = 55;
+waterCols[269][2] = 88;
+waterCols[270][0] = 16;
+waterCols[270][1] = 54;
+waterCols[270][2] = 87;
+waterCols[271][0] = 19;
+waterCols[271][1] = 57;
+waterCols[271][2] = 90;
+waterCols[272][0] = 18;
+waterCols[272][1] = 57;
+waterCols[272][2] = 92;
+waterCols[273][0] = 19;
+waterCols[273][1] = 58;
+waterCols[273][2] = 93;
+waterCols[274][0] = 19;
+waterCols[274][1] = 58;
+waterCols[274][2] = 93;
+waterCols[275][0] = 19;
+waterCols[275][1] = 59;
+waterCols[275][2] = 91;
+waterCols[276][0] = 19;
+waterCols[276][1] = 59;
+waterCols[276][2] = 91;
+waterCols[277][0] = 19;
+waterCols[277][1] = 59;
+waterCols[277][2] = 91;
+waterCols[278][0] = 20;
+waterCols[278][1] = 57;
+waterCols[278][2] = 93;
+waterCols[279][0] = 19;
+waterCols[279][1] = 56;
+waterCols[279][2] = 92;
+waterCols[280][0] = 19;
+waterCols[280][1] = 56;
+waterCols[280][2] = 92;
+waterCols[281][0] = 17;
+waterCols[281][1] = 55;
+waterCols[281][2] = 88;
+waterCols[282][0] = 17;
+waterCols[282][1] = 55;
+waterCols[282][2] = 88;
+waterCols[283][0] = 17;
+waterCols[283][1] = 55;
+waterCols[283][2] = 88;
+waterCols[284][0] = 17;
+waterCols[284][1] = 55;
+waterCols[284][2] = 88;
+waterCols[285][0] = 17;
+waterCols[285][1] = 55;
+waterCols[285][2] = 88;
+waterCols[286][0] = 17;
+waterCols[286][1] = 55;
+waterCols[286][2] = 88;
+waterCols[287][0] = 19;
+waterCols[287][1] = 57;
+waterCols[287][2] = 88;
+waterCols[288][0] = 18;
+waterCols[288][1] = 61;
+waterCols[288][2] = 92;
+waterCols[289][0] = 19;
+waterCols[289][1] = 62;
+waterCols[289][2] = 93;
+waterCols[290][0] = 23;
+waterCols[290][1] = 66;
+waterCols[290][2] = 97;
+waterCols[291][0] = 21;
+waterCols[291][1] = 66;
+waterCols[291][2] = 97;
+waterCols[292][0] = 20;
+waterCols[292][1] = 66;
+waterCols[292][2] = 99;
+waterCols[293][0] = 19;
+waterCols[293][1] = 68;
+waterCols[293][2] = 100;
+waterCols[294][0] = 21;
+waterCols[294][1] = 67;
+waterCols[294][2] = 100;
+waterCols[295][0] = 19;
+waterCols[295][1] = 68;
+waterCols[295][2] = 100;
+waterCols[296][0] = 20;
+waterCols[296][1] = 69;
+waterCols[296][2] = 101;
+waterCols[297][0] = 22;
+waterCols[297][1] = 68;
+waterCols[297][2] = 101;
+waterCols[298][0] = 22;
+waterCols[298][1] = 68;
+waterCols[298][2] = 101;
+waterCols[299][0] = 22;
+waterCols[299][1] = 68;
+waterCols[299][2] = 101;
+waterCols[300][0] = 21;
+waterCols[300][1] = 68;
+waterCols[300][2] = 98;
+waterCols[301][0] = 21;
+waterCols[301][1] = 68;
+waterCols[301][2] = 98;
+waterCols[302][0] = 21;
+waterCols[302][1] = 66;
+waterCols[302][2] = 97;
+waterCols[303][0] = 20;
+waterCols[303][1] = 63;
+waterCols[303][2] = 94;
+waterCols[304][0] = 18;
+waterCols[304][1] = 61;
+waterCols[304][2] = 92;
+waterCols[305][0] = 18;
+waterCols[305][1] = 58;
+waterCols[305][2] = 88;
+waterCols[306][0] = 15;
+waterCols[306][1] = 55;
+waterCols[306][2] = 87;
+waterCols[307][0] = 16;
+waterCols[307][1] = 56;
+waterCols[307][2] = 88;
+waterCols[308][0] = 16;
+waterCols[308][1] = 56;
+waterCols[308][2] = 88;
+waterCols[309][0] = 16;
+waterCols[309][1] = 54;
+waterCols[309][2] = 87;
+waterCols[310][0] = 17;
+waterCols[310][1] = 55;
+waterCols[310][2] = 88;
+waterCols[311][0] = 17;
+waterCols[311][1] = 54;
+waterCols[311][2] = 90;
+waterCols[312][0] = 21;
+waterCols[312][1] = 60;
+waterCols[312][2] = 95;
+waterCols[313][0] = 21;
+waterCols[313][1] = 65;
+waterCols[313][2] = 101;
+waterCols[314][0] = 21;
+waterCols[314][1] = 70;
+waterCols[314][2] = 104;
+waterCols[315][0] = 22;
+waterCols[315][1] = 76;
+waterCols[315][2] = 108;
+waterCols[316][0] = 23;
+waterCols[316][1] = 76;
+waterCols[316][2] = 111;
+waterCols[317][0] = 21;
+waterCols[317][1] = 78;
+waterCols[317][2] = 112;
+waterCols[318][0] = 21;
+waterCols[318][1] = 81;
+waterCols[318][2] = 116;
+waterCols[319][0] = 23;
+waterCols[319][1] = 85;
+waterCols[319][2] = 119;
+waterCols[320][0] = 22;
+waterCols[320][1] = 87;
+waterCols[320][2] = 120;
+waterCols[321][0] = 23;
+waterCols[321][1] = 91;
+waterCols[321][2] = 123;
+waterCols[322][0] = 23;
+waterCols[322][1] = 95;
+waterCols[322][2] = 126;
+waterCols[323][0] = 24;
+waterCols[323][1] = 98;
+waterCols[323][2] = 128;
+waterCols[324][0] = 24;
+waterCols[324][1] = 98;
+waterCols[324][2] = 128;
+waterCols[325][0] = 23;
+waterCols[325][1] = 100;
+waterCols[325][2] = 129;
+waterCols[326][0] = 25;
+waterCols[326][1] = 102;
+waterCols[326][2] = 133;
+waterCols[327][0] = 26;
+waterCols[327][1] = 106;
+waterCols[327][2] = 136;
+waterCols[328][0] = 25;
+waterCols[328][1] = 108;
+waterCols[328][2] = 140;
+waterCols[329][0] = 26;
+waterCols[329][1] = 112;
+waterCols[329][2] = 140;
+waterCols[330][0] = 26;
+waterCols[330][1] = 112;
+waterCols[330][2] = 140;
+waterCols[331][0] = 29;
+waterCols[331][1] = 115;
+waterCols[331][2] = 143;
+waterCols[332][0] = 29;
+waterCols[332][1] = 118;
+waterCols[332][2] = 145;
+waterCols[333][0] = 29;
+waterCols[333][1] = 117;
+waterCols[333][2] = 147;
+waterCols[334][0] = 27;
+waterCols[334][1] = 116;
+waterCols[334][2] = 143;
+waterCols[335][0] = 24;
+waterCols[335][1] = 109;
+waterCols[335][2] = 140;
+waterCols[336][0] = 23;
+waterCols[336][1] = 107;
+waterCols[336][2] = 136;
+waterCols[337][0] = 23;
+waterCols[337][1] = 100;
+waterCols[337][2] = 131;
+waterCols[338][0] = 23;
+waterCols[338][1] = 95;
+waterCols[338][2] = 126;
+waterCols[339][0] = 21;
+waterCols[339][1] = 90;
+waterCols[339][2] = 122;
+waterCols[340][0] = 22;
+waterCols[340][1] = 87;
+waterCols[340][2] = 118;
+waterCols[341][0] = 24;
+waterCols[341][1] = 84;
+waterCols[341][2] = 117;
+waterCols[342][0] = 22;
+waterCols[342][1] = 77;
+waterCols[342][2] = 112;
+waterCols[343][0] = 21;
+waterCols[343][1] = 77;
+waterCols[343][2] = 107;
+waterCols[344][0] = 20;
+waterCols[344][1] = 71;
+waterCols[344][2] = 102;
+waterCols[345][0] = 18;
+waterCols[345][1] = 68;
+waterCols[345][2] = 97;
+waterCols[346][0] = 18;
+waterCols[346][1] = 65;
+waterCols[346][2] = 95;
+waterCols[347][0] = 18;
+waterCols[347][1] = 65;
+waterCols[347][2] = 95;
+waterCols[348][0] = 20;
+waterCols[348][1] = 67;
+waterCols[348][2] = 97;
+waterCols[349][0] = 20;
+waterCols[349][1] = 67;
+waterCols[349][2] = 97;
+waterCols[350][0] = 20;
+waterCols[350][1] = 67;
+waterCols[350][2] = 97;
+waterCols[351][0] = 20;
+waterCols[351][1] = 67;
+waterCols[351][2] = 97;
+waterCols[352][0] = 20;
+waterCols[352][1] = 67;
+waterCols[352][2] = 97;
+waterCols[353][0] = 19;
+waterCols[353][1] = 69;
+waterCols[353][2] = 98;
+waterCols[354][0] = 19;
+waterCols[354][1] = 69;
+waterCols[354][2] = 98;
+waterCols[355][0] = 19;
+waterCols[355][1] = 69;
+waterCols[355][2] = 98;
+waterCols[356][0] = 19;
+waterCols[356][1] = 69;
+waterCols[356][2] = 98;
+waterCols[357][0] = 18;
+waterCols[357][1] = 68;
+waterCols[357][2] = 97;
+waterCols[358][0] = 21;
+waterCols[358][1] = 65;
+waterCols[358][2] = 99;
+waterCols[359][0] = 20;
+waterCols[359][1] = 66;
+waterCols[359][2] = 99;
+waterCols[360][0] = 18;
+waterCols[360][1] = 68;
+waterCols[360][2] = 97;
+waterCols[361][0] = 18;
+waterCols[361][1] = 68;
+waterCols[361][2] = 97;
+waterCols[362][0] = 18;
+waterCols[362][1] = 68;
+waterCols[362][2] = 97;
+waterCols[363][0] = 21;
+waterCols[363][1] = 66;
+waterCols[363][2] = 97;
+waterCols[364][0] = 20;
+waterCols[364][1] = 67;
+waterCols[364][2] = 97;
+waterCols[365][0] = 18;
+waterCols[365][1] = 65;
+waterCols[365][2] = 95;
+waterCols[366][0] = 19;
+waterCols[366][1] = 64;
+waterCols[366][2] = 95;
+waterCols[367][0] = 18;
+waterCols[367][1] = 63;
+waterCols[367][2] = 94;
+waterCols[368][0] = 18;
+waterCols[368][1] = 63;
+waterCols[368][2] = 94;
+waterCols[369][0] = 18;
+waterCols[369][1] = 60;
+waterCols[369][2] = 96;
+waterCols[370][0] = 19;
+waterCols[370][1] = 61;
+waterCols[370][2] = 97;
+waterCols[371][0] = 18;
+waterCols[371][1] = 60;
+waterCols[371][2] = 96;
+waterCols[372][0] = 20;
+waterCols[372][1] = 62;
+waterCols[372][2] = 98;
+waterCols[373][0] = 23;
+waterCols[373][1] = 65;
+waterCols[373][2] = 101;
+waterCols[374][0] = 21;
+waterCols[374][1] = 66;
+waterCols[374][2] = 104;
+waterCols[375][0] = 17;
+waterCols[375][1] = 70;
+waterCols[375][2] = 107;
+waterCols[376][0] = 22;
+waterCols[376][1] = 72;
+waterCols[376][2] = 110;
+waterCols[377][0] = 23;
+waterCols[377][1] = 76;
+waterCols[377][2] = 113;
+waterCols[378][0] = 25;
+waterCols[378][1] = 78;
+waterCols[378][2] = 115;
+waterCols[379][0] = 23;
+waterCols[379][1] = 78;
+waterCols[379][2] = 115;
+waterCols[380][0] = 23;
+waterCols[380][1] = 78;
+waterCols[380][2] = 115;
+waterCols[381][0] = 23;
+waterCols[381][1] = 78;
+waterCols[381][2] = 113;
+waterCols[382][0] = 21;
+waterCols[382][1] = 78;
+waterCols[382][2] = 112;
+waterCols[383][0] = 20;
+waterCols[383][1] = 77;
+waterCols[383][2] = 111;
+waterCols[384][0] = 19;
+waterCols[384][1] = 76;
+waterCols[384][2] = 110;
+waterCols[385][0] = 22;
+waterCols[385][1] = 72;
+waterCols[385][2] = 108;
+waterCols[386][0] = 22;
+waterCols[386][1] = 72;
+waterCols[386][2] = 108;
+waterCols[387][0] = 21;
+waterCols[387][1] = 71;
+waterCols[387][2] = 107;
+waterCols[388][0] = 19;
+waterCols[388][1] = 70;
+waterCols[388][2] = 103;
+waterCols[389][0] = 21;
+waterCols[389][1] = 70;
+waterCols[389][2] = 104;
+waterCols[390][0] = 20;
+waterCols[390][1] = 66;
+waterCols[390][2] = 101;
+waterCols[391][0] = 21;
+waterCols[391][1] = 60;
+waterCols[391][2] = 97;
+waterCols[392][0] = 19;
+waterCols[392][1] = 56;
+waterCols[392][2] = 92;
+waterCols[393][0] = 19;
+waterCols[393][1] = 53;
+waterCols[393][2] = 90;
+waterCols[394][0] = 17;
+waterCols[394][1] = 51;
+waterCols[394][2] = 88;
+waterCols[395][0] = 17;
+waterCols[395][1] = 51;
+waterCols[395][2] = 88;
+waterCols[396][0] = 15;
+waterCols[396][1] = 52;
+waterCols[396][2] = 88;
+waterCols[397][0] = 19;
+waterCols[397][1] = 54;
+waterCols[397][2] = 88;
+waterCols[398][0] = 15;
+waterCols[398][1] = 60;
+waterCols[398][2] = 91;
+waterCols[399][0] = 20;
+waterCols[399][1] = 66;
+waterCols[399][2] = 99;
+waterCols[400][0] = 20;
+waterCols[400][1] = 69;
+waterCols[400][2] = 101;
+waterCols[401][0] = 22;
+waterCols[401][1] = 68;
+waterCols[401][2] = 103;
+waterCols[402][0] = 20;
+waterCols[402][1] = 76;
+waterCols[402][2] = 106;
+waterCols[403][0] = 20;
+waterCols[403][1] = 81;
+waterCols[403][2] = 111;
+waterCols[404][0] = 20;
+waterCols[404][1] = 80;
+waterCols[404][2] = 113;
+waterCols[405][0] = 22;
+waterCols[405][1] = 91;
+waterCols[405][2] = 121;
+waterCols[406][0] = 23;
+waterCols[406][1] = 95;
+waterCols[406][2] = 124;
+waterCols[407][0] = 25;
+waterCols[407][1] = 99;
+waterCols[407][2] = 127;
+waterCols[408][0] = 24;
+waterCols[408][1] = 105;
+waterCols[408][2] = 135;
+waterCols[409][0] = 25;
+waterCols[409][1] = 105;
+waterCols[409][2] = 133;
+waterCols[410][0] = 27;
+waterCols[410][1] = 107;
+waterCols[410][2] = 135;
+waterCols[411][0] = 25;
+waterCols[411][1] = 109;
+waterCols[411][2] = 136;
+waterCols[412][0] = 24;
+waterCols[412][1] = 108;
+waterCols[412][2] = 135;
+waterCols[413][0] = 24;
+waterCols[413][1] = 108;
+waterCols[413][2] = 135;
+waterCols[414][0] = 22;
+waterCols[414][1] = 103;
+waterCols[414][2] = 131;
+waterCols[415][0] = 21;
+waterCols[415][1] = 101;
+waterCols[415][2] = 129;
+waterCols[416][0] = 24;
+waterCols[416][1] = 93;
+waterCols[416][2] = 120;
+waterCols[417][0] = 22;
+waterCols[417][1] = 87;
+waterCols[417][2] = 118;
+waterCols[418][0] = 20;
+waterCols[418][1] = 82;
+waterCols[418][2] = 107;
+waterCols[419][0] = 20;
+waterCols[419][1] = 75;
+waterCols[419][2] = 102;
+waterCols[420][0] = 19;
+waterCols[420][1] = 69;
+waterCols[420][2] = 98;
+waterCols[421][0] = 20;
+waterCols[421][1] = 67;
+waterCols[421][2] = 97;
+waterCols[422][0] = 18;
+waterCols[422][1] = 68;
+waterCols[422][2] = 97;
+waterCols[423][0] = 19;
+waterCols[423][1] = 71;
+waterCols[423][2] = 99;
+waterCols[424][0] = 21;
+waterCols[424][1] = 73;
+waterCols[424][2] = 101;
+waterCols[425][0] = 20;
+waterCols[425][1] = 75;
+waterCols[425][2] = 102;
+waterCols[426][0] = 20;
+waterCols[426][1] = 75;
+waterCols[426][2] = 102;
+waterCols[427][0] = 22;
+waterCols[427][1] = 79;
+waterCols[427][2] = 106;
+waterCols[428][0] = 23;
+waterCols[428][1] = 82;
+waterCols[428][2] = 108;
+waterCols[429][0] = 22;
+waterCols[429][1] = 84;
+waterCols[429][2] = 109;
+waterCols[430][0] = 23;
+waterCols[430][1] = 89;
+waterCols[430][2] = 115;
+waterCols[431][0] = 25;
+waterCols[431][1] = 89;
+waterCols[431][2] = 113;
+waterCols[432][0] = 24;
+waterCols[432][1] = 90;
+waterCols[432][2] = 116;
+waterCols[433][0] = 22;
+waterCols[433][1] = 88;
+waterCols[433][2] = 114;
+waterCols[434][0] = 22;
+waterCols[434][1] = 84;
+waterCols[434][2] = 109;
+waterCols[435][0] = 21;
+waterCols[435][1] = 80;
+waterCols[435][2] = 104;
+waterCols[436][0] = 19;
+waterCols[436][1] = 78;
+waterCols[436][2] = 102;
+waterCols[437][0] = 20;
+waterCols[437][1] = 77;
+waterCols[437][2] = 102;
+waterCols[438][0] = 21;
+waterCols[438][1] = 73;
+waterCols[438][2] = 99;
+waterCols[439][0] = 21;
+waterCols[439][1] = 68;
+waterCols[439][2] = 96;
+waterCols[440][0] = 20;
+waterCols[440][1] = 63;
+waterCols[440][2] = 92;
+waterCols[441][0] = 20;
+waterCols[441][1] = 60;
+waterCols[441][2] = 88;
+waterCols[442][0] = 19;
+waterCols[442][1] = 57;
+waterCols[442][2] = 86;
+waterCols[443][0] = 16;
+waterCols[443][1] = 54;
+waterCols[443][2] = 83;
+waterCols[444][0] = 19;
+waterCols[444][1] = 51;
+waterCols[444][2] = 79;
+waterCols[445][0] = 18;
+waterCols[445][1] = 49;
+waterCols[445][2] = 80;
+waterCols[446][0] = 17;
+waterCols[446][1] = 50;
+waterCols[446][2] = 81;
+waterCols[447][0] = 17;
+waterCols[447][1] = 50;
+waterCols[447][2] = 81;
+waterCols[448][0] = 15;
+waterCols[448][1] = 50;
+waterCols[448][2] = 80;
+waterCols[449][0] = 17;
+waterCols[449][1] = 50;
+waterCols[449][2] = 83;
+waterCols[450][0] = 18;
+waterCols[450][1] = 51;
+waterCols[450][2] = 84;
+waterCols[451][0] = 18;
+waterCols[451][1] = 53;
+waterCols[451][2] = 85;
+waterCols[452][0] = 17;
+waterCols[452][1] = 55;
+waterCols[452][2] = 88;
+waterCols[453][0] = 18;
+waterCols[453][1] = 58;
+waterCols[453][2] = 90;
+waterCols[454][0] = 19;
+waterCols[454][1] = 59;
+waterCols[454][2] = 91;
+waterCols[455][0] = 19;
+waterCols[455][1] = 59;
+waterCols[455][2] = 91;
+waterCols[456][0] = 21;
+waterCols[456][1] = 59;
+waterCols[456][2] = 92;
+waterCols[457][0] = 20;
+waterCols[457][1] = 60;
+waterCols[457][2] = 92;
+waterCols[458][0] = 19;
+waterCols[458][1] = 56;
+waterCols[458][2] = 92;
+waterCols[459][0] = 18;
+waterCols[459][1] = 57;
+waterCols[459][2] = 92;
+waterCols[460][0] = 18;
+waterCols[460][1] = 57;
+waterCols[460][2] = 92;
+waterCols[461][0] = 18;
+waterCols[461][1] = 57;
+waterCols[461][2] = 92;
+waterCols[462][0] = 18;
+waterCols[462][1] = 57;
+waterCols[462][2] = 92;
+waterCols[463][0] = 19;
+waterCols[463][1] = 58;
+waterCols[463][2] = 93;
+waterCols[464][0] = 21;
+waterCols[464][1] = 65;
+waterCols[464][2] = 99;
+waterCols[465][0] = 21;
+waterCols[465][1] = 72;
+waterCols[465][2] = 103;
+waterCols[466][0] = 23;
+waterCols[466][1] = 77;
+waterCols[466][2] = 109;
+waterCols[467][0] = 23;
+waterCols[467][1] = 81;
+waterCols[467][2] = 112;
+waterCols[468][0] = 23;
+waterCols[468][1] = 85;
+waterCols[468][2] = 117;
+waterCols[469][0] = 26;
+waterCols[469][1] = 88;
+waterCols[469][2] = 120;
+waterCols[470][0] = 22;
+waterCols[470][1] = 90;
+waterCols[470][2] = 122;
+waterCols[471][0] = 25;
+waterCols[471][1] = 87;
+waterCols[471][2] = 119;
+waterCols[472][0] = 23;
+waterCols[472][1] = 85;
+waterCols[472][2] = 117;
+waterCols[473][0] = 21;
+waterCols[473][1] = 83;
+waterCols[473][2] = 115;
+waterCols[474][0] = 21;
+waterCols[474][1] = 81;
+waterCols[474][2] = 114;
+waterCols[475][0] = 20;
+waterCols[475][1] = 78;
+waterCols[475][2] = 109;
+waterCols[476][0] = 20;
+waterCols[476][1] = 76;
+waterCols[476][2] = 108;
+waterCols[477][0] = 17;
+waterCols[477][1] = 73;
+waterCols[477][2] = 105;
+waterCols[478][0] = 21;
+waterCols[478][1] = 70;
+waterCols[478][2] = 104;
+waterCols[479][0] = 21;
+waterCols[479][1] = 67;
+waterCols[479][2] = 102;
+waterCols[480][0] = 18;
+waterCols[480][1] = 64;
+waterCols[480][2] = 99;
+waterCols[481][0] = 20;
+waterCols[481][1] = 66;
+waterCols[481][2] = 101;
+waterCols[482][0] = 19;
+waterCols[482][1] = 61;
+waterCols[482][2] = 97;
+waterCols[483][0] = 21;
+waterCols[483][1] = 60;
+waterCols[483][2] = 95;
+waterCols[484][0] = 20;
+waterCols[484][1] = 59;
+waterCols[484][2] = 94;
+waterCols[485][0] = 20;
+waterCols[485][1] = 59;
+waterCols[485][2] = 94;
+waterCols[486][0] = 19;
+waterCols[486][1] = 61;
+waterCols[486][2] = 95;
+waterCols[487][0] = 19;
+waterCols[487][1] = 63;
+waterCols[487][2] = 97;
+waterCols[488][0] = 20;
+waterCols[488][1] = 66;
+waterCols[488][2] = 99;
+waterCols[489][0] = 18;
+waterCols[489][1] = 64;
+waterCols[489][2] = 97;
+waterCols[490][0] = 17;
+waterCols[490][1] = 68;
+waterCols[490][2] = 99;
+waterCols[491][0] = 18;
+waterCols[491][1] = 69;
+waterCols[491][2] = 100;
+waterCols[492][0] = 20;
+waterCols[492][1] = 69;
+waterCols[492][2] = 103;
+waterCols[493][0] = 19;
+waterCols[493][1] = 73;
+waterCols[493][2] = 105;
+waterCols[494][0] = 19;
+waterCols[494][1] = 72;
+waterCols[494][2] = 107;
+waterCols[495][0] = 20;
+waterCols[495][1] = 75;
+waterCols[495][2] = 110;
+waterCols[496][0] = 22;
+waterCols[496][1] = 78;
+waterCols[496][2] = 110;
+waterCols[497][0] = 22;
+waterCols[497][1] = 78;
+waterCols[497][2] = 110;
+waterCols[498][0] = 22;
+waterCols[498][1] = 78;
+waterCols[498][2] = 110;
+waterCols[499][0] = 23;
+waterCols[499][1] = 80;
+waterCols[499][2] = 114;
+waterCols[500][0] = 23;
+waterCols[500][1] = 85;
+waterCols[500][2] = 117;
+waterCols[501][0] = 23;
+waterCols[501][1] = 88;
+waterCols[501][2] = 119;
+waterCols[502][0] = 23;
+waterCols[502][1] = 91;
+waterCols[502][2] = 121;
+waterCols[503][0] = 25;
+waterCols[503][1] = 94;
+waterCols[503][2] = 124;
+waterCols[504][0] = 25;
+waterCols[504][1] = 94;
+waterCols[504][2] = 124;
+waterCols[505][0] = 25;
+waterCols[505][1] = 94;
+waterCols[505][2] = 124;
+waterCols[506][0] = 23;
+waterCols[506][1] = 92;
+waterCols[506][2] = 122;
+waterCols[507][0] = 23;
+waterCols[507][1] = 91;
+waterCols[507][2] = 121;
+waterCols[508][0] = 24;
+waterCols[508][1] = 87;
+waterCols[508][2] = 116;
+waterCols[509][0] = 23;
+waterCols[509][1] = 79;
+waterCols[509][2] = 109;
+waterCols[510][0] = 22;
+waterCols[510][1] = 78;
+waterCols[510][2] = 108;
+waterCols[511][0] = 22;
+waterCols[511][1] = 76;
+waterCols[511][2] = 108;
+waterCols[512][0] = 21;
+waterCols[512][1] = 71;
+waterCols[512][2] = 100;
+waterCols[513][0] = 23;
+waterCols[513][1] = 70;
+waterCols[513][2] = 100;
+waterCols[514][0] = 22;
+waterCols[514][1] = 67;
+waterCols[514][2] = 96;
+waterCols[515][0] = 21;
+waterCols[515][1] = 66;
+waterCols[515][2] = 95;
+waterCols[516][0] = 20;
+waterCols[516][1] = 63;
+waterCols[516][2] = 94;
+waterCols[517][0] = 20;
+waterCols[517][1] = 63;
+waterCols[517][2] = 94;
+waterCols[518][0] = 19;
+waterCols[518][1] = 59;
+waterCols[518][2] = 91;
+waterCols[519][0] = 19;
+waterCols[519][1] = 59;
+waterCols[519][2] = 89;
+waterCols[520][0] = 19;
+waterCols[520][1] = 54;
+waterCols[520][2] = 86;
+waterCols[521][0] = 17;
+waterCols[521][1] = 50;
+waterCols[521][2] = 81;
+waterCols[522][0] = 14;
+waterCols[522][1] = 45;
+waterCols[522][2] = 76;
+waterCols[523][0] = 15;
+waterCols[523][1] = 41;
+waterCols[523][2] = 76;
+waterCols[524][0] = 12;
+waterCols[524][1] = 36;
+waterCols[524][2] = 67;
+waterCols[525][0] = 12;
+waterCols[525][1] = 36;
+waterCols[525][2] = 67;
+waterCols[526][0] = 15;
+waterCols[526][1] = 39;
+waterCols[526][2] = 70;
+waterCols[527][0] = 14;
+waterCols[527][1] = 41;
+waterCols[527][2] = 71;
+waterCols[528][0] = 14;
+waterCols[528][1] = 41;
+waterCols[528][2] = 71;
+waterCols[529][0] = 15;
+waterCols[529][1] = 38;
+waterCols[529][2] = 72;
+waterCols[530][0] = 13;
+waterCols[530][1] = 37;
+waterCols[530][2] = 68;
+waterCols[531][0] = 13;
+waterCols[531][1] = 34;
+waterCols[531][2] = 69;
+waterCols[532][0] = 15;
+waterCols[532][1] = 39;
+waterCols[532][2] = 68;
+waterCols[533][0] = 11;
+waterCols[533][1] = 38;
+waterCols[533][2] = 66;
+waterCols[534][0] = 12;
+waterCols[534][1] = 44;
+waterCols[534][2] = 70;
+waterCols[535][0] = 15;
+waterCols[535][1] = 47;
+waterCols[535][2] = 73;
+waterCols[536][0] = 19;
+waterCols[536][1] = 51;
+waterCols[536][2] = 79;
+waterCols[537][0] = 17;
+waterCols[537][1] = 56;
+waterCols[537][2] = 82;
+waterCols[538][0] = 19;
+waterCols[538][1] = 58;
+waterCols[538][2] = 84;
+waterCols[539][0] = 20;
+waterCols[539][1] = 61;
+waterCols[539][2] = 86;
+waterCols[540][0] = 19;
+waterCols[540][1] = 62;
+waterCols[540][2] = 89;
+waterCols[541][0] = 18;
+waterCols[541][1] = 65;
+waterCols[541][2] = 91;
+waterCols[542][0] = 20;
+waterCols[542][1] = 70;
+waterCols[542][2] = 97;
+waterCols[543][0] = 20;
+waterCols[543][1] = 72;
+waterCols[543][2] = 100;
+waterCols[544][0] = 22;
+waterCols[544][1] = 77;
+waterCols[544][2] = 102;
+waterCols[545][0] = 21;
+waterCols[545][1] = 80;
+waterCols[545][2] = 106;
+waterCols[546][0] = 22;
+waterCols[546][1] = 81;
+waterCols[546][2] = 107;
+waterCols[547][0] = 22;
+waterCols[547][1] = 81;
+waterCols[547][2] = 107;
+waterCols[548][0] = 22;
+waterCols[548][1] = 80;
+waterCols[548][2] = 111;
+waterCols[549][0] = 23;
+waterCols[549][1] = 85;
+waterCols[549][2] = 117;
+waterCols[550][0] = 20;
+waterCols[550][1] = 89;
+waterCols[550][2] = 116;
+waterCols[551][0] = 22;
+waterCols[551][1] = 90;
+waterCols[551][2] = 120;
+waterCols[552][0] = 25;
+waterCols[552][1] = 94;
+waterCols[552][2] = 126;
+waterCols[553][0] = 25;
+waterCols[553][1] = 97;
+waterCols[553][2] = 126;
+waterCols[554][0] = 25;
+waterCols[554][1] = 97;
+waterCols[554][2] = 128;
+waterCols[555][0] = 24;
+waterCols[555][1] = 98;
+waterCols[555][2] = 128;
+waterCols[556][0] = 23;
+waterCols[556][1] = 100;
+waterCols[556][2] = 129;
+waterCols[557][0] = 23;
+waterCols[557][1] = 100;
+waterCols[557][2] = 129;
+waterCols[558][0] = 24;
+waterCols[558][1] = 101;
+waterCols[558][2] = 130;
+waterCols[559][0] = 26;
+waterCols[559][1] = 100;
+waterCols[559][2] = 130;
+waterCols[560][0] = 24;
+waterCols[560][1] = 98;
+waterCols[560][2] = 128;
+waterCols[561][0] = 24;
+waterCols[561][1] = 98;
+waterCols[561][2] = 128;
+waterCols[562][0] = 24;
+waterCols[562][1] = 98;
+waterCols[562][2] = 128;
+waterCols[563][0] = 24;
+waterCols[563][1] = 98;
+waterCols[563][2] = 128;
+waterCols[564][0] = 24;
+waterCols[564][1] = 98;
+waterCols[564][2] = 128;
+waterCols[565][0] = 26;
+waterCols[565][1] = 100;
+waterCols[565][2] = 130;
+waterCols[566][0] = 23;
+waterCols[566][1] = 106;
+waterCols[566][2] = 138;
+waterCols[567][0] = 24;
+waterCols[567][1] = 109;
+waterCols[567][2] = 142;
+waterCols[568][0] = 24;
+waterCols[568][1] = 112;
+waterCols[568][2] = 144;
+waterCols[569][0] = 26;
+waterCols[569][1] = 117;
+waterCols[569][2] = 148;
+waterCols[570][0] = 26;
+waterCols[570][1] = 121;
+waterCols[570][2] = 151;
+waterCols[571][0] = 25;
+waterCols[571][1] = 122;
+waterCols[571][2] = 153;
+waterCols[572][0] = 29;
+waterCols[572][1] = 124;
+waterCols[572][2] = 156;
+waterCols[573][0] = 28;
+waterCols[573][1] = 124;
+waterCols[573][2] = 158;
+waterCols[574][0] = 28;
+waterCols[574][1] = 124;
+waterCols[574][2] = 158;
+waterCols[575][0] = 29;
+waterCols[575][1] = 123;
+waterCols[575][2] = 158;
+waterCols[576][0] = 29;
+waterCols[576][1] = 123;
+waterCols[576][2] = 158;
+waterCols[577][0] = 26;
+waterCols[577][1] = 121;
+waterCols[577][2] = 153;
+waterCols[578][0] = 27;
+waterCols[578][1] = 119;
+waterCols[578][2] = 152;
+waterCols[579][0] = 27;
+waterCols[579][1] = 112;
+waterCols[579][2] = 145;
+waterCols[580][0] = 23;
+waterCols[580][1] = 106;
+waterCols[580][2] = 138;
+waterCols[581][0] = 24;
+waterCols[581][1] = 96;
+waterCols[581][2] = 129;
+waterCols[582][0] = 19;
+waterCols[582][1] = 91;
+waterCols[582][2] = 122;
+waterCols[583][0] = 23;
+waterCols[583][1] = 85;
+waterCols[583][2] = 117;
+waterCols[584][0] = 20;
+waterCols[584][1] = 81;
+waterCols[584][2] = 111;
+waterCols[585][0] = 22;
+waterCols[585][1] = 71;
+waterCols[585][2] = 105;
+waterCols[586][0] = 20;
+waterCols[586][1] = 66;
+waterCols[586][2] = 99;
+waterCols[587][0] = 18;
+waterCols[587][1] = 60;
+waterCols[587][2] = 94;
+waterCols[588][0] = 15;
+waterCols[588][1] = 53;
+waterCols[588][2] = 86;
+waterCols[589][0] = 16;
+waterCols[589][1] = 51;
+waterCols[589][2] = 85;
+waterCols[590][0] = 18;
+waterCols[590][1] = 49;
+waterCols[590][2] = 84;
+waterCols[591][0] = 19;
+waterCols[591][1] = 50;
+waterCols[591][2] = 85;
+waterCols[592][0] = 16;
+waterCols[592][1] = 49;
+waterCols[592][2] = 84;
+waterCols[593][0] = 16;
+waterCols[593][1] = 49;
+waterCols[593][2] = 84;
+waterCols[594][0] = 19;
+waterCols[594][1] = 47;
+waterCols[594][2] = 83;
+waterCols[595][0] = 17;
+waterCols[595][1] = 45;
+waterCols[595][2] = 81;
+waterCols[596][0] = 14;
+waterCols[596][1] = 45;
+waterCols[596][2] = 78;
+waterCols[597][0] = 13;
+waterCols[597][1] = 47;
+waterCols[597][2] = 75;
+waterCols[598][0] = 15;
+waterCols[598][1] = 49;
+waterCols[598][2] = 77;
+waterCols[599][0] = 15;
+waterCols[599][1] = 49;
+waterCols[599][2] = 77;
+waterCols[600][0] = 15;
+waterCols[600][1] = 47;
+waterCols[600][2] = 73;
+waterCols[601][0] = 17;
+waterCols[601][1] = 49;
+waterCols[601][2] = 75;
+waterCols[602][0] = 15;
+waterCols[602][1] = 47;
+waterCols[602][2] = 73;
+waterCols[603][0] = 15;
+waterCols[603][1] = 47;
+waterCols[603][2] = 73;
+waterCols[604][0] = 15;
+waterCols[604][1] = 47;
+waterCols[604][2] = 73;
+waterCols[605][0] = 15;
+waterCols[605][1] = 47;
+waterCols[605][2] = 73;
+waterCols[606][0] = 15;
+waterCols[606][1] = 47;
+waterCols[606][2] = 73;
+waterCols[607][0] = 18;
+waterCols[607][1] = 52;
+waterCols[607][2] = 80;
+waterCols[608][0] = 19;
+waterCols[608][1] = 54;
+waterCols[608][2] = 84;
+waterCols[609][0] = 21;
+waterCols[609][1] = 59;
+waterCols[609][2] = 90;
+waterCols[610][0] = 21;
+waterCols[610][1] = 61;
+waterCols[610][2] = 93;
+waterCols[611][0] = 18;
+waterCols[611][1] = 61;
+waterCols[611][2] = 92;
+waterCols[612][0] = 17;
+waterCols[612][1] = 60;
+waterCols[612][2] = 91;
+waterCols[613][0] = 17;
+waterCols[613][1] = 60;
+waterCols[613][2] = 91;
+waterCols[614][0] = 16;
+waterCols[614][1] = 56;
+waterCols[614][2] = 88;
+waterCols[615][0] = 17;
+waterCols[615][1] = 55;
+waterCols[615][2] = 86;
+waterCols[616][0] = 16;
+waterCols[616][1] = 54;
+waterCols[616][2] = 85;
+waterCols[617][0] = 19;
+waterCols[617][1] = 57;
+waterCols[617][2] = 90;
+waterCols[618][0] = 19;
+waterCols[618][1] = 56;
+waterCols[618][2] = 92;
+waterCols[619][0] = 18;
+waterCols[619][1] = 58;
+waterCols[619][2] = 90;
+waterCols[620][0] = 16;
+waterCols[620][1] = 59;
+waterCols[620][2] = 90;
+waterCols[621][0] = 18;
+waterCols[621][1] = 61;
+waterCols[621][2] = 90;
+waterCols[622][0] = 19;
+waterCols[622][1] = 61;
+waterCols[622][2] = 95;
+waterCols[623][0] = 18;
+waterCols[623][1] = 63;
+waterCols[623][2] = 94;
+waterCols[624][0] = 18;
+waterCols[624][1] = 64;
+waterCols[624][2] = 97;
+waterCols[625][0] = 21;
+waterCols[625][1] = 67;
+waterCols[625][2] = 100;
+waterCols[626][0] = 20;
+waterCols[626][1] = 69;
+waterCols[626][2] = 103;
+waterCols[627][0] = 20;
+waterCols[627][1] = 74;
+waterCols[627][2] = 106;
+waterCols[628][0] = 21;
+waterCols[628][1] = 77;
+waterCols[628][2] = 109;
+waterCols[629][0] = 21;
+waterCols[629][1] = 79;
+waterCols[629][2] = 110;
+waterCols[630][0] = 19;
+waterCols[630][1] = 80;
+waterCols[630][2] = 110;
+waterCols[631][0] = 21;
+waterCols[631][1] = 83;
+waterCols[631][2] = 115;
+waterCols[632][0] = 21;
+waterCols[632][1] = 83;
+waterCols[632][2] = 115;
+waterCols[633][0] = 21;
+waterCols[633][1] = 86;
+waterCols[633][2] = 117;
+waterCols[634][0] = 19;
+waterCols[634][1] = 87;
+waterCols[634][2] = 117;
+waterCols[635][0] = 20;
+waterCols[635][1] = 88;
+waterCols[635][2] = 118;
+waterCols[636][0] = 23;
+waterCols[636][1] = 92;
+waterCols[636][2] = 119;
+waterCols[637][0] = 26;
+waterCols[637][1] = 94;
+waterCols[637][2] = 124;
+waterCols[638][0] = 25;
+waterCols[638][1] = 94;
+waterCols[638][2] = 124;
+waterCols[639][0] = 25;
+waterCols[639][1] = 99;
+waterCols[639][2] = 127;
+waterCols[640][0] = 23;
+waterCols[640][1] = 100;
+waterCols[640][2] = 127;
+waterCols[641][0] = 23;
+waterCols[641][1] = 100;
+waterCols[641][2] = 129;
+waterCols[642][0] = 24;
+waterCols[642][1] = 101;
+waterCols[642][2] = 132;
+waterCols[643][0] = 23;
+waterCols[643][1] = 103;
+waterCols[643][2] = 133;
+waterCols[644][0] = 25;
+waterCols[644][1] = 106;
+waterCols[644][2] = 136;
+waterCols[645][0] = 24;
+waterCols[645][1] = 108;
+waterCols[645][2] = 137;
+waterCols[646][0] = 24;
+waterCols[646][1] = 108;
+waterCols[646][2] = 137;
+waterCols[647][0] = 25;
+waterCols[647][1] = 109;
+waterCols[647][2] = 136;
+waterCols[648][0] = 25;
+waterCols[648][1] = 109;
+waterCols[648][2] = 138;
+waterCols[649][0] = 25;
+waterCols[649][1] = 109;
+waterCols[649][2] = 138;
+waterCols[650][0] = 24;
+waterCols[650][1] = 108;
+waterCols[650][2] = 137;
+waterCols[651][0] = 24;
+waterCols[651][1] = 108;
+waterCols[651][2] = 137;
+waterCols[652][0] = 26;
+waterCols[652][1] = 107;
+waterCols[652][2] = 137;
+waterCols[653][0] = 25;
+waterCols[653][1] = 106;
+waterCols[653][2] = 136;
+waterCols[654][0] = 26;
+waterCols[654][1] = 107;
+waterCols[654][2] = 137;
+waterCols[655][0] = 24;
+waterCols[655][1] = 105;
+waterCols[655][2] = 131;
+waterCols[656][0] = 26;
+waterCols[656][1] = 98;
+waterCols[656][2] = 129;
+waterCols[657][0] = 23;
+waterCols[657][1] = 92;
+waterCols[657][2] = 122;
+waterCols[658][0] = 20;
+waterCols[658][1] = 83;
+waterCols[658][2] = 110;
+waterCols[659][0] = 18;
+waterCols[659][1] = 72;
+waterCols[659][2] = 102;
+waterCols[660][0] = 17;
+waterCols[660][1] = 63;
+waterCols[660][2] = 96;
+waterCols[661][0] = 17;
+waterCols[661][1] = 55;
+waterCols[661][2] = 86;
+waterCols[662][0] = 16;
+waterCols[662][1] = 49;
+waterCols[662][2] = 82;
+waterCols[663][0] = 14;
+waterCols[663][1] = 45;
+waterCols[663][2] = 78;
+waterCols[664][0] = 12;
+waterCols[664][1] = 35;
+waterCols[664][2] = 69;
+waterCols[665][0] = 14;
+waterCols[665][1] = 36;
+waterCols[665][2] = 68;
+waterCols[666][0] = 12;
+waterCols[666][1] = 36;
+waterCols[666][2] = 67;
+waterCols[667][0] = 16;
+waterCols[667][1] = 40;
+waterCols[667][2] = 71;
+waterCols[668][0] = 18;
+waterCols[668][1] = 41;
+waterCols[668][2] = 75;
+waterCols[669][0] = 19;
+waterCols[669][1] = 46;
+waterCols[669][2] = 85;
+waterCols[670][0] = 19;
+waterCols[670][1] = 52;
+waterCols[670][2] = 87;
+waterCols[671][0] = 21;
+waterCols[671][1] = 61;
+waterCols[671][2] = 93;
+waterCols[672][0] = 21;
+waterCols[672][1] = 68;
+waterCols[672][2] = 98;
+waterCols[673][0] = 21;
+waterCols[673][1] = 71;
+waterCols[673][2] = 100;
+waterCols[674][0] = 20;
+waterCols[674][1] = 75;
+waterCols[674][2] = 100;
+waterCols[675][0] = 21;
+waterCols[675][1] = 79;
+waterCols[675][2] = 108;
+waterCols[676][0] = 21;
+waterCols[676][1] = 82;
+waterCols[676][2] = 110;
+waterCols[677][0] = 20;
+waterCols[677][1] = 89;
+waterCols[677][2] = 116;
+waterCols[678][0] = 22;
+waterCols[678][1] = 92;
+waterCols[678][2] = 119;
+waterCols[679][0] = 23;
+waterCols[679][1] = 95;
+waterCols[679][2] = 124;
+waterCols[680][0] = 21;
+waterCols[680][1] = 93;
+waterCols[680][2] = 122;
+waterCols[681][0] = 22;
+waterCols[681][1] = 96;
+waterCols[681][2] = 124;
+waterCols[682][0] = 22;
+waterCols[682][1] = 88;
+waterCols[682][2] = 114;
+waterCols[683][0] = 19;
+waterCols[683][1] = 85;
+waterCols[683][2] = 111;
+waterCols[684][0] = 20;
+waterCols[684][1] = 81;
+waterCols[684][2] = 111;
+waterCols[685][0] = 18;
+waterCols[685][1] = 79;
+waterCols[685][2] = 109;
+waterCols[686][0] = 20;
+waterCols[686][1] = 76;
+waterCols[686][2] = 106;
+waterCols[687][0] = 20;
+waterCols[687][1] = 78;
+waterCols[687][2] = 109;
+waterCols[688][0] = 20;
+waterCols[688][1] = 78;
+waterCols[688][2] = 109;
+waterCols[689][0] = 23;
+waterCols[689][1] = 77;
+waterCols[689][2] = 107;
+waterCols[690][0] = 24;
+waterCols[690][1] = 76;
+waterCols[690][2] = 104;
+waterCols[691][0] = 24;
+waterCols[691][1] = 76;
+waterCols[691][2] = 104;
+waterCols[692][0] = 18;
+waterCols[692][1] = 74;
+waterCols[692][2] = 104;
+waterCols[693][0] = 21;
+waterCols[693][1] = 70;
+waterCols[693][2] = 102;
+waterCols[694][0] = 19;
+waterCols[694][1] = 69;
+waterCols[694][2] = 98;
+waterCols[695][0] = 19;
+waterCols[695][1] = 64;
+waterCols[695][2] = 95;
+waterCols[696][0] = 19;
+waterCols[696][1] = 59;
+waterCols[696][2] = 89;
+waterCols[697][0] = 17;
+waterCols[697][1] = 52;
+waterCols[697][2] = 84;
+waterCols[698][0] = 14;
+waterCols[698][1] = 45;
+waterCols[698][2] = 78;
+waterCols[699][0] = 14;
+waterCols[699][1] = 40;
+waterCols[699][2] = 73;
+waterCols[700][0] = 13;
+waterCols[700][1] = 39;
+waterCols[700][2] = 74;
+waterCols[701][0] = 11;
+waterCols[701][1] = 37;
+waterCols[701][2] = 72;
+waterCols[702][0] = 13;
+waterCols[702][1] = 39;
+waterCols[702][2] = 74;
+waterCols[703][0] = 14;
+waterCols[703][1] = 40;
+waterCols[703][2] = 75;
+waterCols[704][0] = 15;
+waterCols[704][1] = 41;
+waterCols[704][2] = 76;
+waterCols[705][0] = 16;
+waterCols[705][1] = 44;
+waterCols[705][2] = 78;
+waterCols[706][0] = 17;
+waterCols[706][1] = 45;
+waterCols[706][2] = 79;
+waterCols[707][0] = 17;
+waterCols[707][1] = 50;
+waterCols[707][2] = 83;
+waterCols[708][0] = 17;
+waterCols[708][1] = 52;
+waterCols[708][2] = 86;
+waterCols[709][0] = 16;
+waterCols[709][1] = 56;
+waterCols[709][2] = 88;
+waterCols[710][0] = 18;
+waterCols[710][1] = 58;
+waterCols[710][2] = 90;
+waterCols[711][0] = 17;
+waterCols[711][1] = 55;
+waterCols[711][2] = 88;
+waterCols[712][0] = 17;
+waterCols[712][1] = 52;
+waterCols[712][2] = 86;
+waterCols[713][0] = 17;
+waterCols[713][1] = 52;
+waterCols[713][2] = 86;
+waterCols[714][0] = 17;
+waterCols[714][1] = 48;
+waterCols[714][2] = 81;
+waterCols[715][0] = 17;
+waterCols[715][1] = 48;
+waterCols[715][2] = 81;
+waterCols[716][0] = 16;
+waterCols[716][1] = 51;
+waterCols[716][2] = 85;
+waterCols[717][0] = 19;
+waterCols[717][1] = 62;
+waterCols[717][2] = 91;
+waterCols[718][0] = 19;
+waterCols[718][1] = 71;
+waterCols[718][2] = 99;
+waterCols[719][0] = 21;
+waterCols[719][1] = 73;
+waterCols[719][2] = 101;
+waterCols[720][0] = 18;
+waterCols[720][1] = 75;
+waterCols[720][2] = 102;
+waterCols[721][0] = 21;
+waterCols[721][1] = 78;
+waterCols[721][2] = 105;
+waterCols[722][0] = 21;
+waterCols[722][1] = 78;
+waterCols[722][2] = 105;
+waterCols[723][0] = 22;
+waterCols[723][1] = 77;
+waterCols[723][2] = 104;
+waterCols[724][0] = 22;
+waterCols[724][1] = 77;
+waterCols[724][2] = 104;
+waterCols[725][0] = 22;
+waterCols[725][1] = 77;
+waterCols[725][2] = 104;
+waterCols[726][0] = 19;
+waterCols[726][1] = 74;
+waterCols[726][2] = 101;
+waterCols[727][0] = 21;
+waterCols[727][1] = 80;
+waterCols[727][2] = 106;
+waterCols[728][0] = 23;
+waterCols[728][1] = 86;
+waterCols[728][2] = 115;
+waterCols[729][0] = 23;
+waterCols[729][1] = 89;
+waterCols[729][2] = 117;
+waterCols[730][0] = 25;
+waterCols[730][1] = 88;
+waterCols[730][2] = 115;
+waterCols[731][0] = 24;
+waterCols[731][1] = 87;
+waterCols[731][2] = 114;
+waterCols[732][0] = 21;
+waterCols[732][1] = 84;
+waterCols[732][2] = 113;
+waterCols[733][0] = 19;
+waterCols[733][1] = 85;
+waterCols[733][2] = 113;
+waterCols[734][0] = 21;
+waterCols[734][1] = 82;
+waterCols[734][2] = 112;
+waterCols[735][0] = 22;
+waterCols[735][1] = 78;
+waterCols[735][2] = 110;
+waterCols[736][0] = 22;
+waterCols[736][1] = 78;
+waterCols[736][2] = 110;
+waterCols[737][0] = 21;
+waterCols[737][1] = 77;
+waterCols[737][2] = 109;
+waterCols[738][0] = 23;
+waterCols[738][1] = 79;
+waterCols[738][2] = 111;
+waterCols[739][0] = 22;
+waterCols[739][1] = 80;
+waterCols[739][2] = 111;
+waterCols[740][0] = 21;
+waterCols[740][1] = 79;
+waterCols[740][2] = 110;
+waterCols[741][0] = 21;
+waterCols[741][1] = 79;
+waterCols[741][2] = 110;
+waterCols[742][0] = 23;
+waterCols[742][1] = 81;
+waterCols[742][2] = 110;
+waterCols[743][0] = 23;
+waterCols[743][1] = 81;
+waterCols[743][2] = 110;
+waterCols[744][0] = 23;
+waterCols[744][1] = 81;
+waterCols[744][2] = 110;
+waterCols[745][0] = 24;
+waterCols[745][1] = 82;
+waterCols[745][2] = 111;
+waterCols[746][0] = 24;
+waterCols[746][1] = 85;
+waterCols[746][2] = 113;
+waterCols[747][0] = 26;
+waterCols[747][1] = 89;
+waterCols[747][2] = 118;
+waterCols[748][0] = 25;
+waterCols[748][1] = 90;
+waterCols[748][2] = 121;
+waterCols[749][0] = 23;
+waterCols[749][1] = 91;
+waterCols[749][2] = 121;
+
 }

 // This is our main loop


commands with variable parameters

commands with variable parameters

--- Garan_Test/Garan_Test.ino
+++ Garan_Test/Garan_Test.ino
@@ -8,13 +8,11 @@

 #include <SoftwareSerial.h>

+#if !defined(__MSP430_CPU__)
 SoftwareSerial player(2, 3); // RX, TX
-
-void waitButton() {
-  delay(3000);
-}
-
-unsigned char commandBuffer[10];
+#else
+SoftwareSerial player(P1_4, P1_5); // RX, TX
+#endif

 const unsigned char SINGLE_PLAY[]        = {0x04, 0x01, 0x00, 0x00, 0x01};  // NH NL
 const unsigned char SEQUENCE_PLAY[]      = {0x04, 0x02, 0x00, 0x00, 0x02};  // NH NL
@@ -42,51 +40,144 @@
 const unsigned char NO_FEEDBACK_AT_END[] = {0x03, 0xA0, 0x01, 0x00};
 const unsigned char GET_VERSION[]        = {0x02, 0x80, 0x01};

+unsigned char commandBuff[13];
+
+inline void buildCommand(unsigned char len, unsigned char cmd) {
+  commandBuff[0] = len;
+  commandBuff[1] = cmd;
+}
+
+unsigned char *singlePlay(unsigned int number) {
+  buildCommand(0x04, 0x01);
+  commandBuff[3] = number >> 8;
+  commandBuff[4] = number;
+
+  return commandBuff;
+}
+
+unsigned char *sequencePlay(unsigned int number) {
+  buildCommand(0x04, 0x02);
+  commandBuff[3] = number >> 8;
+  commandBuff[4] = number;
+
+  return commandBuff;
+}
+
+unsigned char *singleLoopPlay(unsigned int number) {
+  buildCommand(0x04, 0x02);
+  commandBuff[3] = number >> 8;
+  commandBuff[4] = number;
+
+  return commandBuff;
+}
+
+unsigned char *singlePlayName(String name) {
+  name.toCharArray((char *)&commandBuff[3], name.length() + 1);
+  buildCommand(name.length() + 2, 4);
+
+  return commandBuff;
+}
+
+unsigned char *sequencePlayName(String name) {
+  name.toCharArray((char *)&commandBuff[3], name.length() + 1);
+  buildCommand(name.length() + 2, 5);
+
+  return commandBuff;
+}
+
+unsigned char *singleLoopName(String name) {
+  name.toCharArray((char *)&commandBuff[3], name.length() + 1);
+  buildCommand(name.length() + 2, 6);
+
+  return commandBuff;
+}
+
+unsigned char *setVolume(unsigned char volume) {
+  buildCommand(0x03, 0x0D);
+  commandBuff[3] = volume;
+
+  return commandBuff;
+}
+
 void sendCommand(unsigned char command[]) {
   unsigned char checksum = 0;

   player.write(0x24);
+  Serial.print(String(0x24, HEX) + ' ');

   for (unsigned int i = 0; i <= command[0]; i++) {
     player.write(command[i]);
+    Serial.print(String(command[i], HEX) + ' ');
     checksum ^= command[i];
   }
-
   player.write(checksum);
+  Serial.print(String(checksum, HEX) + '\n');
 }

 void setup() {
   //Initialize serial and wait for port to open:
-  Serial.begin(115200);
+  Serial.begin(9600);
+
+#if !defined(__MSP430_CPU__)
+  // wait for USB CDC serial port to connect.  Arduino Leonardo only
   while (!Serial) {
-    ; // wait for serial port to connect. Needed for Leonardo only
   }
-  Serial.println("Arduino is ready!");
+#endif
+  Serial.println("Console is ready!");

   player.begin(9600);
+
+  // this byte must be 0
+  commandBuff[2] = 0;
 }

 void loop() {
   if (Serial.available()) {
     switch(Serial.read()) {
       case '1':
-        sendCommand((unsigned char *)GET_VERSION);
+        sendCommand(singlePlay(1));
         break;
       case '2':
-        sendCommand((unsigned char *)SEQUENCE_PLAY);
+        sendCommand(singlePlay(2));
         break;
       case '3':
+        sendCommand(singlePlay(3));
+        break;
+      case '4':
+        sendCommand(singlePlayName("01.mp3"));
+        break;
+      case '5':
+        sendCommand(sequencePlayName("01.mp3"));
+        break;
+      case '6':
+        sendCommand(singleLoopName("01.mp3"));
+        break;
+      case '9':
+        sendCommand(setVolume(15));
+        break;
+      case '0':
+        sendCommand(setVolume(0));
+        break;
+      case 'n':
         sendCommand((unsigned char *)NEXT);
         break;
-      case '4':
+      case 'l':
+        sendCommand((unsigned char *)LAST);
+        break;
+      case 't':
         sendCommand((unsigned char *)GET_MUSIC_TOTALITY);
+        break;
+      case 'v':
+        sendCommand((unsigned char *)GET_VERSION);
         break;
       case ']':
         sendCommand((unsigned char *)VOLUME_ADD);
         break;
       case '[':
         sendCommand((unsigned char *)VOLUME_SUBSTRACT);
-        break;
+        break;
+      default:
+        Serial.println("This key maps to none.");
     }
   }


Editable LCD contrast via Serial

Editable LCD contrast via Serial

--- Project_11/Project_11.ino
+++ Project_11/Project_11.ino
@@ -2,16 +2,21 @@

 LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
 const int switchPin = 6;
+const int contrastPin = 9;
 int switchState = 0;
 int prevSwitchState = 0;
 int reply;

 void setup() {
+  Serial.begin(9600);
   lcd.begin(16, 2);
   pinMode(switchPin, INPUT);
+  pinMode(contrastPin, OUTPUT);
+  analogWrite(contrastPin, 50);
   lcd.print("Ask the");
   lcd.setCursor(0, 1);
   lcd.print("Crystal ball!");
+  Serial.println("Type value from 0 to 255 for LCD contrast");
 }

 void loop() {
@@ -52,4 +57,12 @@
     }
   }
   prevSwitchState = switchState;
+  if (Serial.available()) {
+    int contrast = Serial.parseInt();
+    analogWrite(contrastPin, contrast);
+    Serial.print("New contrast ");
+    Serial.println(contrast);
+    Serial.println("Type value from 0 to 255 for LCD contrast");
+  }
+  delay(100);
 }


switch/case based card reading

switch/case based card reading

--- software/firmware/LogoBotDrive/LogoBotDrive.ino
+++ software/firmware/LogoBotDrive/LogoBotDrive.ino
@@ -11,9 +11,10 @@
 String cmd; // cmd received over serial - builds up char at a time
 Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);
 DMTimer checkTimer(2000000);
-String cardval;
-String oldcardval = "";
+uint32_t cardval;
+uint32_t oldcardval = 0;
 bool bot_drive = 1;
+

 void setup()
 {
@@ -40,29 +41,8 @@

     if(checkTimer.isTimeReached()) {
         Serial.println("timeout");
-        cardval = readNFC();
-        Serial.println(cardval);
-
-        Serial.println(oldcardval);
-        if(! cardval.equals(oldcardval)) {
-          oldcardval = cardval;
-          Serial.println(oldcardval);
-          Serial.println("card change");
-          // different card
-          if(cardval.equals("56721eff")) {
-            Serial.println("stop card");
-            bot_drive = 0;
-          } else if(cardval.equals("3662bbfd")) {
-            bot.turn(270);
-          }
-        } else {
-          if(bot_drive) {
-            bot.drive(10);
-          } else {
-            bot.stop();
-          }
-        }
-      }
+        checkCardAndDirectBot();
+    }

     if (!bot.isQFull()) {  // fill up the move queue to get the speed up
         //setLEDColour(0,1,0); // Green, because we are happily doing something
@@ -72,7 +52,42 @@

 }

-String readNFC() {
+void checkCardAndDirectBot() {
+  cardval = readNFC();
+  Serial.println(cardval);
+
+  if( cardval != oldcardval) {
+    oldcardval = cardval;
+    Serial.println("card change");
+    // different card
+
+    switch(cardval) {
+      case 0xFF1E7256: // "56721eff":
+      Serial.println("stop card");
+      bot_drive = 0;
+      break;
+    case 0xFDBB6236: // "3662bbfd":
+      Serial.println("turn 270 card");
+      bot.turn(270);
+      break;
+    case 0xFDC11086: // "8610c1fd":
+      Serial.println("turn 90 card");
+      bot.turn(90);
+      break;
+    default:
+      bot.drive(10);
+    }
+
+  } else {
+    if(bot_drive) {
+      bot.drive(10);
+    } else {
+      bot.stop();
+    }
+  }
+}
+
+uint32_t readNFC() {
   uint8_t success;
   uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
   uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
@@ -86,18 +101,14 @@
     // Display some basic information about the card
     //Serial.println("Found an ISO14443A card");
     //Serial.print("  UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
-    Serial.print("  UID Value: ");
-    nfc.PrintHex(uid, uidLength);
-    Serial.println("");
+    //Serial.print("  UID Value: ");
+    //nfc.PrintHex(uid, uidLength);
+    uint32_t val = *(uint32_t *)uid;
+    Serial.println(val, HEX);
+    Serial.println("");
+    return val;
   }
-  String direction = "";

-  for (int szPos=0; szPos < uidLength; szPos++) {
-      if (uid[szPos] <= 0xF)
-      direction.concat("0");
-      direction.concat(String(uid[szPos]&0xff, HEX));
-  }
-  return direction;
 }

 static void handleCollision(byte collisionData)


Update arrowprint_firmware.ino

Update arrowprint_firmware.ino

added link to aJson library

--- arrowprint_firmware/arrowprint_firmware.ino
+++ arrowprint_firmware/arrowprint_firmware.ino
@@ -5,7 +5,10 @@
  *
  * Use arduino toolkit version 1.5.2 or later
  * Make sure you use an Arduino DUE (Or Leonardo)
- * Install aJSON library
+ *
+ * Install aJSON library from https://github.com/interactive-matter/aJson
+ * to sketchbook/libraries/aJson
+ *
  */
 #include <aJSON.h>


Update arrowprint_firmware.ino

Update arrowprint_firmware.ino

--- arrowprint_firmware/arrowprint_firmware.ino
+++ arrowprint_firmware/arrowprint_firmware.ino
@@ -21,21 +21,20 @@
  *    CONFIGURATION
  *  =======================================================================================
  */
-int cmd = 0;
-//int hotheadtarget = 160;    //160 DEFAULT
-int hotheadtarget = 10;    //160 DEFAULT
-
-//physical movement scale (bigger == more);
+int cmd = 0;
+int hotheadtarget = 10;
+
+//how many stepper pulses (finer stepper motors would be more steps for same distance)
 double tablexsteps    = 1920.0 * substeps;
 double tableysteps    = 2134.0 * substeps;
-double tablezsteps    = 22400.0 * substeps;    //234000 (100mm) from top (STEPS FROM TABLE SURFACE TO TOP) 0,0,0 is FAR LEFT BOTTOM
-double tableesteps  = 72000.000 * substeps;  //-45000 safe //66666.666
-
-//measured (1000 = 1mm)
-double tablexdistance = 180;    //in microns (158mm )
-double tableydistance = 200.0625;    //in microns (200mm)
-double tablezdistance = 70.0;    //in microns (96mm)
-double tableedistance = 1000.000;    //in microns (96mm)
+double tablezsteps    = 22400.0 * substeps;
+double tableesteps  = 72000.000 * substeps;
+
+//measured table movements(1000 = 1mm)
+double tablexdistance = 180;
+double tableydistance = 200.0625;
+double tablezdistance = 70.0;
+double tableedistance = 1000.000;   //extruder scale, best to keep at 1000 and tweak tableesteps

 // Motor pins


Changed the number of targets

Changed the number of targets

--- arduino_practice_target.ino
+++ arduino_practice_target.ino
@@ -9,7 +9,7 @@

 #include "Target.h"

-const int lenTargets = 5;
+const int lenTargets = 16;
 const float visibleTime = 2000;
 const float idleTime = 250;


Created by Peter Clarke

Created by Peter Clarke

--- sketches/BasicBotBudget/BasicBotBudget.ino
+++ sketches/BasicBotBudget/BasicBotBudget.ino
@@ -1,4 +1,6 @@
-                                                /**
+/**
+ Created by Peter Clarke
+
  PIN ALLOCATION:

  13 - Motor B direction 1


Fixed a few display bugs.

Fixed a few display bugs.

--- shutter-timer/src/shutter-timer.ino
+++ shutter-timer/src/shutter-timer.ino
@@ -101,7 +101,7 @@
   Serial.print("Shutter detected: 1/");
   Serial.print(shutter);
   Serial.print("s (");
-  Serial.print(duration / 1000);
+  Serial.print(duration / 1000.0);
   Serial.print("ms)");

   Serial.print("    Avg (");
@@ -109,9 +109,10 @@
   Serial.print(") 1/");
   Serial.print(avgShutter);
   Serial.print("s (");
-  Serial.print(mean / 1000 );
+  Serial.print(mean / 1000.0 );
   Serial.print("ms) σ:");
-  Serial.println(stdDevSample / 1000);
+  Serial.print( count == 1 ? 0.0 : stdDevSample / 1000 );
+  Serial.println("ms");
 }

 void debugRawValues()


Fixed settings screen entry bug. Apologies. :facepalm:

--- arduboy-game/arduboy-game.ino
+++ arduboy-game/arduboy-game.ino
@@ -213,7 +213,7 @@

     totalDelay ++;
   }
-  playMusic(99);
+//  playMusic(99);

   return (totalDelay >= ATTRACT_MODE_TIMEOUT ? TITLE_TIMEOUT : selectedItem);
@@ -847,7 +847,7 @@
 }

 void playerWinsScreen() {
-  playMusic(99);
+//  playMusic(99);
   arduboy.clear();

   // Temp


Refactor code so bitshuffling is seperate.

--- JnGeneral/JnGeneral.ino
+++ JnGeneral/JnGeneral.ino
@@ -523,83 +523,106 @@
 //    Serial.println("");
 }

+// Takes the given measurements for a plug and buffer them for transmission
+static void bufferMeasurements(Plug &plug, const measurement_t (&measurements)[4])
+{
+    // Now add this information to the databuffer
+    byte pos = databufferpos;
+    Device *dev = getDevice(plug.device_id);
+    databuffer[pos++] = plug.id | ((dev->num_measurements-1) << 5);  // start id + number of values
+    int32_t bitbuffer = 0;
+    byte bitbuffercount = 0;
+    for(byte j=0; j<dev->num_measurements; j++) {
+        int8_t width = plug.measurements[j].width;
+        // Clamp based on width
+        int32_t low, high, mask;
+        byte width_val;
+        if(width > 0) {
+            low = 0;
+            high = (1 << width)-1;
+            mask = high;
+            width_val = width;
+        } else {
+            high = (1 << (-width-1))-1;
+            low = ~high;
+            mask = (1<<(-width))-1;
+            width_val = -width;
+        }
+        int32_t m = measurements[j];
+        if(m < low) m = low;
+        if(m > high) m = high;
+
+        // Chop
+        m &= mask;
+
+        bitbuffer <<= width_val;
+        bitbuffer |= m;
+        bitbuffercount += width_val;
+
+//        Serial.print("(");
+//        printInt(bitbuffer);
+//        Serial.print(")");
+        while(bitbuffercount >= 8) {
+            databuffer[pos++] = bitbuffer >> (bitbuffercount-8);
+            bitbuffercount -= 8;
+        }
+        bitbuffer &= ((1 << bitbuffercount)-1);  // Not really necessary
+    }
+    // Push remainder
+    if(bitbuffercount) {
+        bitbuffer <<= (8-bitbuffercount);
+        databuffer[pos++] = bitbuffer;
+    }
+
+//    Serial.print("=> ");
+//    for(byte j=databufferpos; j<pos; j++) {
+//        printInt(databuffer[j]);
+//        Serial.print(",");
+//    }
+
+    databufferpos = pos;
+}
+
+// Takes all the measurements form a single plug and, if requested, buffer for transmission
+static int measurePlug(Plug &plug, byte record)
+{
+    printInt(plug.port);
+    Serial.print(": ");
+
+    Device *dev = getDevice(plug.device_id);
+    measurement_t measurements[4];
+    serialFlush();
+    if(!measure(plug, measurements)) {
+        Serial.println("(measurement failed)");
+        return 1;
+    }
+
+    // Print measurements
+    for(byte j=0; j<dev->num_measurements; j++) {
+        printInt(measurements[j]);
+        Serial.print(", ");
+    }
+    Serial.print("\r\n");
+    serialFlush();
+
+    if(record) {
+        bufferMeasurements(plug, measurements);
+        if(scheduler.idle(TASK_REPORT))
+            scheduler.timer(TASK_REPORT, 1);
+    }
+    return 0;
+}
+
+// Measures all defined plugs
 static int doMeasure(int count)
 {
     Serial.print("Doing measurements:\r\n");
     for(byte n=0; n<count; n++) {
         for(byte i=0; i<numPlugs; i++) {
-
-            printInt(plugs[i].port);
-            Serial.print(": ");
-
-            Device *dev = getDevice(plugs[i].device_id);
-            measurement_t measurements[4];
-            serialFlush();
-            if(!measure(plugs[i], measurements)) {
-                Serial.println("(measurement failed)");
-                continue;
-            }
-            // Now add this information to the databuffer
-            byte pos = databufferpos;
-            databuffer[pos++] = plugs[i].id | ((dev->num_measurements-1) << 5);  // start id + number of values
-            int32_t bitbuffer = 0;
-            byte bitbuffercount = 0;
-            for(byte j=0; j<dev->num_measurements; j++) {
-                printInt(measurements[j]);
-                Serial.print(", ");
-
-                int8_t width = plugs[i].measurements[j].width;
-                // Clamp based on width
-                int32_t low, high, mask;
-                byte width_val;
-                if(width > 0) {
-                    low = 0;
-                    high = (1 << width)-1;
-                    mask = high;
-                    width_val = width;
-                } else {
-                    high = (1 << (-width-1))-1;
-                    low = ~high;
-                    mask = (1<<(-width))-1;
-                    width_val = -width;
-                }
-                int32_t m = measurements[j];
-                if(m < low) m = low;
-                if(m > high) m = high;
-
-                // Chop
-                m &= mask;
-
-                bitbuffer <<= width_val;
-                bitbuffer |= m;
-                bitbuffercount += width_val;
-
-//                Serial.print("(");
-//                printInt(bitbuffer);
-//                Serial.print(")");
-                while(bitbuffercount >= 8) {
-                    databuffer[pos++] = bitbuffer >> (bitbuffercount-8);
-                    bitbuffercount -= 8;
-                }
-            }
-            // Push remainder
-            if(bitbuffercount) {
-                bitbuffer <<= (8-bitbuffercount);
-                databuffer[pos++] = bitbuffer;
-            }
-
-//            Serial.print("=> ");
-//            for(byte j=databufferpos; j<pos; j++) {
-//                printInt(databuffer[j]);
-//                Serial.print(",");
-//            }
-            Serial.print("\r\n");
-            serialFlush();
-
-            databufferpos = pos;
-        }
-
-        Sleepy::loseSomeTime(1000);
+            measurePlug(plugs[i], n == 0);
+        }
+        if( (n+1) < count )
+            Sleepy::loseSomeTime(1000);
     }
 }


Update RetroWatchArduino_spi.ino

Update RetroWatchArduino_spi.ino

changed line 34 and 46 from SSD1306 to SSD1331

--- RetroWatch_Arduino/RetroWatchArduino_spi/RetroWatchArduino_spi.ino
+++ RetroWatch_Arduino/RetroWatchArduino_spi/RetroWatchArduino_spi.ino
@@ -31,7 +31,7 @@
 #include <Wire.h>
 #include <SoftwareSerial.h>
 #include <Adafruit_GFX.h>
-#include <Adafruit_SSD1306.h>
+#include <Adafruit_SSD1331.h>
 #include <math.h>
 #include "bitmap.h"

@@ -43,7 +43,7 @@
 #define OLED_DC    8     // DC
 #define OLED_CS    10    // CS
 #define OLED_RESET 9     // RES
-Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
+Adafruit_SSD1331 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

 #if (SSD1306_LCDHEIGHT != 64)
 #error("Height incorrect, please fix Adafruit_SSD1306.h!");


Update Timer_Interrupt_Notes.ino

Update Timer_Interrupt_Notes.ino

--- PulseSensorAmped_Arduino_1dot4/Timer_Interrupt_Notes.ino
+++ PulseSensorAmped_Arduino_1dot4/Timer_Interrupt_Notes.ino
@@ -184,7 +184,7 @@
   You will need to change the name of the funcion in the Interrupts tab from
   'ISR(TIMER2_COMPA_vect)'
   to
-  'getPulse()'
+  'void getPulse()'
   and also comment out the entire interruptSetup() function in the interrupts tab in order for this to work.

   Happy Hacking!


COH-78: WIP

COH-78: WIP

--- Arduino/COHEAT2015/20160316-COHEAT-M1/COHEAT-M1/COHEAT-M1.ino
+++ Arduino/COHEAT2015/20160316-COHEAT-M1/COHEAT-M1/COHEAT-M1.ino
@@ -878,7 +878,7 @@
   // TODO: filter for only this unit address/housecode as FHT8V.getHC{1,2}() are thread-safe.
 #else
   // Expect secure frame with 2-byte ID and empty body.
-  if((buflen < 29) || ((0x80|OTRadioLink::FTp2_CC1PollAndCmd) != buf[0])) { return(false); }
+  if((buflen < 28) || ((0x80|OTRadioLink::FTp2_CC1PollAndCmd) != buf[0])) { return(false); }
   // TODO: filter for only this unit address/housecode as FHT8V.getHC{1,2}() are thread-safe.
 #endif // ENABLE_OTSECUREFRAME_ENCODING_SUPPORT
   return(true); // Accept message.
@@ -894,7 +894,7 @@
   // TODO: filter for only associated relay address/housecodes.
 #else
   // Expect secure frame with 2-byte ID and 32-byte encrypted body.
-  if(buflen < 63) { return(false); }
+  if(buflen < 60) { return(false); }
   const uint8_t t = buf[0];
   if(((0x80|OTRadioLink::FTp2_CC1Alert) != t) && ((0x80|OTRadioLink::FTp2_CC1PollResponse) != t)) { return(false); }
   // TODO: filter for only associated relay address/housecodes.


Delete Cing.ino

Delete Cing.ino

--- Cing.ino
+++ Cing.ino
@@ -1,17 +0,0 @@
-#include "Attiny85_IO_basic.h"
-Attiny attiny;
-void setup() {
-
-
-}
-
-void loop()
-{
-if (attiny.UltrasonicSensor()<20){attiny.motor("AB", 0,"digital");}
-else{attiny.motor("AB", 1,"digital");}
-//if (attiny.LightSensor(2,"digital")==0){attiny.motor("B", 1,"digital");}
-//else{attiny.motor("B", 0,"digital");}
-}
-
-
-


add long-push short-push recognition, flashing LED based on mode change

--- app/inTheDuck/LoverDuck.ino
+++ app/inTheDuck/LoverDuck.ino
@@ -1,5 +1,5 @@
 #include <Adafruit_NeoPixel.h>
-//test
+
 #include <Adafruit_Sensor.h>
 #include <Adafruit_LSM303.h>
 #include <Wire.h>
@@ -31,6 +31,8 @@
 int lastButtonState=HIGH;
 unsigned long lastDebounceTime=0;
 unsigned long debounceDelay=50;
+unsigned long lastButtonTime=0;
+unsigned long longPush=1000;  // how long to push to be registered as a long push

 unsigned long startCurrentMode=0;

@@ -84,11 +86,40 @@
       if(reading != buttonState){
         buttonState=reading;
         if(buttonState==LOW){
-          if(mode != 0){
-            changeMode(0);
+          // if(mode != 0){
+          //   changeMode(0);
+          // }
+          // else{
+          //   changeMode(1);
+          // }
+          lastButtonTime=millis();
+        }
+        else{
+          // every process is done when the button is released
+          if(millis()-lastButtonTime>longPush){
+            // register a long press
+            if(mode==0){
+              changeMode(1);
+            }
+            else{
+              changeMode(0);
+            }
           }
           else{
-            changeMode(1);
+            // register a short press
+            switch (mode) {
+              case 1:
+                changeMode(4);
+                break;
+              case 4:
+                changeMode(5);
+                break;
+              case 5:
+                changeMode(1);
+                break;
+              default:
+                break;
+            }
           }
         }
       }
@@ -164,15 +195,6 @@
   return value;
 }

-//void warning(){
-//  for(int i=0; i<4; i++){
-//    tone(tonePin, 900);
-//    delay(500);
-//    tone(tonePin, 700);
-//    delay(250);
-//  }
-//  noTone(tonePin);
-//}

 int LEDangles[]={355, 5, 67, 77, 139, 149, 211, 221, 283, 293};
 void setLED(int i, int c[]){
@@ -190,9 +212,41 @@
     pixelsB.show();
   }
 }
+
+// return how long the first blinking sequence lasts
+unsigned long waitDuration(int myMode){
+  unsigned long value=600;
+  switch(myMode){
+    case 1:
+      value=value;
+      break;
+    case 4:
+      value=2*value;
+      break;
+    case 5:
+      value=3*value;
+      break;
+    default:
+      value=0;
+  }
+  return value;
+}
 void setColors(){
-  switch(mode){
-    case 1:{
+  if(mode==1 || mode ==4 || mode ==5){
+    if((millis()-startCurrentMode)<waitDuration(mode)){
+      // blink if the current mode just started
+      if((millis()-startCurrentMode)%600 < 300){
+        color[0]=200;
+        color[1]=200;
+        color[2]=200;
+      }
+      else{
+        color[0]=0;
+        color[1]=0;
+        color[2]=0;
+      }
+    }
+    else{
       float ratio= 0.7+ 0.3 * sin(((millis()/10)%360)*3.14/180);
       int tmp[3];
       for(int i=0; i<3; i++){
@@ -201,47 +255,44 @@
           a=-abs(a);
         }
         color[i]=(a/mode1Duration+startColor[i])%256;
-//        color[i]=startColor[i];
+  //        color[i]=startColor[i];
         color[i]=(int)(color[i]*ratio);
       }
-
       if(millis()-startCurrentMode>mode1Duration){
         changeMode(3);
       }
-      break;}
-    case 2:
-      if((millis()-startCurrentMode)%1000<600){
-        color[0]=200;
-        color[1]=200;
-        color[2]=200;
-      }
-      else{
-        color[0]=0;
-        color[1]=0;
-        color[2]=0;
-      }
-      //possible drowning
-      break;
-    case 3:
-      //10 minutes have passed
-      if((millis()-startCurrentMode)%2000<1000){
-        color[0]=0;
-        color[1]=200;
-        color[2]=0;
-      }
-      else{
-        color[0]=0;
-        color[1]=0;
-        color[2]=0;
-      }
-      break;
-    case 0:
-        color[0]=0;
-        color[1]=0;
-        color[2]=0;
-        break;
-    default:
-      break;
+    }
+  }
+  else if(mode==2){
+    if((millis()-startCurrentMode)%1000<600){
+      color[0]=200;
+      color[1]=200;
+      color[2]=200;
+    }
+    else{
+      color[0]=0;
+      color[1]=0;
+      color[2]=0;
+    }
+    //possible drowning
+  }
+  else if(mode==3){
+    //10 minutes have passed
+    if((millis()-startCurrentMode)%2000<1000){
+      color[0]=0;
+      color[1]=200;
+      color[2]=0;
+    }
+    else{
+      color[0]=0;
+      color[1]=0;
+      color[2]=0;
+    }
+  }
+  else{
+    color[0]=0;
+    color[1]=0;
+    color[2]=0;
   }
   for(int i=0; i<10; i++){
     setLED(i, color);
@@ -260,6 +311,12 @@
     case 3:
       //warning mode- 10minutes have passed
       break;
+    case 4:
+      //radio mode- still is counting 10 minutes
+      break;
+    case 5:
+      //math mode
+      break;
     default:
       break;
   }
@@ -269,21 +326,22 @@

 //phi is angle of LED
 //theta is edge of current LED lgihting state
-float getRatio(float phi, float theta){
-  float width=100;
-  if(theta-width<0){
-    if(theta<phi || 360+theta-width < phi){
-      return 0.0;
-    }
-    else if(phi<=theta){
-      return (phi-theta+width)/width;
-    }
-    else{
-      return (phi-360.0-theta+width)/width;
-    }
-  }
-  else{
-    return (phi-theta+width)/width;
-  }
-  return 0.0;
-}
+// I wrote this because I was gonna make the lit-up segment rotate, but eh, so much for that.
+// float getRatio(float phi, float theta){
+//   float width=100;
+//   if(theta-width<0){
+//     if(theta<phi || 360+theta-width < phi){
+//       return 0.0;
+//     }
+//     else if(phi<=theta){
+//       return (phi-theta+width)/width;
+//     }
+//     else{
+//       return (phi-360.0-theta+width)/width;
+//     }
+//   }
+//   else{
+//     return (phi-theta+width)/width;
+//   }
+//   return 0.0;
+// }


Wokring first try, but still has some problems with reseting the connection after the second or third reconnect - now we'll try a different route!

--- Stroller_interruptHandling_1/Stroller_interruptHandling_1.ino
+++ Stroller_interruptHandling_1/Stroller_interruptHandling_1.ino
@@ -233,12 +233,14 @@
         }

     }
-    if ( runningMillis>60000) {
+    if ( runningMillis>20000) {
        // in the next iteration, stop this maddness and go back to sleep
        beginBLETime=0;
        countTimesSend=0;

     }
+     attachInterrupt(0, countRPM, FALLING);
+
     ble_do_events();

     } else {


mention minimum schedule times for deep sleep in example

--- examples/ShowSleep/ShowSleep.ino
+++ examples/ShowSleep/ShowSleep.ino
@@ -1,5 +1,8 @@
 /*
-   Show when the CPU is sleep mode (LED off) and active (LED on).
+   Shows when the CPU is in sleep mode (LED off) and active (LED on).
+   Please not that the CPU is not put to deep sleep for schedule times
+   shorter than 1 second. For these, it uses SLEEP_MODE_IDLE.
+
    You will notice, that it's not on in full brightness because
    the CPU is sleeping shortly almost all the time when it is set
    to SLEEP_MODE_IDLE. In that case, it wakes up on every timer tick


Delete Pathfinding_arduino.ino

Delete Pathfinding_arduino.ino

--- Pathfinding_arduino.ino
+++ Pathfinding_arduino.ino
@@ -1,215 +0,0 @@
-#include <StandardCplusplus.h>
-#include <system_configuration.h>
-#include <unwind-cxx.h>
-#include <utility.h>
-
-#include <vector>
-//#include <Math.h>
-#include <iostream>
-using namespace std;
-
-
-
-void setup() {
-  // put your setup code here, to run once:
-   Serial.begin(57600);
-   gridInit();
-  FindPath(0,0,10,10);
-
-}
-
-void loop() {
-  // put your main code here, to run repeatedly:
-
-//    gridInit();
-//  FindPath(0,0,10,10);
- // cout << "[""]" << "\n";
-
-}
-
-
-
-
-
-
-
-struct node
-  {
-    int posx;
-    int posy;
-    int gcost;
-    int hcost;
-    bool walkable;
-
-    struct node* parent;
-  };
-
-struct node grid[20][20];
-int gridsizex = 20;
-
-int gridsizey = 20;
-void gridInit(){
-  for (int i = 0; i < gridsizex; i++)
-  {
-    for (int j = 0; j < gridsizey; j++)
-    {
-      grid[i][j].posx = i;
-      grid[i][j].posy = j;
-      grid[i][j].walkable = true;
-    }
-  }
-  grid[0][10].walkable = false;
-  grid[0][9].walkable = false;
-  grid[1][10].walkable = false;
-  grid[2][9].walkable = false;
-
-
-}
-
-//using structures to represent nodes for open and closed lists
-vector<struct node *> open; // nodes that need to be evaluated
-vector<struct node *> closed; //already been evaluated
-
-vector<struct node *> neighbours;
-
-
-int abs(int i) {
-  return i >= 0 ? i : -i;
-}
-
-struct node * get_node(int x, int y){
-
-  return &grid[x][y];
-
-}
-
-//calculate fcost
-int fcost(struct node *a)
-{
-  return a->gcost + a->hcost;
-}
-
-int getDistance(struct node *a, struct node *b){
-  int dstX = abs(a->posx - b->posx);
-  int dstY = abs(a->posy - b->posy);
-
-  return dstX + dstY;
-}
-
-bool inClosed(struct node *current)
-{
-  for(int i = 0; i< closed.size(); i++){
-    if (current == closed[i])
-      return true;
-  }
-  return false;
-}
-
-bool inOpen(struct node *current)
-{
-  for(int i = 0; i< open.size(); i++){
-    if (current == open[i])
-      return true;
-  }
-  return false;
-
-}
-
-
-
-void printnode(struct node* node){ // print this bitch
- Serial.print( node->posx);
-  Serial.print(" ");
-  Serial.println(node->posy);
-}
-
-void RetracePath(struct node *startNode, struct node *endNode){
- // cout << "[retrace]" << "\n";
-  vector<struct node *> path;
-  struct node *currentNode = endNode;
-
-  // TODO WTF DO WE IF THERES NO PATH BRAH
-  while(currentNode != startNode){
-    path.push_back(currentNode);
-    currentNode = currentNode->parent;
-  Serial.print("[");
-   Serial.print(currentNode->posx);
-    Serial.print(", ");
-     Serial.print(currentNode->posy);
-      Serial.println("]");
-
-    if (!currentNode) {
-      // THERE'S NO PATH THO.
-      break;
-
-
-    }
-  }
-}
-void GetNeighbours(struct node *current){
-  neighbours.clear();
-
-  for(int x = -1; x<=1;x++){
-    for (int y = -1; y <= 1; y++){
-      if(abs(x)==abs(y))
-        continue;
-
-      int checkX = current->posx + x;
-      int checkY = current->posy + y;
-
-      if(checkX >= 0 && checkX < gridsizex && checkY >= 0 && checkY<gridsizey){
-        neighbours.push_back(&grid[checkX][checkY]);
-      }
-    }
-  }
-  return;
-}
-void FindPath (int start_x, int start_y, int target_x, int target_y){
-  struct node *startNode = get_node(start_x,start_y);
-  struct node *targetNode = get_node(target_x,target_y);
-  //cout << "[1]" << "\n";
-  open.push_back(startNode);
-  //cout << open[0]->posy << "\n";
-
-  while(open.size() > 0 ){
-    //cout << "[2]" << "\n";
-    struct node *currentNode = open[0];
-    int index = 0;
-
-    for (int i =1; i<open.size(); i++){
-      if(fcost(open[i]) < fcost(currentNode) || fcost(open[i]) == fcost(currentNode) && open[i]->hcost < currentNode->hcost){
-        currentNode = open[i];
-        index = i;
-
-      }
-
-    }
-    open.erase(open.begin() + index);
-    closed.push_back(currentNode);
-    printnode(currentNode);
-    if(currentNode == targetNode){
-      RetracePath(startNode, targetNode);
-      return;
-    }
-
-    GetNeighbours(currentNode);
-    for(int i = 0; i< neighbours.size(); i++){
-      if (!neighbours[i]->walkable || inClosed(neighbours[i])){
-        continue;
-      }
-      int newMovementCostToNeighbour = currentNode->gcost + getDistance(currentNode,neighbours[i]);
-      if(newMovementCostToNeighbour < neighbours[i]->gcost || !inOpen(neighbours[i])){
-        neighbours[i]->gcost = newMovementCostToNeighbour;
-        neighbours[i]->hcost = getDistance(neighbours[i], targetNode);
-        neighbours[i]->parent = currentNode;
-
-        if(!inOpen(neighbours[i]))
-          open.push_back(neighbours[i]);
-      }
-
-    }
-  }
-}
-
-
-


Improved tag handling (#8)

Improved tag handling (#8)

* #7 Stop playback when card is removed. Todo: Playback started via web

* #7 revert something stupid

* #7 make web triggered playback work again

--- RfidShelf/RfidShelf.ino
+++ RfidShelf/RfidShelf.ino
@@ -43,11 +43,14 @@
 // Init array that will store new card uid
 byte lastCardUid[4];
 bool playing = false;
+bool playingByCard = true;
 bool pairing = false;
 String currentFile = "";

 SdFat SD;
 SdFile uploadFile;
+
+unsigned long lastRfidCheck;

 void setup() {
   // Seems to make flashing more reliable
@@ -80,15 +83,18 @@
     key.keyByte[i] = 0xFF;
   }

-  Serial.print(F("Using rfid key (for A and B):"));
+  Serial.print(F("Using rfid key (for A and B): "));
   print_byte_array(key.keyByte, MFRC522::MF_KEY_SIZE);
   Serial.println();

   //Initialize the SdCard.
-  if (!SD.begin(SD_CS)) SD.initErrorHalt();
+  if (!SD.begin(SD_CS)) {
+    Serial.println(F("Could not initialize SD card"));
+    SD.initErrorHalt();
+  }

   // initialise the music player
-  if (! musicPlayer.begin()) { // initialise the music player
+  if (!musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1) delay(500);
   }
@@ -149,28 +155,42 @@
     playMp3();
   }

-  handleRfid();
+  if (!playing || (millis() - lastRfidCheck > 500)) {
+    handleRfid();
+    lastRfidCheck = millis();
+  }
+
   server.handleClient();
 }

 void handleRfid() {
-  // Look for new cards
-  if ( ! mfrc522.PICC_IsNewCardPresent()) {
-    return;
-  }
-
-  // Select one of the cards
-  if ( ! mfrc522.PICC_ReadCardSerial()) {
-    return;
-  }
-
-  if (!pairing && (
-        mfrc522.uid.uidByte[0] == lastCardUid[0] &&
-        mfrc522.uid.uidByte[1] == lastCardUid[1] &&
-        mfrc522.uid.uidByte[2] == lastCardUid[2] &&
-        mfrc522.uid.uidByte[3] == lastCardUid[3] )) {
-    mfrc522.PICC_HaltA();
-    Serial.println(F("Card already read"));
+
+  // While playing check if the tag is still present
+  if (playing && playingByCard) {
+
+    // Since wireless communication is voodoo we'll give it a few retrys before killing the music
+    for (int i = 0; i < 3; i++) {
+      // Detect Tag without looking for collisions
+      byte bufferATQA[2];
+      byte bufferSize = sizeof(bufferATQA);
+
+      MFRC522::StatusCode result = mfrc522.PICC_WakeupA(bufferATQA, &bufferSize);
+
+      if (result == mfrc522.STATUS_OK && mfrc522.PICC_ReadCardSerial() && (
+            mfrc522.uid.uidByte[0] == lastCardUid[0] &&
+            mfrc522.uid.uidByte[1] == lastCardUid[1] &&
+            mfrc522.uid.uidByte[2] == lastCardUid[2] &&
+            mfrc522.uid.uidByte[3] == lastCardUid[3] )) {
+        mfrc522.PICC_HaltA();
+        return;
+      }
+    }
+
+    stopMp3();
+  }
+
+  // Look for new cards and select one if it exists
+  if (!mfrc522.PICC_IsNewCardPresent() ||  !mfrc522.PICC_ReadCardSerial()) {
     return;
   }

@@ -183,7 +203,7 @@
   Serial.println(mfrc522.PICC_GetTypeName(piccType));

   // Check for compatibility
-  if ( piccType != MFRC522::PICC_TYPE_MIFARE_1K ) {
+  if (piccType != MFRC522::PICC_TYPE_MIFARE_1K ) {
     Serial.println(F("Unsupported card."));
     return;
   }
@@ -198,35 +218,28 @@
     pairing = false;
   }

+  // Reset watchdog timer
+  yield();
   byte readBuffer[18];
   if (readRfidBlock(1, 0, readBuffer, sizeof(readBuffer))) {

     char readFolder[18];
     readFolder[0] = '/';
     // allthough sizeof(readBuffer) == 18, we only get 16 byte of data
-    for (byte i = 0; i < 16; i++) {
-      readFolder[i + 1] = readBuffer[i];
-    }
+    memcpy(readFolder + 1 , readBuffer, 16 * sizeof(byte) );
     // readBuffer will already contain \0 if the folder name is < 16 chars, but otherwise we need to add it
     readFolder[17] = '\0';

-    // Store NUID into nuidPICC array
-    for (byte i = 0; i < 4; i++) {
-      lastCardUid[i] = mfrc522.uid.uidByte[i];
-    }
-
+    // Store uid
+    memcpy(lastCardUid, mfrc522.uid.uidByte, 4 * sizeof(byte) );
+
+    if (playing) {
+      stopMp3();
+    }

-
-    if(readFolder[1] == '\0') {
-      Serial.println(F("Stopping playback"));
-      stopMp3();
-      yield();
-    } else {
-      if (switchFolder(readFolder)) {
-        stopMp3();
-        yield();
-        playMp3();
-      }
+    if (readFolder[1] != '\0' && switchFolder(readFolder)) {
+      playMp3();
+      playingByCard = true;
     }
   }

@@ -239,12 +252,10 @@

 bool writeRfidBlock(uint8_t sector, uint8_t relativeBlock, const char *newContent, uint8_t contentSize) {
   uint8_t absoluteBlock = (sector * 4) + relativeBlock;
-  MFRC522::StatusCode status;
-

   // Authenticate using key A
   Serial.println(F("Authenticating using key A..."));
-  status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, absoluteBlock, &key, &(mfrc522.uid));
+  MFRC522::StatusCode status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, absoluteBlock, &key, &(mfrc522.uid));
   if (status != MFRC522::STATUS_OK) {
     Serial.print(F("PCD_Authenticate() failed: "));
     Serial.println(mfrc522.GetStatusCodeName(status));
@@ -256,13 +267,11 @@
   if (contentSize < bufferSize) {
     bufferSize = contentSize;
   }
-  for (byte i = 0; i < bufferSize; i++) {
-    buffer[i] = newContent[i];
-  }
+  memcpy(buffer, newContent, bufferSize * sizeof(byte) );

   // Write block
   Serial.print(F("Writing data to block: ")); Serial.println(newContent);
-  status = (MFRC522::StatusCode) mfrc522.MIFARE_Write(absoluteBlock, buffer, 16);
+  status = mfrc522.MIFARE_Write(absoluteBlock, buffer, 16);
   if (status != MFRC522::STATUS_OK) {
     Serial.print(F("MIFARE_Write() failed: "));
     Serial.println(mfrc522.GetStatusCodeName(status));
@@ -280,14 +289,11 @@
     return false;
   }

-  // Block 4 is trailer block
-  //uint8_t trailerBlock   = (sector * 4) + 3;
   uint8_t absoluteBlock = (sector * 4) + relativeBlock;
-  MFRC522::StatusCode status;

   // Authenticate using key A
   Serial.println(F("Authenticating using key A..."));
-  status = (MFRC522::StatusCode) mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, absoluteBlock, &key, &(mfrc522.uid));
+  MFRC522::StatusCode status = (MFRC522::StatusCode) mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, absoluteBlock, &key, &(mfrc522.uid));
   if (status != MFRC522::STATUS_OK) {
     Serial.print(F("PCD_Authenticate() failed: "));
     Serial.println(mfrc522.GetStatusCodeName(status));
@@ -296,7 +302,7 @@

   Serial.print(F("Reading block "));
   Serial.println(absoluteBlock);
-  status = (MFRC522::StatusCode) mfrc522.MIFARE_Read(absoluteBlock, outputBuffer, &bufferSize);
+  status = mfrc522.MIFARE_Read(absoluteBlock, outputBuffer, &bufferSize);
   if (status != MFRC522::STATUS_OK) {
     Serial.print(F("MIFARE_Read() failed: "));
     Serial.println(mfrc522.GetStatusCodeName(status));
@@ -333,6 +339,7 @@
 }

 void stopMp3() {
+  Serial.println(F("Stopping playback"));
   playing = false;
   if (AMP_POWER > 0) {
     digitalWrite(AMP_POWER, LOW);
@@ -341,6 +348,8 @@
 }

 void playMp3() {
+  // IO takes time, reset watchdog timer so it does not kill us
+  yield();
   SdFile file;
   SD.vwd()->rewind();

@@ -589,8 +598,7 @@
     return;
   } else if (server.method() == HTTP_POST) {
     if (server.hasArg("newFolder")) {
-      Serial.print(F("Creating folder"));
-      Serial.print(F(" "));
+      Serial.print(F("Creating folder "));
       Serial.println(server.arg("newFolder"));
       stopMp3();
       yield();
@@ -626,10 +634,10 @@
         handleWriteRfid(path);
         returnOK();
         return;
-      } else if(server.hasArg("play") && switchFolder((char *)path.c_str())) {
+      } else if (server.hasArg("play") && switchFolder((char *)path.c_str())) {
         stopMp3();
-        yield();
         playMp3();
+        playingByCard = false;
         returnOK();
         return;
       }


Don't use a lookup table with 256 slots, that's overkill. Hashmaps would also be overkill spacewise too. Instead, use a switch/case statement for each of the context pairs since we're working with a limited number of contexts for demonstration.

--- RoverMain/RoverMain.ino
+++ RoverMain/RoverMain.ino
@@ -39,7 +39,7 @@

 //int lookups[256];
 //lookups[0b00101010] = 0b0011110111001001;
-int lookups[256]; //we should probably burn this into prog memory
+//int lookups[256]; //we should probably burn this into prog memory

 // The read and write handlers for using the EEPROM Library
 void writer(unsigned long address, byte data)
@@ -64,10 +64,26 @@
 	//eps indicates how often we should randomly select

 	byte epsilon = (byte)random(100);
+	int ctxinfo = 0;
+
+	switch(ctxpair) {
+		case (SAD << 4) | HAPPY:
+			ctxinfo = (B00000011) << 8 | B10001100;
+			break;
+		case (FEARFUL << 4) | CALM:
+			ctxinfo = (B01000010) << 8 | B10011101;
+			break;
+		case (DISTRACTED << 4) | FOCUSED:
+			ctxinfo = (B00010110) << 8 | B10101110;
+			break;
+		case (MAD << 4) | CALM:
+			ctxinfo = (B01010111) << 8 | B10111111;
+			break;
+	}

 	if (epsilon < eps) {
 		ActionScore as;
-		db.readRec(lookups[ctxpair] & (15 << (random(4) * 4)), EDB_REC as)
+		db.readRec(ctxinfo & (15 << (random(4) * 4)), EDB_REC as)
 		return as;
 	}
 	else {
@@ -78,10 +94,10 @@

 		ActionScore maxScore;

-		db.readRec(records[ctxpair] & ACTION0_MASK, EDB_REC actionScore1 );
-		db.readRec(records[ctxpair] & ACTION1_MASK, EDB_REC actionScore2 );
-		db.readRec(records[ctxpair] & ACTION2_MASK, EDB_REC actionScore3 );
-		db.readRec(records[ctxpair] & ACTION3_MASK, EDB_REC actionScore4 );
+		db.readRec(ctxinfo & ACTION0_MASK, EDB_REC actionScore1 );
+		db.readRec(ctxinfo & ACTION1_MASK, EDB_REC actionScore2 );
+		db.readRec(ctxinfo & ACTION2_MASK, EDB_REC actionScore3 );
+		db.readRec(ctxinfo & ACTION3_MASK, EDB_REC actionScore4 );

 		maxScore = actionScore1;
 		if(maxScore > actionScore2.score) {