LED control mode added

LED control mode added

--- Master.ino
+++ Master.ino
@@ -1,4 +1,4 @@
- // Yigit Suoglu, Musab Cevik, Onur Calik, Baran Dereli, Ozgun Sensoy Aug 1, 2016
+// Yigit Suoglu, Musab Cevik, Onur Calik, Baran Dereli, Ozgun Sensoy Aug 1, 2016
 // All codes combined

 #include <colorBit_Struct.h>
@@ -24,6 +24,7 @@
 #define redONtime 20 //(ms)
 #define redOFFtime 20 //(ms)
 #define trnsDELAY 0 //(ms)
+#define ledContol "MODE_ledC" //open led control modes

 void flashDotOrDash(int color, bool dotOrDash);
 void synchronization();
@@ -34,11 +35,11 @@

 String inputHOLD; //string to hold inputs
 bool buff[12]; //buffer to store recived and to be send packets
-char ch; //store recived char and char to send
+char ch; //store recived char and char to send
 colorBit th_Val[8]; //strore all possible combs
 uint16_t r, g, b, c; //to store env data

-void setup()
+void setup()
 {
   th_Val[0].bits[0] = 0; //values for environment
   th_Val[0].bits[1] = 0;
@@ -60,7 +61,7 @@
   th_Val[5].bits[2] = 1;
   th_Val[6].bits[0] = 0; //values for GB
   th_Val[6].bits[1] = 1;
-  th_Val[6].bits[2] = 1;
+  th_Val[6].bits[2] = 1;
   th_Val[7].bits[0] = 1; //values for RGB
   th_Val[7].bits[1] = 1;
   th_Val[7].bits[2] = 1;
@@ -73,17 +74,17 @@
   digitalWrite(blueLED, LOW);
   digitalWrite(redLED, LOW);
   Serial.begin(250000); //start serial at the highest rate
-
+
   if (tcs.begin())  //start sensor
-    {
-      Serial.println("Found sensor");
-    }
-  else
-    {
-     Serial.println("Cannot find sensor"); //if fail stuck here
-        while (1);
-    }
-
+  {
+    Serial.println("Found sensor");
+  }
+  else
+  {
+    Serial.println("Cannot find sensor"); //if fail stuck here
+    while (1);
+  }
+
   Serial.print("Getting enviroment values"); //get env
   tcs.getRawData(&r, &g, &b, &c); //store environment values
   th_Val[0].r_t = ((float) r * thErrOFF);
@@ -93,20 +94,20 @@
   Serial.print(sync);
   Serial.println(" to send threshold sequence");
   uint16_t r_h, g_h, b_h;
-  setupMain: //come back here untill sync seq start
+setupMain: //come back here untill sync seq start
   if (Serial.available() > 0) //if there is an input data
   {
     inputHOLD = Serial.readString(); //get input

-    if(inputHOLD == sync) //check for sync code
-      {
-        synchronization(); //if true sync
-        goto setupMain; //then go back
-       }
+    if (inputHOLD == sync) //check for sync code
+    {
+      synchronization(); //if true sync
+      goto setupMain; //then go back
+    }
   }
   tcs.getRawData(&r, &g, &b, &c); //get env info
   //R00
-  if(r < th_Val[0].r_t) //go back if red is lower then OFF threshold
+  if (r < th_Val[0].r_t) //go back if red is lower then OFF threshold
   {
     goto setupMain;
   }
@@ -115,10 +116,10 @@
   Serial.print(".");
   //set threshold for red HIGH
   r_h = g_h = b_h = 0;
-  while(true)
+  while (true)
   {
     tcs.getRawData(&r, &g, &b, &c); //get env info
-    if(r > r_h)
+    if (r > r_h)
     {
       r_h = r;
       g_h = g;
@@ -126,30 +127,30 @@
     }
     else
     {
-      th_Val[1].r_t = ((float) r_h * thErrON);
+      th_Val[1].r_t = ((float) r_h * thErrON);
       th_Val[1].g_t = ((float) g_h * thErrOFF);
       th_Val[1].b_t = ((float) b_h * thErrOFF);
       break;
     }
   }
-
-  while(r > th_Val[0].r_t) //wait until red is LOW
+
+  while (r > th_Val[0].r_t) //wait until red is LOW
   {
     tcs.getRawData(&r, &g, &b, &c); //get env info
   }
   Serial.print(".");
-    //0G0
-   while(g < th_Val[0].g_t)
+  //0G0
+  while (g < th_Val[0].g_t)
   {
     tcs.getRawData(&r, &g, &b, &c); //wait until green is HIGH
-  }
+  }
   delay(setupWaitTime);
   //set threshold for green high
-    r_h = g_h = b_h = 0;
-  while(true)
+  r_h = g_h = b_h = 0;
+  while (true)
   {
     tcs.getRawData(&r, &g, &b, &c); //get env info
-    if(g > g_h)
+    if (g > g_h)
     {
       r_h = r;
       g_h = g;
@@ -157,29 +158,29 @@
     }
     else
     {
-      th_Val[2].r_t = ((float) r_h * thErrOFF);
+      th_Val[2].r_t = ((float) r_h * thErrOFF);
       th_Val[2].g_t = ((float) g_h * thErrON);
       th_Val[2].b_t = ((float) b_h * thErrOFF);
       break;
     }
   }
-  while(g > th_Val[0].g_t) //wait until green is LOW
-  {
-    tcs.getRawData(&r, &g, &b, &c);
+  while (g > th_Val[0].g_t) //wait until green is LOW
+  {
+    tcs.getRawData(&r, &g, &b, &c);
   }
   Serial.print(".");
   //00B
-   while(b < th_Val[0].b_t)
+  while (b < th_Val[0].b_t)
   {
     tcs.getRawData(&r, &g, &b, &c); //wait until blue is HIGH
   }
-  delay(setupWaitTime);
+  delay(setupWaitTime);
   //set threshold for blue high
   r_h = g_h = b_h = 0;
-  while(true)
+  while (true)
   {
     tcs.getRawData(&r, &g, &b, &c); //get env info
-    if(b > b_h)
+    if (b > b_h)
     {
       r_h = r;
       g_h = g;
@@ -187,177 +188,177 @@
     }
     else
     {
-      th_Val[3].r_t = ((float) r_h * thErrOFF);
+      th_Val[3].r_t = ((float) r_h * thErrOFF);
       th_Val[3].g_t = ((float) g_h * thErrOFF);
       th_Val[3].b_t = ((float) b_h * thErrON);
       break;
     }
   }
-  while(b > th_Val[0].b_t)
+  while (b > th_Val[0].b_t)
   {
     tcs.getRawData(&r, &g, &b, &c); //wait until blue is LOW
   }
   Serial.print(".");
   //RG0
-  while((r < th_Val[0].r_t) | (g < th_Val[0].g_t)) //wait until red and green is HIGH
-  {
-    tcs.getRawData(&r, &g, &b, &c);
-  }
-  delay(setupWaitTime);
+  while ((r < th_Val[0].r_t) | (g < th_Val[0].g_t)) //wait until red and green is HIGH
+  {
+    tcs.getRawData(&r, &g, &b, &c);
+  }
+  delay(setupWaitTime);
   //set threshold for red-green high
-   r_h = g_h = b_h = 0;
-  while(true)
+  r_h = g_h = b_h = 0;
+  while (true)
   {
     tcs.getRawData(&r, &g, &b, &c); //get env info
-    if(r > r_h)
+    if (r > r_h)
     {
       r_h = r;
-      if(b_h < b)
+      if (b_h < b)
       {
         b_h = b;
       }
     }
-    else if(g > g_h)
+    else if (g > g_h)
     {
       g_h = g;
-      if(b_h < b)
+      if (b_h < b)
       {
         b_h = b;
       }
     }
     else
     {
-      th_Val[4].r_t = ((float) r_h * thErrON);
+      th_Val[4].r_t = ((float) r_h * thErrON);
       th_Val[4].g_t = ((float) g_h * thErrON);
       th_Val[4].b_t = ((float) b_h * thErrOFF);
       break;
     }
   }
-  while((r > th_Val[0].r_t) | (g > th_Val[0].g_t)) //wait until red and green is LOW
-  {
-    tcs.getRawData(&r, &g, &b, &c);
+  while ((r > th_Val[0].r_t) | (g > th_Val[0].g_t)) //wait until red and green is LOW
+  {
+    tcs.getRawData(&r, &g, &b, &c);
   }
   Serial.print(".");
   //R0B
-  while((r < th_Val[0].r_t) | (b < th_Val[0].b_t)) //wait until red and blue is HIGH
-  {
-    tcs.getRawData(&r, &g, &b, &c);
-  }
-  delay(setupWaitTime);
+  while ((r < th_Val[0].r_t) | (b < th_Val[0].b_t)) //wait until red and blue is HIGH
+  {
+    tcs.getRawData(&r, &g, &b, &c);
+  }
+  delay(setupWaitTime);
   //set threshold for red-blue high
-     r_h = g_h = b_h = 0;
-  while(true)
+  r_h = g_h = b_h = 0;
+  while (true)
   {
     tcs.getRawData(&r, &g, &b, &c); //get env info
-    if(r > r_h)
+    if (r > r_h)
     {
       r_h = r;
-      if(g_h < g)
+      if (g_h < g)
       {
         g_h = g;
       }
     }
-    else if(b > b_h)
+    else if (b > b_h)
     {
       b_h = b;
-      if(g_h < g)
+      if (g_h < g)
       {
         g_h = g;
       }
     }
     else
     {
-      th_Val[5].r_t = ((float) r_h * thErrON);
-       th_Val[5].g_t = ((float) g_h * thErrOFF);
-        th_Val[5].b_t = ((float) b_h * thErrON);
+      th_Val[5].r_t = ((float) r_h * thErrON);
+      th_Val[5].g_t = ((float) g_h * thErrOFF);
+      th_Val[5].b_t = ((float) b_h * thErrON);
       break;
     }
   }
-
-  while((r > th_Val[0].r_t) | (b > th_Val[0].b_t)) //wait until red and blue is LOW
-  {
-    tcs.getRawData(&r, &g, &b, &c);
+
+  while ((r > th_Val[0].r_t) | (b > th_Val[0].b_t)) //wait until red and blue is LOW
+  {
+    tcs.getRawData(&r, &g, &b, &c);
   }
   Serial.print(".");
   //0GB
-  while((g < th_Val[0].g_t) | (b < th_Val[0].b_t)) //wait until green and blue is HIGH
-  {
-    tcs.getRawData(&r, &g, &b, &c);
-  }
-  delay(setupWaitTime);
+  while ((g < th_Val[0].g_t) | (b < th_Val[0].b_t)) //wait until green and blue is HIGH
+  {
+    tcs.getRawData(&r, &g, &b, &c);
+  }
+  delay(setupWaitTime);
   //set threshold for green-blue high
-     r_h = g_h = b_h = 0;
-  while(true)
+  r_h = g_h = b_h = 0;
+  while (true)
   {
     tcs.getRawData(&r, &g, &b, &c); //get env info
-    if(b > b_h)
+    if (b > b_h)
     {
       b_h = b;
-      if(r_h < r)
+      if (r_h < r)
       {
         r_h = r;
       }
     }
-    else if(g > g_h)
+    else if (g > g_h)
     {
       g_h = g;
-      if(r_h < r)
+      if (r_h < r)
       {
         r_h = r;
       }
     }
     else
     {
-     th_Val[6].r_t = ((float) r_h * thErrOFF);
-     th_Val[6].g_t = ((float) g_h * thErrON);
-     th_Val[6].b_t = ((float) b_h * thErrON);
+      th_Val[6].r_t = ((float) r_h * thErrOFF);
+      th_Val[6].g_t = ((float) g_h * thErrON);
+      th_Val[6].b_t = ((float) b_h * thErrON);
       break;
     }
   }
-  while((g > th_Val[0].g_t) | (b > th_Val[0].b_t)) //wait until green and blue is LOW
-  {
-    tcs.getRawData(&r, &g, &b, &c);
-  }
-  Serial.print(".");
-    //RGB
-  while((g < th_Val[0].g_t) | (b < th_Val[0].b_t) | (r < th_Val[0].r_t)) //wait until red, green and blue is HIGH
-  {
-    tcs.getRawData(&r, &g, &b, &c);
-  }
-  delay(setupWaitTime);
+  while ((g > th_Val[0].g_t) | (b > th_Val[0].b_t)) //wait until green and blue is LOW
+  {
+    tcs.getRawData(&r, &g, &b, &c);
+  }
+  Serial.print(".");
+  //RGB
+  while ((g < th_Val[0].g_t) | (b < th_Val[0].b_t) | (r < th_Val[0].r_t)) //wait until red, green and blue is HIGH
+  {
+    tcs.getRawData(&r, &g, &b, &c);
+  }
+  delay(setupWaitTime);
   //set threshold for red-green-blue high
-     r_h = g_h = b_h = 0;
-  while(true)
+  r_h = g_h = b_h = 0;
+  while (true)
   {
     tcs.getRawData(&r, &g, &b, &c); //get env info
-    if(r > r_h)
+    if (r > r_h)
     {
       r_h = r;
     }
-    else if(g > g_h)
+    else if (g > g_h)
     {
       g_h = g;
     }
     else if (b_h < b)
-      {
-        b_h = b;
-      }
+    {
+      b_h = b;
+    }
     else
     {
-       th_Val[7].r_t = ((float) r_h * thErrON);
-       th_Val[7].g_t = ((float) g_h * thErrON);
-        th_Val[7].b_t = ((float) b_h * thErrON);
+      th_Val[7].r_t = ((float) r_h * thErrON);
+      th_Val[7].g_t = ((float) g_h * thErrON);
+      th_Val[7].b_t = ((float) b_h * thErrON);
       break;
     }
   }

-  while((g > th_Val[0].g_t) | (b > th_Val[0].b_t) | (r > th_Val[0].r_t)) //wait until red, green and blue is HIGH
-  {
-    tcs.getRawData(&r, &g, &b, &c);
+  while ((g > th_Val[0].g_t) | (b > th_Val[0].b_t) | (r > th_Val[0].r_t)) //wait until red, green and blue is HIGH
+  {
+    tcs.getRawData(&r, &g, &b, &c);
   }
   Serial.println("Done");
   //print env values
-  for(int j = 0; j < 8; j++)
+  for (int j = 0; j < 8; j++)
   {
     Serial.print("Env ");
     Serial.print(j);
@@ -371,382 +372,399 @@
   Serial.println("Starting...");
 }

-void loop()
+void loop()
 {
-  short writtenCH = 0; //to count chars before new line
+  short writtenCH = 0; //to count chars before new line
   bool err = 0;
   tcs.getRawData(&r, &g, &b, &c);
-  if(g > th_Val[2].g_t)
-  {
-    listenSTR:
-     //send start bacon
-     digitalWrite(greenLED, HIGH);
-     delay(fbTime);
-     digitalWrite(greenLED, LOW);
-     delay(cycTime);
-
-     tcs.getRawData(&r, &g, &b, &c);
-
-     detect_rgb(r, g, b, th_Val, buff[0], buff[1], buff[2]);
-
-     digitalWrite(blueLED, HIGH);
-     delay(fbTime);
-     digitalWrite(blueLED, LOW);
-     delay(cycTime);
-
-     tcs.getRawData(&r, &g, &b, &c);
-
-     detect_rgb(r, g, b, th_Val, buff[3], buff[4], buff[5]);
-
-     digitalWrite(blueLED, HIGH);
-     delay(fbTime);
-     digitalWrite(blueLED, LOW);
-     delay(cycTime);
-
-     tcs.getRawData(&r, &g, &b, &c);
-
-     detect_rgb(r, g, b, th_Val, buff[6], buff[7], buff[8]);
-
-     digitalWrite(blueLED, HIGH);
-     delay(fbTime);
-     digitalWrite(blueLED, LOW);
-     delay(cycTime);
-
-     tcs.getRawData(&r, &g, &b, &c);
-
-   detect_rgb(r, g, b, th_Val, buff[9], buff[10], buff[11]);
+  if (g > th_Val[2].g_t)
+  {
+listenSTR:
+    //send start bacon
+    digitalWrite(greenLED, HIGH);
+    delay(fbTime);
+    digitalWrite(greenLED, LOW);
+    delay(cycTime);
+
+    tcs.getRawData(&r, &g, &b, &c);
+
+    detect_rgb(r, g, b, th_Val, buff[0], buff[1], buff[2]);
+
+    digitalWrite(blueLED, HIGH);
+    delay(fbTime);
+    digitalWrite(blueLED, LOW);
+    delay(cycTime);
+
+    tcs.getRawData(&r, &g, &b, &c);
+
+    detect_rgb(r, g, b, th_Val, buff[3], buff[4], buff[5]);
+
+    digitalWrite(blueLED, HIGH);
+    delay(fbTime);
+    digitalWrite(blueLED, LOW);
+    delay(cycTime);
+
+    tcs.getRawData(&r, &g, &b, &c);
+
+    detect_rgb(r, g, b, th_Val, buff[6], buff[7], buff[8]);
+
+    digitalWrite(blueLED, HIGH);
+    delay(fbTime);
+    digitalWrite(blueLED, LOW);
+    delay(cycTime);
+
+    tcs.getRawData(&r, &g, &b, &c);
+
+    detect_rgb(r, g, b, th_Val, buff[9], buff[10], buff[11]);

     checkParity(buff[2], buff[4], buff[5], buff[6], buff[8], buff[9], buff[10], buff[11], buff[0], buff[1], buff[3], buff[7], err);
-
-   ch = decodeASCII(buff[2], buff[4], buff[5], buff[6], buff[8], buff[9], buff[10], buff[11]);
-
-    if(ch != NULL)
-     {
+
+    ch = decodeASCII(buff[2], buff[4], buff[5], buff[6], buff[8], buff[9], buff[10], buff[11]);
+
+    if (ch != NULL)
+    {
       digitalWrite(redLED, HIGH);
       delay(redONtime);
       Serial.print(ch);
       writtenCH++;
-      if(writtenCH == 80)
-       {
-          Serial.print("\n");
-          writtenCH = 0;
-       }
-       digitalWrite(redLED, LOW);
-       delay(redOFFtime);
-       if(ch != '\n')
-           goto listenSTR;
-      }
-  }
-
+      if (writtenCH == 80)
+      {
+        Serial.print("\n");
+        writtenCH = 0;
+      }
+      digitalWrite(redLED, LOW);
+      delay(redOFFtime);
+      if (ch != '\n')
+        goto listenSTR;
+    }
+  }
+

   if (Serial.available() > 0)
   {
-    inputHOLD = Serial.readString();
-
-    if(inputHOLD == sync)
+    inputHOLD = Serial.readString();
+
+    if (inputHOLD == sync)
       synchronization();
-    else if(inputHOLD == crdM)
+    else if (inputHOLD == crdM)
     {
       Serial.println("In alphabetic order:\nOnur Calik\nMusab Cevik\nBaran Dereli\nOzgun Sensoy\nYigit Suoglu");
     }
-    else if(inputHOLD == recal) //start recalabration seq. wait for synchronization seq.
+    else if (inputHOLD == ledContol)
+    {
+      Serial.print("Enter led code: ");
+      while (true)
+      {
+        if (Serial.available() > 0)
+        {
+          inputHOLD = Serial.readString();
+          if (inputHOLD == "quit")
+          {
+            break;
+          }
+          short j = (int) inputHOLD[0] - 48;
+          ledControl(j);
+        }
+      }
+    }
+    else if (inputHOLD == recal) //start recalabration seq. wait for synchronization seq.
     {
       Serial.print("Getting enviroment values"); //get env
-  tcs.getRawData(&r, &g, &b, &c); //store environment values
-  th_Val[0].r_t = ((float) r * thErrOFF);
-  th_Val[0].g_t = ((float) g * thErrOFF);
-  th_Val[0].b_t = ((float) b * thErrOFF);
-  Serial.print("\nWaiting for threshold sequence");
-  uint16_t r_h, g_h, b_h;
-  setupMain: //come back here untill sync seq start
-  if (Serial.available() > 0) //if there is an input data
-  {
-    inputHOLD = Serial.readString(); //get input
-
-    if(inputHOLD == sync) //check for sync code
-      {
-        synchronization(); //if true sync
-        goto setupMain; //then go back
-       }
-  }
-  tcs.getRawData(&r, &g, &b, &c); //get env info
-  //R00
-  if(r < th_Val[0].r_t) //go back if red is lower then OFF threshold
-  {
-    goto setupMain;
-  }
-  delay(setupWaitTime);
-  Serial.print("Getting threshold values");
-  Serial.print(".");
-  //set threshold for red HIGH
-  r_h = g_h = b_h = 0;
-  while(true)
-  {
-    tcs.getRawData(&r, &g, &b, &c); //get env info
-    if(r > r_h)
-    {
-      r_h = r;
-      g_h = g;
-      b_h = b;
+      tcs.getRawData(&r, &g, &b, &c); //store environment values
+      th_Val[0].r_t = ((float) r * thErrOFF);
+      th_Val[0].g_t = ((float) g * thErrOFF);
+      th_Val[0].b_t = ((float) b * thErrOFF);
+      Serial.print("\nWaiting for threshold sequence\n");
+      uint16_t r_h, g_h, b_h;
+setupMain: //come back here untill sync seq start
+      if (Serial.available() > 0) //if there is an input data
+      {
+        inputHOLD = Serial.readString(); //get input
+
+        if (inputHOLD == sync) //check for sync code
+        {
+          synchronization(); //if true sync
+          goto setupMain; //then go back
+        }
+      }
+      tcs.getRawData(&r, &g, &b, &c); //get env info
+      //R00
+      if (r < th_Val[0].r_t) //go back if red is lower then OFF threshold
+      {
+        goto setupMain;
+      }
+      delay(setupWaitTime);
+      Serial.print("Getting threshold values");
+      Serial.print(".");
+      //set threshold for red HIGH
+      r_h = g_h = b_h = 0;
+      while (true)
+      {
+        tcs.getRawData(&r, &g, &b, &c); //get env info
+        if (r > r_h)
+        {
+          r_h = r;
+          g_h = g;
+          b_h = b;
+        }
+        else
+        {
+          th_Val[1].r_t = ((float) r_h * thErrON);
+          th_Val[1].g_t = ((float) g_h * thErrOFF);
+          th_Val[1].b_t = ((float) b_h * thErrOFF);
+          break;
+        }
+      }
+
+      while (r > th_Val[0].r_t) //wait until red is LOW
+      {
+        tcs.getRawData(&r, &g, &b, &c); //get env info
+      }
+      Serial.print(".");
+      //0G0
+      while (g < th_Val[0].g_t)
+      {
+        tcs.getRawData(&r, &g, &b, &c); //wait until green is HIGH
+      }
+      delay(setupWaitTime);
+      //set threshold for green high
+      r_h = g_h = b_h = 0;
+      while (true)
+      {
+        tcs.getRawData(&r, &g, &b, &c); //get env info
+        if (g > g_h)
+        {
+          r_h = r;
+          g_h = g;
+          b_h = b;
+        }
+        else
+        {
+          th_Val[2].r_t = ((float) r_h * thErrOFF);
+          th_Val[2].g_t = ((float) g_h * thErrON);
+          th_Val[2].b_t = ((float) b_h * thErrOFF);
+          break;
+        }
+      }
+      while (g > th_Val[0].g_t) //wait until green is LOW
+      {
+        tcs.getRawData(&r, &g, &b, &c);
+      }
+      Serial.print(".");
+      //00B
+      while (b < th_Val[0].b_t)
+      {
+        tcs.getRawData(&r, &g, &b, &c); //wait until blue is HIGH
+      }
+      delay(setupWaitTime);
+      //set threshold for blue high
+      r_h = g_h = b_h = 0;
+      while (true)
+      {
+        tcs.getRawData(&r, &g, &b, &c); //get env info
+        if (b > b_h)
+        {
+          r_h = r;
+          g_h = g;
+          b_h = b;
+        }
+        else
+        {
+          th_Val[3].r_t = ((float) r_h * thErrOFF);
+          th_Val[3].g_t = ((float) g_h * thErrOFF);
+          th_Val[3].b_t = ((float) b_h * thErrON);
+          break;
+        }
+      }
+      while (b > th_Val[0].b_t)
+      {
+        tcs.getRawData(&r, &g, &b, &c); //wait until blue is LOW
+      }
+      Serial.print(".");
+      //RG0
+      while ((r < th_Val[0].r_t) | (g < th_Val[0].g_t)) //wait until red and green is HIGH
+      {
+        tcs.getRawData(&r, &g, &b, &c);
+      }
+      delay(setupWaitTime);
+      //set threshold for red-green high
+      r_h = g_h = b_h = 0;
+      while (true)
+      {
+        tcs.getRawData(&r, &g, &b, &c); //get env info
+        if (r > r_h)
+        {
+          r_h = r;
+          if (b_h < b)
+          {
+            b_h = b;
+          }
+        }
+        else if (g > g_h)
+        {
+          g_h = g;
+          if (b_h < b)
+          {
+            b_h = b;
+          }
+        }
+        else
+        {
+          th_Val[4].r_t = ((float) r_h * thErrON);
+          th_Val[4].g_t = ((float) g_h * thErrON);
+          th_Val[4].b_t = ((float) b_h * thErrOFF);
+          break;
+        }
+      }
+      while ((r > th_Val[0].r_t) | (g > th_Val[0].g_t)) //wait until red and green is LOW
+      {
+        tcs.getRawData(&r, &g, &b, &c);
+      }
+      Serial.print(".");
+      //R0B
+      while ((r < th_Val[0].r_t) | (b < th_Val[0].b_t)) //wait until red and blue is HIGH
+      {
+        tcs.getRawData(&r, &g, &b, &c);
+      }
+      delay(setupWaitTime);
+      //set threshold for red-blue high
+      r_h = g_h = b_h = 0;
+      while (true)
+      {
+        tcs.getRawData(&r, &g, &b, &c); //get env info
+        if (r > r_h)
+        {
+          r_h = r;
+          if (g_h < g)
+          {
+            g_h = g;
+          }
+        }
+        else if (b > b_h)
+        {
+          b_h = b;
+          if (g_h < g)
+          {
+            g_h = g;
+          }
+        }
+        else
+        {
+          th_Val[5].r_t = ((float) r_h * thErrON);
+          th_Val[5].g_t = ((float) g_h * thErrOFF);
+          th_Val[5].b_t = ((float) b_h * thErrON);
+          break;
+        }
+      }
+
+      while ((r > th_Val[0].r_t) | (b > th_Val[0].b_t)) //wait until red and blue is LOW
+      {
+        tcs.getRawData(&r, &g, &b, &c);
+      }
+      Serial.print(".");
+      //0GB
+      while ((g < th_Val[0].g_t) | (b < th_Val[0].b_t)) //wait until green and blue is HIGH
+      {
+        tcs.getRawData(&r, &g, &b, &c);
+      }
+      delay(setupWaitTime);
+      //set threshold for green-blue high
+      r_h = g_h = b_h = 0;
+      while (true)
+      {
+        tcs.getRawData(&r, &g, &b, &c); //get env info
+        if (b > b_h)
+        {
+          b_h = b;
+          if (r_h < r)
+          {
+            r_h = r;
+          }
+        }
+        else if (g > g_h)
+        {
+          g_h = g;
+          if (r_h < r)
+          {
+            r_h = r;
+          }
+        }
+        else
+        {
+          th_Val[6].r_t = ((float) r_h * thErrOFF);
+          th_Val[6].g_t = ((float) g_h * thErrON);
+          th_Val[6].b_t = ((float) b_h * thErrON);
+          break;
+        }
+      }
+      while ((g > th_Val[0].g_t) | (b > th_Val[0].b_t)) //wait until green and blue is LOW
+      {
+        tcs.getRawData(&r, &g, &b, &c);
+      }
+      Serial.print(".");
+      //RGB
+      while ((g < th_Val[0].g_t) | (b < th_Val[0].b_t) | (r < th_Val[0].r_t)) //wait until red, green and blue is HIGH
+      {
+        tcs.getRawData(&r, &g, &b, &c);
+      }
+      delay(setupWaitTime);
+      //set threshold for red-green-blue high
+      r_h = g_h = b_h = 0;
+      while (true)
+      {
+        tcs.getRawData(&r, &g, &b, &c); //get env info
+        if (r > r_h)
+        {
+          r_h = r;
+        }
+        else if (g > g_h)
+        {
+          g_h = g;
+        }
+        else if (b_h < b)
+        {
+          b_h = b;
+        }
+        else
+        {
+          th_Val[7].r_t = ((float) r_h * thErrON);
+          th_Val[7].g_t = ((float) g_h * thErrON);
+          th_Val[7].b_t = ((float) b_h * thErrON);
+          break;
+        }
+      }
+
+      while ((g > th_Val[0].g_t) | (b > th_Val[0].b_t) | (r > th_Val[0].r_t)) //wait until red, green and blue is HIGH
+      {
+        tcs.getRawData(&r, &g, &b, &c);
+      }
+      Serial.println("Done");
+      //print env values
+      for (int j = 0; j < 8; j++)
+      {
+        Serial.print("Env ");
+        Serial.print(j);
+        Serial.print(" R: ");
+        Serial.print(th_Val[j].r_t);
+        Serial.print(" G: ");
+        Serial.print(th_Val[j].g_t);
+        Serial.print(" B: ");
+        Serial.println(th_Val[j].b_t);
+      }
+      Serial.println("Ready...");
     }
     else
     {
-      th_Val[1].r_t = ((float) r_h * thErrON);
-      th_Val[1].g_t = ((float) g_h * thErrOFF);
-      th_Val[1].b_t = ((float) b_h * thErrOFF);
-      break;
-    }
-  }
-
-  while(r > th_Val[0].r_t) //wait until red is LOW
-  {
-    tcs.getRawData(&r, &g, &b, &c); //get env info
-  }
-  Serial.print(".");
-    //0G0
-   while(g < th_Val[0].g_t)
-  {
-    tcs.getRawData(&r, &g, &b, &c); //wait until green is HIGH
-  }
-  delay(setupWaitTime);
-  //set threshold for green high
-    r_h = g_h = b_h = 0;
-  while(true)
-  {
-    tcs.getRawData(&r, &g, &b, &c); //get env info
-    if(g > g_h)
-    {
-      r_h = r;
-      g_h = g;
-      b_h = b;
-    }
-    else
-    {
-      th_Val[2].r_t = ((float) r_h * thErrOFF);
-      th_Val[2].g_t = ((float) g_h * thErrON);
-      th_Val[2].b_t = ((float) b_h * thErrOFF);
-      break;
-    }
-  }
-  while(g > th_Val[0].g_t) //wait until green is LOW
-  {
-    tcs.getRawData(&r, &g, &b, &c);
-  }
-  Serial.print(".");
-  //00B
-   while(b < th_Val[0].b_t)
-  {
-    tcs.getRawData(&r, &g, &b, &c); //wait until blue is HIGH
-  }
-  delay(setupWaitTime);
-  //set threshold for blue high
-  r_h = g_h = b_h = 0;
-  while(true)
-  {
-    tcs.getRawData(&r, &g, &b, &c); //get env info
-    if(b > b_h)
-    {
-      r_h = r;
-      g_h = g;
-      b_h = b;
-    }
-    else
-    {
-      th_Val[3].r_t = ((float) r_h * thErrOFF);
-      th_Val[3].g_t = ((float) g_h * thErrOFF);
-      th_Val[3].b_t = ((float) b_h * thErrON);
-      break;
-    }
-  }
-  while(b > th_Val[0].b_t)
-  {
-    tcs.getRawData(&r, &g, &b, &c); //wait until blue is LOW
-  }
-  Serial.print(".");
-  //RG0
-  while((r < th_Val[0].r_t) | (g < th_Val[0].g_t)) //wait until red and green is HIGH
-  {
-    tcs.getRawData(&r, &g, &b, &c);
-  }
-  delay(setupWaitTime);
-  //set threshold for red-green high
-   r_h = g_h = b_h = 0;
-  while(true)
-  {
-    tcs.getRawData(&r, &g, &b, &c); //get env info
-    if(r > r_h)
-    {
-      r_h = r;
-      if(b_h < b)
-      {
-        b_h = b;
-      }
-    }
-    else if(g > g_h)
-    {
-      g_h = g;
-      if(b_h < b)
-      {
-        b_h = b;
-      }
-    }
-    else
-    {
-      th_Val[4].r_t = ((float) r_h * thErrON);
-      th_Val[4].g_t = ((float) g_h * thErrON);
-      th_Val[4].b_t = ((float) b_h * thErrOFF);
-      break;
-    }
-  }
-  while((r > th_Val[0].r_t) | (g > th_Val[0].g_t)) //wait until red and green is LOW
-  {
-    tcs.getRawData(&r, &g, &b, &c);
-  }
-  Serial.print(".");
-  //R0B
-  while((r < th_Val[0].r_t) | (b < th_Val[0].b_t)) //wait until red and blue is HIGH
-  {
-    tcs.getRawData(&r, &g, &b, &c);
-  }
-  delay(setupWaitTime);
-  //set threshold for red-blue high
-     r_h = g_h = b_h = 0;
-  while(true)
-  {
-    tcs.getRawData(&r, &g, &b, &c); //get env info
-    if(r > r_h)
-    {
-      r_h = r;
-      if(g_h < g)
-      {
-        g_h = g;
-      }
-    }
-    else if(b > b_h)
-    {
-      b_h = b;
-      if(g_h < g)
-      {
-        g_h = g;
-      }
-    }
-    else
-    {
-      th_Val[5].r_t = ((float) r_h * thErrON);
-       th_Val[5].g_t = ((float) g_h * thErrOFF);
-        th_Val[5].b_t = ((float) b_h * thErrON);
-      break;
-    }
-  }
-
-  while((r > th_Val[0].r_t) | (b > th_Val[0].b_t)) //wait until red and blue is LOW
-  {
-    tcs.getRawData(&r, &g, &b, &c);
-  }
-  Serial.print(".");
-  //0GB
-  while((g < th_Val[0].g_t) | (b < th_Val[0].b_t)) //wait until green and blue is HIGH
-  {
-    tcs.getRawData(&r, &g, &b, &c);
-  }
-  delay(setupWaitTime);
-  //set threshold for green-blue high
-     r_h = g_h = b_h = 0;
-  while(true)
-  {
-    tcs.getRawData(&r, &g, &b, &c); //get env info
-    if(b > b_h)
-    {
-      b_h = b;
-      if(r_h < r)
-      {
-        r_h = r;
-      }
-    }
-    else if(g > g_h)
-    {
-      g_h = g;
-      if(r_h < r)
-      {
-        r_h = r;
-      }
-    }
-    else
-    {
-     th_Val[6].r_t = ((float) r_h * thErrOFF);
-     th_Val[6].g_t = ((float) g_h * thErrON);
-     th_Val[6].b_t = ((float) b_h * thErrON);
-      break;
-    }
-  }
-  while((g > th_Val[0].g_t) | (b > th_Val[0].b_t)) //wait until green and blue is LOW
-  {
-    tcs.getRawData(&r, &g, &b, &c);
-  }
-  Serial.print(".");
-    //RGB
-  while((g < th_Val[0].g_t) | (b < th_Val[0].b_t) | (r < th_Val[0].r_t)) //wait until red, green and blue is HIGH
-  {
-    tcs.getRawData(&r, &g, &b, &c);
-  }
-  delay(setupWaitTime);
-  //set threshold for red-green-blue high
-     r_h = g_h = b_h = 0;
-  while(true)
-  {
-    tcs.getRawData(&r, &g, &b, &c); //get env info
-    if(r > r_h)
-    {
-      r_h = r;
-    }
-    else if(g > g_h)
-    {
-      g_h = g;
-    }
-    else if (b_h < b)
-      {
-        b_h = b;
-      }
-    else
-    {
-       th_Val[7].r_t = ((float) r_h * thErrON);
-       th_Val[7].g_t = ((float) g_h * thErrON);
-        th_Val[7].b_t = ((float) b_h * thErrON);
-      break;
-    }
-  }
-
-  while((g > th_Val[0].g_t) | (b > th_Val[0].b_t) | (r > th_Val[0].r_t)) //wait until red, green and blue is HIGH
-  {
-    tcs.getRawData(&r, &g, &b, &c);
-  }
-  Serial.println("Done");
-  //print env values
-  for(int j = 0; j < 8; j++)
-  {
-    Serial.print("Env ");
-    Serial.print(j);
-    Serial.print(" R: ");
-    Serial.print(th_Val[j].r_t);
-    Serial.print(" G: ");
-    Serial.print(th_Val[j].g_t);
-    Serial.print(" B: ");
-    Serial.println(th_Val[j].b_t);
-  }
-  Serial.println("Ready...");
-    }
-    else
-    {
       digitalWrite(greenLED, HIGH);

       //Serial.print("\n");
-      for(int j=0; j<inputHOLD.length(); ++j)
-        {
-          flashSequence(inputHOLD[j]);
-        }
-        flashSequence('\n');
-       Serial.print("\n");
+      for (int j = 0; j < inputHOLD.length(); ++j)
+      {
+        flashSequence(inputHOLD[j]);
+      }
+      flashSequence('\n');
+      Serial.print("\n");
     }
     digitalWrite(redLED, LOW);
     digitalWrite(greenLED, LOW);
@@ -757,66 +775,66 @@
 void flashSequence(char sequence)
 {

-  encodeASCII(sequence, buff[2],buff[4],buff[5],buff[6],buff[8],buff[9],buff[10],buff[11]);
-  addParity(buff[2],buff[4],buff[5],buff[6],buff[8],buff[9],buff[10],buff[11], buff[0],buff[1],buff[3],buff[7]);
-
-
+  encodeASCII(sequence, buff[2], buff[4], buff[5], buff[6], buff[8], buff[9], buff[10], buff[11]);
+  addParity(buff[2], buff[4], buff[5], buff[6], buff[8], buff[9], buff[10], buff[11], buff[0], buff[1], buff[3], buff[7]);
+
+
   Serial.print(sequence); //for testing **********************************************
   Serial.print(": ");

-  tcs.getRawData(&r, &g, &b, &c);
-  while(g < th_Val[2].g_t)
+  tcs.getRawData(&r, &g, &b, &c);
+  while (g < th_Val[2].g_t)
   {
     tcs.getRawData(&r, &g, &b, &c);
   }
   digitalWrite(greenLED, LOW);

-  while(g > th_Val[0].g_t)
+  while (g > th_Val[0].g_t)
   {
     tcs.getRawData(&r, &g, &b, &c);
   }
   bool first = true;
-  int j =0;
-  while(j<12)
-  {
-    if(!first)
+  int j = 0;
+  while (j < 12)
+  {
+    if (!first)
     {
       tcs.getRawData(&r, &g, &b, &c); //store environment values
-      while(b > th_Val[0].b_t)
+      while (b > th_Val[0].b_t)
       {
         tcs.getRawData(&r, &g, &b, &c); //store environment values
       }
     }

     first = false;
-
-      flashDotOrDash(redLED, buff[j]);
-      j++;
-
-      flashDotOrDash(greenLED, buff[j]);
-      j++;
-
-      flashDotOrDash(blueLED, buff[j]);
-      j++;
-      if(j < 12)
-      {
-        while(b < th_Val[3].b_t)
-         {
-            tcs.getRawData(&r, &g, &b, &c); //store environment values
-         }
-      }
-      else
-      {
-        while(r < th_Val[1].r_t)
-         {
-            tcs.getRawData(&r, &g, &b, &c); //store environment values
-         }
-      }
-      flashDotOrDash(redLED, false);
-      flashDotOrDash(blueLED, false);
-      flashDotOrDash(greenLED, false);
-      Serial.print(" ");
-    delay(trnsDELAY);
+
+    flashDotOrDash(redLED, buff[j]);
+    j++;
+
+    flashDotOrDash(greenLED, buff[j]);
+    j++;
+
+    flashDotOrDash(blueLED, buff[j]);
+    j++;
+    if (j < 12)
+    {
+      while (b < th_Val[3].b_t)
+      {
+        tcs.getRawData(&r, &g, &b, &c); //store environment values
+      }
+    }
+    else
+    {
+      while (r < th_Val[1].r_t)
+      {
+        tcs.getRawData(&r, &g, &b, &c); //store environment values
+      }
+    }
+    flashDotOrDash(redLED, false);
+    flashDotOrDash(blueLED, false);
+    flashDotOrDash(greenLED, false);
+    Serial.print(" ");
+    delay(trnsDELAY);
   }
   Serial.println(); //for testing **************************************

@@ -824,111 +842,111 @@

 void synchronization()
 {
+  digitalWrite(redLED, HIGH);
+  delay(initDelay);
+  digitalWrite(redLED, LOW);
+  delay(initDelay);
+
+  digitalWrite(greenLED, HIGH);
+  delay(initDelay);
+  digitalWrite(greenLED, LOW);
+  delay(initDelay);
+
+  digitalWrite(blueLED, HIGH);
+  delay(initDelay);
+  digitalWrite(blueLED, LOW);
+  delay(initDelay);
+
+  digitalWrite(redLED, HIGH);
+  digitalWrite(greenLED, HIGH);
+  delay(initDelay);
+  digitalWrite(redLED, LOW);
+  digitalWrite(greenLED, LOW);
+  delay(initDelay);
+
+  digitalWrite(redLED, HIGH);
+  digitalWrite(blueLED, HIGH);
+  delay(initDelay);
+  digitalWrite(redLED, LOW);
+  digitalWrite(blueLED, LOW);
+  delay(initDelay);
+
+  digitalWrite(greenLED, HIGH);
+  digitalWrite(blueLED, HIGH);
+  delay(initDelay);
+  digitalWrite(greenLED, LOW);
+  digitalWrite(blueLED, LOW);
+  delay(initDelay);
+
+  digitalWrite(redLED, HIGH);
+  digitalWrite(greenLED, HIGH);
+  digitalWrite(blueLED, HIGH);
+  delay(initDelay);
+  digitalWrite(redLED, LOW);
+  digitalWrite(greenLED, LOW);
+  digitalWrite(blueLED, LOW);
+}
+
+void flashDotOrDash(int color, bool dotOrDash)
+{
+  Serial.print(dotOrDash); //for testing ******************************************
+  if (dotOrDash)
+    digitalWrite(color, HIGH);
+  else
+    digitalWrite(color, LOW);
+}
+
+void ledControl(int led)
+{
+  if (led == 0)
+  {
+    digitalWrite(redLED, LOW);
+    digitalWrite(greenLED, LOW);
+    digitalWrite(blueLED, LOW);
+  }
+  else if (led == 1)
+  {
     digitalWrite(redLED, HIGH);
-    delay(initDelay);
+    digitalWrite(greenLED, LOW);
+    digitalWrite(blueLED, LOW);
+  }
+  else if (led == 2)
+  {
     digitalWrite(redLED, LOW);
-    delay(initDelay);
-
     digitalWrite(greenLED, HIGH);
-    delay(initDelay);
+    digitalWrite(blueLED, LOW);
+  }
+  else if (led == 3)
+  {
+    digitalWrite(redLED, LOW);
     digitalWrite(greenLED, LOW);
-    delay(initDelay);
-
     digitalWrite(blueLED, HIGH);
-    delay(initDelay);
-    digitalWrite(blueLED, LOW);
-    delay(initDelay);
-
+  }
+  else if (led == 4)
+  {
     digitalWrite(redLED, HIGH);
     digitalWrite(greenLED, HIGH);
-    delay(initDelay);
+    digitalWrite(blueLED, LOW);
+  }
+  else if (led == 5)
+  {
+    digitalWrite(redLED, HIGH);
+    digitalWrite(greenLED, LOW);
+    digitalWrite(blueLED, HIGH);
+  }
+  else if (led == 6)
+  {
     digitalWrite(redLED, LOW);
-    digitalWrite(greenLED, LOW);
-    delay(initDelay);
-
-    digitalWrite(redLED, HIGH);
-    digitalWrite(blueLED, HIGH);
-    delay(initDelay);
-    digitalWrite(redLED, LOW);
-    digitalWrite(blueLED, LOW);
-    delay(initDelay);
-
     digitalWrite(greenLED, HIGH);
     digitalWrite(blueLED, HIGH);
-    delay(initDelay);
-    digitalWrite(greenLED, LOW);
-    digitalWrite(blueLED, LOW);
-    delay(initDelay);
-
+  }
+  else if (led == 7)
+  {
     digitalWrite(redLED, HIGH);
     digitalWrite(greenLED, HIGH);
     digitalWrite(blueLED, HIGH);
-    delay(initDelay);
-    digitalWrite(redLED, LOW);
-    digitalWrite(greenLED, LOW);
-    digitalWrite(blueLED, LOW);
-}
-
-void flashDotOrDash(int color, bool dotOrDash)
-{
-    Serial.print(dotOrDash); //for testing ******************************************
-    if(dotOrDash)
-        digitalWrite(color, HIGH);
-    else
-        digitalWrite(color, LOW);
-}
-
-void ledControl(int led)
-{
-  if(led == 0)
-  {
-    digitalWrite(redLED, LOW);
-    digitalWrite(greenLED, LOW);
-    digitalWrite(blueLED, LOW);
-  }
-  else if(led == 1)
-  {
-    digitalWrite(redLED, HIGH);
-    digitalWrite(greenLED, LOW);
-    digitalWrite(blueLED, LOW);
-  }
-  else if(led == 2)
-  {
-    digitalWrite(redLED, LOW);
-    digitalWrite(greenLED, HIGH);
-    digitalWrite(blueLED, LOW);
-  }
-  else if(led == 3)
-  {
-    digitalWrite(redLED, LOW);
-    digitalWrite(greenLED, LOW);
-    digitalWrite(blueLED, HIGH);
-  }
-  else if(led == 4)
-  {
-    digitalWrite(redLED, HIGH);
-    digitalWrite(greenLED, HIGH);
-    digitalWrite(blueLED, LOW);
-  }
-  else if(led == 5)
-  {
-    digitalWrite(redLED, HIGH);
-    digitalWrite(greenLED, LOW);
-    digitalWrite(blueLED, HIGH);
-  }
-  else if(led == 6)
-  {
-    digitalWrite(redLED, LOW);
-    digitalWrite(greenLED, HIGH);
-    digitalWrite(blueLED, HIGH);
-  }
-  else if(led == 7)
-  {
-    digitalWrite(redLED, HIGH);
-    digitalWrite(greenLED, HIGH);
-    digitalWrite(blueLED, HIGH);
-  }
-  else
+  }
+  else
     Serial.println("Please enter a number between 0 and 7!!");
 }


test ring

test ring

--- keypad/keypad.ino
+++ keypad/keypad.ino
@@ -301,6 +301,12 @@
         tone(melodyPin, NOTE_C3,noteDuration);

         rainbowCycle(20);
+        lightRing(8, pixels.Color(100,150,100));
+        delay(125);
+        lightRing(10, pixels.Color(100,150,100));
+        delay(125);
+        lightRing(0, pixels.Color(100,150,100));
+        delay(125);

         break;
       case '#':
@@ -394,8 +400,8 @@
   uint16_t i, j;

   for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
-    for(i=0; i< pixels.numPixels(); i++) {
-      pixels.setPixelColor(i, Wheel(((i * 256 / pixels.numPixels()) + j) & 255));
+    for(i=0; i< ringPixels; i++) {
+      pixels.setPixelColor(i, Wheel(((i * 256 / ringPixels) + j) & 255));
     }
     pixels.show();
     delay(wait);
@@ -418,7 +424,7 @@
 }

 void killRing (){
-  for(uint16_t i=0; i< pixels.numPixels(); i++) {
+  for(uint16_t i=0; i< ringPixels; i++) {
       pixels.setPixelColor(i, 0);
     }
     pixels.show();


Bridge, TemperatureWebPanel example: mention that the example must be uploaded via wifi

--- libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino
+++ libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino
@@ -7,6 +7,8 @@
  The circuit:
  * TMP36 temperature sensor on analog pin A1
  * SD card attached to SD card slot of the Arduino Yún
+
+ This sketch must be uploaded via wifi.

  Prepare your SD card with an empty folder in the SD root
  named "arduino" and a subfolder of that named "www".


throttle input

throttle input

--- longboard-ctl.ino
+++ longboard-ctl.ino
@@ -10,7 +10,8 @@

 // Used for blinking on error
 #define StatusLed 13
-#define Throttle 9
+#define ThrottleSensor1 A0
+#define ThrottleOut 9
 #define DataReadyIntPin 2

 // Bluetooth pins 0, 1, 3V3
@@ -20,7 +21,7 @@
 // serial config is default: 8, 1, n

-// Pin that defines the address of accelerometer
+// Pin that defines the address of accelerometer, (is grounded?)
 #define SA0 1

 #include <Wire.h>
@@ -33,6 +34,11 @@
 #define AccelerometerNewDataInterrupt 1
 // Software Filter for acceleration
 #define AccelerometerSoftFilter 1
+
+
+// TESTING
+#define SendAccelerometerDebug 0
+#define SendThrottleDebug 1

@@ -84,6 +90,11 @@
     pinMode(StatusLed, OUTPUT);
     digitalWrite(StatusLed, HIGH); // High until setup ends

+    pinMode(ThrottleSensor1, INPUT);
+    // internal pull-up
+    // digitalWrite(ThrottleSensor1, HIGH);
+    pinMode(ThrottleOut, OUTPUT);
+    analogWrite(ThrottleOut, 128);

     // Connect bluetooth serial
     setupBluetooth();
@@ -118,9 +129,20 @@
     lastAccTime = newAccTime;
     lastAccValue = x;

+#if SendAccelerometerDebug
     Bluetooth.println(xVelocity*1000);
-
-}
+#endif
+
+    int throttleIn = analogRead(ThrottleSensor1);
+
+#if SendThrottleDebug
+    Bluetooth.print('E');
+    Bluetooth.print(throttleIn);
+    Bluetooth.println();
+#endif
+
+}
+
 inline float getUnfilteredXAcc() {
     float x, y, z;

@@ -149,16 +171,19 @@
             (zeroResetCounter < MaxZeroCounter) ? 2 : 0 ;
     else
         zeroResetCounter = (float) zeroResetCounter * 0.4;
-
+#if SendAccelerometerDebug
     Bluetooth.print('E');
     Bluetooth.print(x*1000);
     Bluetooth.print(',');
+#endif
 #if AccelerometerSoftFilter
     lpFilter.input(x);
     x = lpFilter.output();
 #endif
+#if SendAccelerometerDebug
     Bluetooth.print(x*1000);
     Bluetooth.print(',');
+#endif
     return x;
 }


Fix typo in TrebleBoost_wApp

Fix typo in TrebleBoost_wApp


about to start refactoring arduino code into commands

--- ImageAnalysis/PrinterMechanics_Scanner/PrinterMechanics_Scanner.ino
+++ ImageAnalysis/PrinterMechanics_Scanner/PrinterMechanics_Scanner.ino
@@ -79,8 +79,8 @@

 	//Serial.println(analogRead(JoyH_X));
 	//Serial.println(analogRead(JoyH_Y));
-	//Serial.println(analogRead(JoyV_Y));
-	//Serial.println(analogRead(JoyV_X));
+	Serial.println(analogRead(JoyV_Y));
+	Serial.println(analogRead(JoyV_X));
 	//Serial.println(digitalRead(JoyV_SW));

 	// Big
@@ -95,30 +95,30 @@
 	}

 	// Scanner
-	if (analogRead(JoyH_X)<400)	{
+	if (analogRead(JoyH_X)<400)	{ // Right
 		move_stepper(StepPinH_X, 1);
 		digitalWrite(DirectionPinH_X, HIGH);
 	}

-	if (analogRead(JoyH_X)>600)	{
+	if (analogRead(JoyH_X)>600)	{ // Left
 		move_stepper(StepPinH_X, 1);
 		digitalWrite(DirectionPinH_X, LOW);
 	}

 	// DVD

-	if (analogRead(JoyV_Y)<400)	{
+	if (analogRead(JoyV_Y)<400)	{ // Up
 		move_stepper(StepPinV_Y, 700);
 		digitalWrite(DirectionPinV_Y, HIGH);
 	}

-	if (analogRead(JoyV_Y)>600)	{
+	if (analogRead(JoyV_Y)>600)	{ // Down
 		move_stepper(StepPinV_Y, 700);
 		digitalWrite(DirectionPinV_Y, LOW);
 	}

-	// Servo
-	if (digitalRead(JoyV_SW) == HIGH) {
+	// Servo
+	if (digitalRead(JoyV_SW) == HIGH) { // Up
 		if (dvd_down.read() != init_start_pos) {
 			unsigned long currentMillis = millis();

@@ -135,7 +135,7 @@
 		}
 	}

-	if (digitalRead(JoyV_SW) == LOW) {
+	if (digitalRead(JoyV_SW) == LOW) { // Down
 		if (dvd_down.read() != init_end_pos) {
 			unsigned long currentMillis = millis();
 			if (currentMillis - previousMillis >= interval) { // Execute on every interval


keep track of each bucket seperately

keep track of each bucket seperately

--- DanceFeather/DanceFeather.ino
+++ DanceFeather/DanceFeather.ino
@@ -69,7 +69,7 @@
   sht30.begin();
   PDM.onReceive(onPDMdata);
   PDM.begin(1, 16000);
-  PDM.setGain(5);
+  PDM.setGain(10);

   // init hann window
   for (int i = 0; i < HANN_SIZE ; i++) {
@@ -238,10 +238,10 @@
 	}
 }

-float _old_phase = 0;
+float prevPhase[END_INDEX];
 uint16_t _old_max_index = 0;
-float _phase_avg = 0;
-float _phaseRateAverage = 0;
+float phaseAvg[END_INDEX];
+float phaseRateAverage[END_INDEX];

 void updatePhase(const float mag[], const float phases[], uint16_t startIndex, uint16_t endIndex) {
     float maxValue = -1000;
@@ -255,53 +255,40 @@
             maxValue = val;
             maxIndex = i;
         }
-    }
-    // Serial.print("INDEX: "); Serial.println(maxIndex);
-
-    float phase = phases[maxIndex];
-
-    // Add the rate to our phase even in the case where we don't update the rate.
-    _phase_avg += _phaseRateAverage;
-    _phase_avg = norm_rads(_phase_avg);
-
-    if (maxIndex == _old_max_index && maxIndex > 1) {
-        float phaseDiff = norm_rads(phase - _old_phase);
-
-        // when we jump buckets, we need to be able to change beat
-        if (maxIndex > 4) {
-          phaseDiff *= 0.5;
-          if (abs(_phase_avg) > PI / 2) {
-            phase = phase * 0.5;
-          } else {
-            phase = PI + phase * 0.5;
-          }
-        }
+
+        float phase = phases[i];
+        float old_phase = prevPhase[i];
+	prevPhase[i] = phase;
+
+        // Add the rate to our phase even in the case where we don't update the rate.
+        phaseAvg[i] += phaseRateAverage[i];
+        phaseAvg[i] = norm_rads(phaseAvg[i]);
+
+        float phaseDiff = norm_rads(phase - old_phase);

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

-        if (phase + PI < _phase_avg) {
+        if (phase + PI < phaseAvg[i]) {
             phase += 2*PI;
-        } else if (phase - PI > _phase_avg) {
+        } else if (phase - PI > phaseAvg[i]) {
             phase -= 2*PI;
         }

-        _phase_avg = _phase_avg * 0.9 + phase * 0.1;
-        _phase_avg = norm_rads(_phase_avg);
+        phaseAvg[i] = phaseAvg[i] * 0.9 + phase * 0.1;
+        phaseAvg[i] = norm_rads(phaseAvg[i]);
         // Serial.print("Phase    : "); Serial.println(phase);
         // Serial.print("Phase: "); Serial.println(_phase_avg);
-
     }

-    if (_phase_avg > 0) {
-      digitalWrite(LED_PIN, LOW);
-    } else {
-      digitalWrite(LED_PIN, HIGH);
-    }
-
-    _old_phase = phase;
+    //if (_phase_avg > 0) {
+    //  digitalWrite(LED_PIN, LOW);
+    //} else {
+    //  digitalWrite(LED_PIN, HIGH);
+    //}
+
     _old_max_index = maxIndex;
 }

@@ -325,7 +312,7 @@

   float diff = max(0, windowedVal - prevWindowedVal);
   fftBuffer[0] = diff;
-  Serial.print("Diff: "); Serial.println(diff);
+  // Serial.print("Diff: "); Serial.println(diff);

   prevWindowedVal = windowedVal;

@@ -335,24 +322,36 @@
   // KickFFT<int32_t>::fft(fs, 0, 4, FFT_SIZE, fftBuffer, mag, startIndex, endIndex);
   fft_phase(FS, 0, F2, FFT_SIZE, fftBuffer, mag, phase, startIndex, endIndex);
   updatePhase(mag, phase, startIndex, endIndex);
-  float hz = FS * _phaseRateAverage / 2 / PI;
+
+  if (diff > 0) {
+    Serial.print("BPM:\t");
+    for (int i = 0; i < endIndex; i++) {
+      float hz = FS * phaseRateAverage[i] / 2 / PI;
+      float bpm = hz * 60;
+      Serial.print(bpm);
+      Serial.print("\t");
+    }
+    Serial.println("");
+  }
+
+  // float hz = FS * phaseRateAverage / 2 / PI;
   // Serial.print("endIndex: "); Serial.println(endIndex);
   // Serial.print("END_INDEX: "); Serial.println(END_INDEX);
   // Serial.print("BPM: "); Serial.println(hz * 60);
-  //Serial.print("radsPerUpdate: "); Serial.println(_phaseRateAverage);
-
-
-  // each sample changes the phase _phaseRateAverage rads
+  //Serial.print("radsPerUpdate: "); Serial.println(phaseRateAverage);
+
+
+  // each sample changes the phase phaseRateAverage rads

   // Serial.print("startIndex: ");
   // Serial.print(startIndex);
-  Serial.print("  Mag: ");
-  for (int i = startIndex; i < endIndex; i++) {
-    Serial.print(mag[i]);
-    Serial.print(" ");
-  }
-  Serial.println("");
+  // Serial.print("  Mag: ");
+  // for (int i = startIndex; i < endIndex; i++) {
+  //   Serial.print(mag[i]);
+  //   Serial.print(" ");
+  // }
+  // Serial.println("");

   // Serial.print("Phase: ");
   // for (int i = startIndex; i < endIndex; i++) {


Megaに対応.

Megaに対応.

--- sketch/arduinode/arduinode.ino
+++ sketch/arduinode/arduinode.ino
@@ -57,6 +57,36 @@
   {"EXTERNAL", EXTERNAL}
 };

+volatile uint32_t interrupt_counter[6] = {0};
+
+void interrupt0(void){
+  ++interrupt_counter[0];
+}
+void interrupt1(void){
+  ++interrupt_counter[1];
+}
+void interrupt2(void){
+  ++interrupt_counter[2];
+}
+void interrupt3(void){
+  ++interrupt_counter[3];
+}
+void interrupt4(void){
+  ++interrupt_counter[4];
+}
+void interrupt5(void){
+  ++interrupt_counter[5];
+}
+
+const VOID_FUNC_PTR INTERRUPT_FUNC_TBL[] = {
+  interrupt0,
+  interrupt1,
+  interrupt2,
+  interrupt3,
+  interrupt4,
+  interrupt5,
+};
+
 #else
 /*******************
   Arduino Unoとか
@@ -76,28 +106,28 @@
   {"EXTERNAL", EXTERNAL}
 };

+volatile uint32_t interrupt_counter[2] = {0};
+void interrupt0(void){
+  ++interrupt_counter[0];
+}
+
+void interrupt1(void){
+  ++interrupt_counter[1];
+}
+
+const VOID_FUNC_PTR INTERRUPT_FUNC_TBL[] = {
+  interrupt0,
+  interrupt1,
+};
+
+#endif
+
 const struct STR_UINT8_PEAR INTERRUPT_MODE_TBL[] = {
   {"LOW", LOW},
   {"CHANGE", CHANGE},
   {"RISING", RISING},
   {"FALLING", FALLING}
 };
-
-volatile uint32_t interrupt_counter[2] = {0};
-void interrupt0(void){
-  ++interrupt_counter[0];
-}
-
-void interrupt1(void){
-  ++interrupt_counter[1];
-}
-
-const VOID_FUNC_PTR INTERRUPT_FUNC_TBL[] = {
-  interrupt0,
-  interrupt1,
-};
-
-#endif

 const prog_char ILLEGAL_COMMAND[] PROGMEM       = "Illegal command.";
 const prog_char ILLEGAL_TYPE[] PROGMEM          = "Illegal type.";


add starting text, ask for version last, fix baudrate to 115200 to match tutorial

--- examples/GPS_SoftwareSerial_EchoTest/GPS_SoftwareSerial_EchoTest.ino
+++ examples/GPS_SoftwareSerial_EchoTest/GPS_SoftwareSerial_EchoTest.ino
@@ -38,17 +38,19 @@
 void setup() {
   while (!Serial); // wait for Serial to be ready

-  Serial.begin(57600); // this baud rate doesn't actually matter!
+  Serial.begin(115200); // The serial port for the Arduino IDE port output
   mySerial.begin(9600);
   delay(2000);
-  Serial.println("Get version!");
-  mySerial.println(PMTK_Q_RELEASE);

+  Serial.println("Software Serial GPS Test Echo Test");
   // you can send various commands to get it started
   //mySerial.println(PMTK_SET_NMEA_OUTPUT_RMCGGA);
   mySerial.println(PMTK_SET_NMEA_OUTPUT_ALLDATA);

   mySerial.println(PMTK_SET_NMEA_UPDATE_1HZ);
+
+  Serial.println("Get version!");
+  mySerial.println(PMTK_Q_RELEASE);
  }

@@ -62,4 +64,4 @@
     char c = mySerial.read();
     Serial.write(c);
   }
-}
+}


had rotary switch without required pullup

--- KSPboard.ino
+++ KSPboard.ino
@@ -76,7 +76,7 @@
 #define OPS 16 // Action 1-10, stage, gear, light, rcs, brake, abort

 // helm
-#define RAMP_MAX 50
+#define RAMP_MAX 65
 #define RAMP_MIN -RAMP_MAX
 #define DIR_MAX 2000
 #define DIR_MIN -DIR_MAX
@@ -238,7 +238,7 @@
 void setupControl()
 {
   // when you click the dial
-  pinMode(PIN_ROT_CTRL_SW, INPUT);
+  pinMode(PIN_ROT_CTRL_SW, INPUT_PULLUP);

   // set the data line as input as well
   pinMode(PIN_ROT_CTRL_DATA, INPUT);


more tweaking

more tweaking

--- mocap_usbtext/mocap_usbtext.ino
+++ mocap_usbtext/mocap_usbtext.ino
@@ -17,9 +17,8 @@

   sen.setGyroFullScale(2000);
   sen.setGyroOutputDataRate(LSM9DS0_RATE_95);
-  sen.setGyroBandwidthCutOffMode(LSM9DS0_BW_HIGH);
+  sen.setGyroBandwidthCutOffMode(LSM9DS0_BW_LOW);
   sen.setGyroDataFilter(LSM9DS0_LOW_PASS);
-  sen.setFIFOEnabled(false);

   sen.setAccRate(LSM9DS0_ACC_RATE_100);
   sen.setAccFullScale(LSM9DS0_ACC_2G);
@@ -50,6 +49,7 @@
      o->q1 = o->q2 = o->q3 = 0;
      o->exInt = o->eyInt = o->ezInt = 0;

+
 //     p(m.gx);p("\t");p(m.gy);p("\t");p(m.gz);p("\t");
 //     p(m.ax);p("\t");p(m.ay);p("\t");p(m.az);p("\t");
 //     p(m.mx);p("\t");p(m.my);p("\t");p(m.mz);p("\n");


Forgot to make longer delay change when short delay was incremented.

--- Debug_Auto.ino
+++ Debug_Auto.ino
@@ -7,10 +7,82 @@
  documentation. Filename: DebugManchester.ino ReadMe: DebugMan.md

  Please leave comment or suggestions in the "Issues" feature on the GIT-Hub site
-
- Remember to check both nos of Bytes and header hits settings for sensible data.
-
- DebugVersion_09, 28tyh July 2014
+
+ DebugAuto, 28th July 2014
+
+ This version steps automatically through a series of delays 10uS at a time each 5mins
+ and attempts to decode Manchester encoded signals.  The Polarity of the code can be either
+ positive or negative.  This program detects longer intervals bewtween transitions
+ as 'faulty' zeroes and automatically reverses the Polarity setting for subsequent
+ packets.  Because it starts off at a fairly unlikely setting for a Weather Station
+ (low durations between samples) few packets will be initially decoded, if any at all.
+ You will have to be patient and wait until the timings get closer and data finally
+ begins to appear.  This may involve looking at a static screen for quite a while,
+ as it steps through the 10uS increments. When the data does begin to appear then
+ note down the Polarity and what delay is best.  You should also allow it to go through
+ to longer and longer delays to there the packets begin to reduce in numbers so you know
+ you have the best mid point for the sDelay setting.
+
+ The aim of this program it to provide experimenters and hackers a simple to use tool that
+ will reveal the basic settings to receive a particular systems codes.  The program can
+ be easily modified to become the basis of permanent installations when an experimenter
+ adds in their own calculations and procedures. I have overdone the comments but hopefully
+ experimenters, especially beginners will appreciate the overflow! Experts delete them!
+ For actual installations the program can be stripped back to its bare essentials by
+ deleting all the debug and incrementing stuff etc and putting chosen final values for all
+ the parameters.
+
+ Considerable lattitude is allowed in choosing a sDelay value to set up the Manchester
+ decoding and experimenters may find there are a range of values of sDelay to choose from.
+ Generally aim for the mididle ground to give you a bit of room to handle errors on either
+ side. Variations up to +-10-15% are tolerated due to the program syncing each bit
+ to the middle transition event that always occurs in proper Manchester encoding.  So
+ small errors are contirnually corrected and do not accumulate.
+
+ So expect to see a fairly broad band of sDelays that will work OK.  Once you
+ are satisfied you have the sDelay and Polarity worked out (only two settings!)
+ you can begin pulling the program apart for your own purposes and building your
+ own version, eg what bits get discarded, how many bytes, packet repeat etc
+
+ The knowledge for this program came from wanting to intercept the signals from
+ a Bios (or Thermor) weather station to feed into my 24/7 weather www page.
+ I had to get to get to grips with the Manchester encoding first and after many
+ false starts I succeeded.  After that came the decryption of the packets and
+ calculating of meaningful values.  My old Bios broke down and I swapped to an Oregon
+ Scientific WS, and had to do it all over again.  Both quite different animals, so to
+ speak, but both used Manchester Encoding.  Second time through was a lot quicker
+ but after having tried to help people do the same on the Arduino Forums I figured
+ I needed to publish some good stuff for people to read up on.
+
+ After a while I wanted to streamline my Manchester decoding logic and the result
+ of that is here in this program.  With better logic and a much tighter procedure
+ (instead of one routine for the header and another for the packet data, this routine
+ can do it all in one!) design, I have been able to make it almost automatic to
+ at least get some Manchester data from something like a weather station. If the
+ bit waveform has a duration very much above or below 1mS the automatic part will
+ will fall down.  If the duration gets very short where the delay caused by the
+ processing becomes similar in size to the sDelay then program will probably work
+ but will need fairly inspired alterations.  The simple relationship that
+    lDelay=2*sDelay will probably break down. Then the sDelay and lDelay may need to
+ to be determined independently.  For longer delays the 1:2 relation will work fine
+ but the auto detection will need the loopCount and timeout turned into a word
+ variable as it is only a byte varaible at the moment to maximise the speed of the
+ loopCount++ counting.  As the delays get bigger counting in words will not matter.
+     timeout=lDelay/5; may need to change as well to keep the timeout (the number
+ of loop++'s) to be about 1.5 times the duration of the sDelay duration.
+
+ Obviously once the validation of the packets is working ie checked by repeats or
+ a numerical checksum, then if this process is repeated the best timings will become
+ even more evident.  This checking will eliminate packets that don't have any
+ obvious Manchester decoding errors, but do in fact have internal errors.
+
+ Please read the other documents on my GIT-Hub site that accompany this program for
+ a fuller understanding of the Manchester concepts so you can "do you own thing!!"
+
+ I hope you enjoy your own personal journey as I have enjoyed mine and this program
+ heklps you enjoy even more :-)  Best wishes for your progress!
+
+ Rob Ward

  */

@@ -29,9 +101,10 @@
 byte    timeout       ;    //Maximum loops allowed to look for the next bit transition
 byte    loopCount     ;    //Incremented inside the loop looking for next bit transition
 //variables for Header detection
-byte    headerBits = 15;   //The number of ones expected to make a valid header
+byte    headerBits = 10;   //The number of ones expected to make a valid header
 byte    headerHits = 0;    //Counts the number of "1"s to determine a header
 boolean firstZero  = false;//has it processed the first zero yet?  This a "sync" bit.
+word    nosHits    = 0;    //number hex dumps achieved (not necessarily error free, just hits!)
 //Variables for Byte storage
 byte    discards   = 0;    //how many leading "bits" need to be dumped, usually just a zero if anything eg discards=1
 byte    dataByte   = 0;    //Accumulates the bit information
@@ -85,7 +158,7 @@
   sei();

-  Serial.println("Debug Manchester Version GIT-Hub V01");
+  Serial.println("Debug Manchester Version GIT-Hub V03");
   lDelay=2*sDelay;//just to make sure the 1:2 ratio is established. They can have some other ratio if required
   Serial.print("Using a delay of 1/4 bitWaveform ");// +-15% and they still seem to work ok, pretty tolerant!
   Serial.print(sDelay,DEC);
@@ -109,7 +182,7 @@
   }
   timeout=lDelay/5;//Rough number to indicate max loops allowed, if exceeded usually wrong polarity chosen, heals itself if wrong
   Serial.print(timeout,DEC);
-  Serial.println(" timeout for wrong Polarity");
+  Serial.println(" initial timeout to detect wrong Polarity");
   Serial.println("P 00 00001111 01 22223333 02 44445555 03 66667777 04 88889999 05 AAAABBBB 06 CCCCDDDD 07 EEEEFFFF 08 00001111 90 22223333");
   Serial.print("sDelay =");
   Serial.println(sDelay,DEC);
@@ -124,8 +197,13 @@
   if (seconds == 300){//make 300 for each output ie 5 minutes
     sDelay = sDelay+10;
     seconds = 0;
-    Serial.print("sDelay =");
+    Serial.print("Nos Hits =");//Number of successful Hex dumps (not necessarily fre of errors)
+    Serial.println(nosHits,DEC);
+    nosHits=0;
+    Serial.print("sDelay =");//So the progress of the increments on sDelay can be monitored
     Serial.println(sDelay,DEC);
+    lDelay = sDelay*2;//Assume the sampling delays are ratio 1:2
+    timeout=lDelay/5; //Rough number to indicate max loops allowed, if exceeded usually wrong polarity chosen, heals itself if wrong
   }
 } //end of interrupt routine

@@ -141,7 +219,7 @@
     loopCount=0;
     while(digitalRead(RxPin)!=tempBit){
       //pause here until a transition is found
-      loopCount++;//track how long the wait is, too long=error!
+      loopCount++;//track how long the wait is, if too long=error!
     }//at Data transition, half way through bit pattern, this should be where RxPin==tempBit
     delayMicroseconds(sDelay);//skip ahead to 3/4 of the bit pattern
     // 3/4 the way through, if RxPin has changed it is definitely an error
@@ -160,11 +238,14 @@
         //data transition detection must swap, so it loops for the opposite transition in the next bit waveform
         tempBit = tempBit^1;
       }//end of detecting no transition at end of bit waveform
+      //when looping to detect the transition in middle of bit waveform it must never take too long
       if(loopCount>timeout){
-        noErrors=false;
+        noErrors=false;//not allowed to sync on an incorrect transition
+        //if in the header phase and looking for the sync 0
         if ((!firstZero)&&(headerHits>headerBits)){
-          //Serial.println(loopCount,DEC);
-          polarity = polarity^1;
+          //ending here means the zero was found but polarity was wrong
+          //Serial.println(loopCount,DEC);//enable for debugging
+          polarity = polarity^1;//switch polarity and try for next packet
           //Serial.print("Polarity now =");
           //Serial.println(polarity,DEC);
         }
@@ -203,10 +284,6 @@
   digitalWrite(ledPin,0); //data processing exited, look for another header
 }//end of mainloop

-//Read the binary data from the bank and apply conversions where necessary to scale and format data
-void analyseData(){
-}
-
 void add(byte bitData){
   if (discards>0){ //if first one, it has not been found previously
     discards--;
@@ -221,15 +298,20 @@
       //Serial.print("B");
     }
     if(nosBytes==maxBytes){
+      nosHits++;//keep track
       hexBinDump();//for debug purposes dump out in hex and bainary
       //analyseData();//later on develop your own analysis routines
     }
   }
 }

+//Read the binary data from the bank and apply conversions where necessary to scale and format data
+void analyseData(){
+}
+
 void hexBinDump(){
   //Print the fully aligned binary data in manchester[bank] array
-  Serial.print(polarity,DEC);
+  Serial.print(polarity,DEC);//show what polarity was used to reveal the packet
   Serial.print(" ");
   for( int i=0; i < maxBytes; i++){
     byte mask = B10000000;


Not for esp32

Not for esp32

--- espLightServerRGB.ino
+++ espLightServerRGB.ino
@@ -1,359 +0,0 @@
-#include <ESP8266WiFi.h>
-#include <DNSServer.h>
-#include <ESP8266WebServer.h>
-#include <WiFiManager.h>
-#include <ESP8266HTTPClient.h>
-#include <Ticker.h>
-#include <ESP8266mDNS.h>
-#include <OneWire.h>
-#include <DallasTemperature.h>
-#define ONE_WIRE_BUS D4
-String resetpass = "YourResetPassword"; // password to reset wifimanager when allready connected
-const String thingkey = "YOURTHINGSPEKKEY"; //your thingspeak API key
-String dernadd = "Fraichement booté"; //variable for ip logging (you can put your fresh boot mesage here in text/html)
-int pinRouge = D1; // pin for red leds
-int pinVerte = D7; // pin for green leds
-int pinBleu = D5; // pin for blue leds
-const long interval = 60000; // interval in ms for sending temperature data to thingspeak
-const String liens = "Acceuil - Température - Version - Reset - Temp stats\n"; // html/links shown at bottom of pages
-ESP8266WebServer server(80);
-String derncoul;
-long r;
-long g;
-long b;
-int rouge = 0;
-int vert = 0;
-int bleu = 0;
-unsigned long previousMillis = 0;
-OneWire oneWire(ONE_WIRE_BUS);
-DallasTemperature sensors(&oneWire);
-int roulepastusuite = 0;
-Ticker tiqueFade;
-
-const String css = "\n";
-
-void fadeRGB() {
-  if (r == rouge && g == vert && b == bleu) {
-    tiqueFade.detach();
-//    Serial.println("Stopping");
-  }
-  for (int i = 0; i <= 2; i++) {
-    int couleur;
-    int tc;
-    int pinouche;
-    switch (i) {
-      case 0:
-        pinouche = pinRouge;
-        tc = r;
-        couleur = rouge;
-        break;
-      case 1:
-        pinouche = pinVerte;
-        tc = g;
-        couleur = vert;
-        break;
-      case 2:
-        pinouche = pinBleu;
-        tc = b;
-        couleur = bleu;
-        break;
-    }
-    if (couleur < tc) {
-      couleur++;
-      analogWrite(pinouche, couleur);
-    } else if (couleur > tc) {
-      couleur--;
-      analogWrite(pinouche, couleur);
-    }
-    switch (i) {
-      case 0:
-        rouge = couleur;
-        break;
-      case 1:
-        vert = couleur;
-        break;
-      case 2:
-        bleu = couleur;
-        break;
-    }
-  }
-}
-
-void handleRoot() {
-  String addy = server.client().remoteIP().toString();
-  //  Serial.println("");
-  //  Serial.println(addy);
-  String testteu = server.arg("COULEUR");
-  //  Serial.println(testteu);
-  if (testteu != 0) {
-    derncoul = testteu;
-    long number = strtol( &testteu[1], NULL, 16);
-    // Split them up into r, g, b values
-    r = number >> 16;
-    g = number >> 8 & 0xFF;
-    b = number & 0xFF;
-    if (r != rouge) {
-      //      Serial.print("Rouge = ");
-      //      Serial.println(r);
-      tiqueFade.attach_ms(40, fadeRGB);
-      dernadd = addy;
-      delay(5);
-    }
-    if (g != vert) {
-      //      Serial.print("Vert = ");
-      //      Serial.println(g);
-      tiqueFade.attach_ms(40, fadeRGB);
-      dernadd = addy;
-      delay(5);
-    }
-    if (b != bleu) {
-      //      Serial.print("Bleu = ");
-      //      Serial.println(b);
-      tiqueFade.attach_ms(40, fadeRGB);
-      dernadd = addy;
-    }
-  }
-  String contenu = "<!DOCTYPE html>\n\n\n";
-  if (server.args()) { // recharge la page / pour permetre d'appuyer refresh sans re-poster la form
-    contenu += "<meta http-equiv=\"refresh\" content=\"0;url=/\" />\n";
-  }
-  contenu += "<meta charset=\"UTF-8\" />\n<title>Que la lumiere soit</title>\n"
-             "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
-  contenu += css;
-  contenu += "\n\n"
-             "
\n"
-             "<form action=\"/\" method=\"post\">\n"
-             "
Change la couleur de mon bureau:
"
-             "<input type=\"color\" name=\"COULEUR\" value=\"" + derncoul + "\">
\n"
-             "<input type=\"submit\" class=\"button1\" value=\"Changer\">\n"
-             "</form>\n
Dernier IP à avoir changé la couleur : ";
-  contenu += dernadd;
-  contenu += "
\n";
-  contenu += liens;
-  contenu += "
\n";
-  server.send(200, "text/html", contenu);
-}
-
-void handleReset() {
-  int ouireset = 0;
-  String addy = server.client().remoteIP().toString();
-  //  Serial.println("");
-  //  Serial.println(addy);
-  //  Serial.println("!!! RESET PAGE !!!");
-  String testteu = server.arg("RESET");
-  String passme = server.arg("PASSME");
-  if (testteu == "OUI") {
-    if (passme == resetpass) {
-      ouireset = 1;
-    } else {
-      ouireset = 2;
-    }
-  }
-  String contenu = "<!DOCTYPE html>\n\n\n";
-  contenu += "<meta charset=\"UTF-8\" />\n<title>Que la lumiere se RESET</title>\n"
-             "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
-  contenu += css;
-  contenu += "\n\n"
-             "
\n";
-  if (!ouireset) {
-    contenu += "<form action=\"/reset\" method=\"post\">\n"
-               "
Tu veux resetter le wifi network pour reconfigurer ?
"
-               "<input type=\"hidden\" name=\"RESET\" value=\"OUI\">
\n"
-               "<input type=\"password\" name=\"PASSME\" value=\"password\">
\n"
-               "<input type=\"submit\" class=\"button1\" value=\"Reset Wifi Network\">\n"
-               "</form>\n";
-  } else if (ouireset != 1) {
-    contenu += "<form action=\"/reset\" method=\"post\">\n"
-               "
Tu veux resetter le wifi network pour reconfigurer ?
"
-               "<input type=\"hidden\" name=\"RESET\" value=\"OUI\">
\n"
-               "<input type=\"password\" name=\"PASSME\" value=\"password\">
\n"
-               "
!!! MAUVAIS PASSWORD !!!

\n"
-               "<input type=\"submit\" class=\"button1\" value=\"Reset Wifi Network\">\n"
-               "</form>\n";
-    //    Serial.print("BAD PASSWORD : ");
-    //    Serial.println(passme);
-  } else if (ouireset == 1) {
-    contenu += "
Reset Dans 10 Secondes
\n";
-  }
-  contenu += "
Dernier IP à avoir changé la couleur :";
-  contenu += dernadd;
-  contenu += "\n
";
-  contenu += liens;
-  contenu += "\n

\n";
-  server.send(200, "text/html", contenu);
-  if (ouireset == 1) {
-    //    Serial.println("Reset dans 10 secondes");
-    delay(10000);
-    WiFiManager wifiManager;
-    wifiManager.resetSettings();
-    ESP.restart();
-  }
-}
-
-void handleNotFound() {
-  String addy = server.client().remoteIP().toString();
-  //  Serial.println("");
-  //  Serial.println(addy);
-  String htmlmessage = "<!DOCTYPE html>\n\n\n";
-  htmlmessage += "<meta charset=\"UTF-8\" />\n<title>404 Not found</title>\n"
-                 "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
-  htmlmessage += css;
-  htmlmessage += "\n\n"
-                 "
\n";
-  htmlmessage += "
404 File Not Found

\n";
-  htmlmessage += "URI: ";
-  htmlmessage += server.uri();
-  htmlmessage += "
\nMethod: ";
-  htmlmessage += (server.method() == HTTP_GET) ? "GET" : "POST";
-  htmlmessage += "
\nArguments: ";
-  htmlmessage += server.args();
-  htmlmessage += "
\n";
-  for (uint8_t i = 0; i < server.args(); i++) {
-    htmlmessage += " " + server.argName(i) + ": " + server.arg(i) + "
\n";
-  }
-  htmlmessage += "
\n";
-  htmlmessage += liens;
-  htmlmessage += "
\n
\n";
-  server.send(404, "text/html", htmlmessage);
-  String message = "404 File Not Found\n";
-  message += "URI: ";
-  message += server.uri();
-  message += "\nMethod: ";
-  message += (server.method() == HTTP_GET) ? "GET" : "POST";
-  message += "\nArguments: ";
-  message += server.args();
-  message += "\n";
-  for (uint8_t i = 0; i < server.args(); i++) {
-    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
-  }
-  //  Serial.print(message);
-}
-
-void updateTemp(String tempe) {
-  if (tempe != "-127.00") {
-    //    Serial.print("Sending temp : ");
-    //    Serial.println(tempe);
-    HTTPClient http;
-    String webadd = "http://api.thingspeak.com/update?key=";
-    webadd += thingkey;
-    webadd += "&field1=";
-    webadd += tempe;
-    http.begin(webadd);
-    int httpCode = http.GET();//Send the request
-    if (httpCode > 0) { //Check the returning code
-      String payload = http.getString();   //Get the request response payload
-      //      Serial.println(payload);                     //Print the response payload
-    }
-    http.end();   //Close connection
-  }
-}
-
-void latemp() {
-  sensors.requestTemperatures();
-  float thetemp = sensors.getTempCByIndex(0);// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
-  char buffer[10];
-  String tempF = dtostrf(thetemp, 5, 2, buffer);
-  updateTemp(tempF);
-}
-
-void handleTemp() {
-  sensors.requestTemperatures();
-  float latemp = sensors.getTempCByIndex(0);
-  while (latemp == -127.00) {
-    sensors.requestTemperatures();
-    latemp = sensors.getTempCByIndex(0);
-  }
-  String addy = server.client().remoteIP().toString();
-  //  Serial.println("");
-  //  Serial.println(addy);
-  //  Serial.print("Temperature : ");
-  //  Serial.println(latemp);
-  String contenu = "<!DOCTYPE html>\n\n\n";
-  contenu += "<meta charset=\"UTF-8\" />\n<title>Quel chaleur</title>\n"
-             "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
-  contenu += css;
-  contenu += "\n\n"
-             "
\n";
-  contenu += "<form action=\"/\" method=\"get\">\n"
-             "
Voici la temperature
"
-             "
";
-  contenu += latemp;
-  contenu += "°C

\n<input type=\"submit\" class=\"button1\" value=\"Go Home\">\n"
-             "</form>\n"
-             "
Dernier IP à avoir changé la couleur :";
-  contenu += dernadd;
-  contenu += "\n
";
-  contenu += liens;
-  contenu += "\n

\n";
-  server.send(200, "text/html", contenu);
-}
-
-void setup() {
-  analogWriteRange(255);
-  //  analogWriteFreq(500);
-  //  Serial.begin(9600);
-  pinMode(pinRouge, OUTPUT);
-  pinMode(pinVerte, OUTPUT);
-  pinMode(pinBleu, OUTPUT);
-  digitalWrite(pinRouge, LOW);
-  digitalWrite(pinBleu, LOW);
-  digitalWrite(pinVerte, LOW);
-  WiFiManager wifiManager;
-  wifiManager.autoConnect();
-  delay(500);
-  if (!MDNS.begin("esp8266")) {
-    //Serial.println("Error setting up MDNS responder!");
-    while (1) {
-      delay(1000);
-    }
-  }
-  server.on("/", handleRoot);
-  server.on("/reset", handleReset);
-  server.on("/temp", handleTemp);
-  server.on("/version", []() {
-    String addy = server.client().remoteIP().toString();
-    //Serial.println("");
-    //Serial.println(addy);
-    //Serial.println("Version request");
-    server.send(200, "text/html", "V1.7, Steve Olmstead sansillusion@gmail.com\n\n

"
-                "Added fader function\nRemoved connection watchdog (better have good signal)\n
"
-                "Removed mDns (did not work anyway)\n\n

"
-                "Added smoother fading\n\n

"
-                "Added AutoConect WifiManager !\n\n

"
-                "Added basic last IP logging\n
"
-                "Added /reset page to reset wifiManager connection settings\n\n

"
-                "Added /temp (temperature sensor read of ky-001)\n\n

"
-                "Added thingspeak support to send temperature each minute
\n\n
"
-                "Major rewrite for RGB led trip usin mosfet
\n"
-                "Removed serial to free resources for software pwm (still flikers but less than before)
\n" + liens);
-  });
-  server.onNotFound(handleNotFound);
-  server.begin();
-  //Serial.println("HTTP server started");
-  MDNS.addService("http", "tcp", 80);
-  sensors.begin();
-}
-
-void loop() {
-  server.handleClient();
-  unsigned long currentMillis = millis();
-  if (currentMillis - previousMillis >= interval) {
-    previousMillis = currentMillis;
-    latemp();
-  }
-}
-


Update to work with easy transfer and adjust mag

--- gps_arduino/gps_arduino.ino
+++ gps_arduino/gps_arduino.ino
@@ -14,10 +14,31 @@
 #include <Adafruit_L3GD20_U.h>
 #include <Adafruit_9DOF.h>
 #include <SabertoothSimplified.h>
+#include <EasyTransfer.h>

 //Optional second 4 line 20 char LCD for displaying data

 #include <LiquidCrystal_I2C.h>
+
+//START Easy Transfer
+EasyTransfer etData;
+struct COM_DATA_STRUCTURE{
+  //put your variable definitions here for the data you want to receive
+  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
+  int tar;
+  int cmd;
+  int val;
+  int dur;
+};
+
+//give a name to the group of data
+COM_DATA_STRUCTURE dataStruct;
+//END Easy Transfer
+
+//Motor speed -127 to 127
+#define SPEED 127
+#define TURN_SPEED 70
+

 #define I2C_ADDR 0x27  // Define I2C Address where the PCF8574A is
                           // Address can be changed by soldering A0, A1, or A2
@@ -50,7 +71,10 @@
 /* Update this with the correct SLP for accurate altitude measurements */
 float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;

+//Compass stuff
 float compassHeading;
+int mHeadingOffset = 0;
+#define HEADING_ADJUST_PIN A2

 // 2x16 LCD stuff
 LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
@@ -115,8 +139,9 @@
     lcd.setCursor(0,0);
     lcd.print("Starting..."); // print a simple message

-    //Set up diagnostic output
+    //Set up diagnostic outputs
     Serial.begin(9600);
+    etData.begin(details(dataStruct), &Serial);
     Serial.println("Starting ...");

     //Set gps
@@ -153,6 +178,10 @@
     updateHeading();
     updateDisplay(newData);

+    //Update heading offset
+    mHeadingOffset = analogRead(HEADING_ADJUST_PIN);            // reads the value of the potentiometer (value between 0 and 1023)
+    mHeadingOffset = map(mHeadingOffset, 0, 1023, 90, -90);     // scale it to use it with the heading (value between 0 and 180)
+
   }

   /**
@@ -190,6 +219,11 @@

     // Convert radians to degrees for readability.
     compassHeading = heading * 180/M_PI;
+    //Adjust heading
+    compassHeading += mHeadingOffset;
+    if(compassHeading >= 360){
+      compassHeading -= 360;
+    }
   }

   void updateDisplay(bool newData){
@@ -407,18 +441,39 @@
   }

  void forward(){
-   ST.motor(RIGHT, 100);
-   ST.motor(LEFT, 100);
+   //Send data
+    dataStruct.tar = 20;
+    dataStruct.val = SPEED;
+    etData.sendData();
+    dataStruct.tar = 21;
+    dataStruct.val = SPEED;
+    etData.sendData();
+   ST.motor(RIGHT, SPEED);
+   ST.motor(LEFT, SPEED);
  }

  void left(){
-   ST.motor(RIGHT, 45);
-   ST.motor(LEFT, 25);
+      //Send data
+    dataStruct.tar = 20;
+    dataStruct.val = SPEED;
+    etData.sendData();
+    dataStruct.tar = 21;
+    dataStruct.val = TURN_SPEED;
+    etData.sendData();
+   ST.motor(RIGHT, SPEED);
+   ST.motor(LEFT, TURN_SPEED);
  }

  void right(){
-   ST.motor(RIGHT, 25);
-   ST.motor(LEFT, 45);
+      //Send data
+    dataStruct.tar = 20;
+    dataStruct.val = TURN_SPEED;
+    etData.sendData();
+    dataStruct.tar = 21;
+    dataStruct.val = SPEED;
+    etData.sendData();
+   ST.motor(RIGHT, TURN_SPEED);
+   ST.motor(LEFT, SPEED);
  }

  float formatDistance(int meters){
@@ -512,6 +567,8 @@
     double arg2 = cos(currentLat)*sin(waypointLat)-sin(currentLat)*cos(waypointLat)*cos(waypointLon-currentLon);
     float heading = atan2(arg1, arg2);//,2*3.1415926535;
     heading = heading*180/3.1415926535;  // convert from radians to degrees
+    //Way points are backwards flip them 180
+    heading += 180;
     //if the heading is negative then add 360 to make it positive
     if(heading < 0){
       heading+=360;


power down only on normal mode mode

power down only on normal mode mode

--- vibrate_alarm_clock.ino
+++ vibrate_alarm_clock.ino
@@ -16,7 +16,7 @@

 #define DISPLAY_CONTRAST 64

-#define INITIAL_TEXT "Happy 24th birthday\n Jason!\n\nBy: Yeo Kheng Meng\n(2014)"
+#define INITIAL_TEXT "Happy 24th birthday\n Jason!\n\nBy: Yeo Kheng Meng\n(14 May 2014)"
 #define INITIAL_TEXT_DELAY 8000
 #define MIN_TIME_BETWEEN_BUTTON_PRESSES 100  //Debouncing purposes
 #define BLINK_INTERVAL 100
@@ -115,10 +115,12 @@
     display.display();
   }

-  LowPower.powerDown(SLEEP_30MS, ADC_OFF, BOD_OFF);
-
-}
-
+  if(currentState == NORMAL) {
+      LowPower.powerDown(SLEEP_30MS, ADC_OFF, BOD_OFF);
+  }
+
+}
+
 void processLeftButtonPressed(){
   unsigned long currentMillis = millis();


Fix extra space padding & simplify temp conversion

--- Attic_Controller/Attic_Controller.ino
+++ Attic_Controller/Attic_Controller.ino
@@ -67,10 +67,10 @@
   if (millis() > lastTempHumidSend + TEMP_HUMID_UPDATE_FREQUENCY) {

     char temp[8]; // Buffer big enough for 7-character float
-    dtostrf(getTemperature(), 6, 2, temp); // Leave room for too large numbers!
+    dtostrf(getTemperature(), -6, 2, temp); // Leave room for too large numbers!

     char humid[8];
-    dtostrf(getHumidity(), 6, 2, humid);
+    dtostrf(getHumidity(), -6, 2, humid);

     MQTT_Helper.publishMQTT("home/attic/controller/temp",  temp,  false);
     MQTT_Helper.publishMQTT("home/attic/controller/humid", humid, false);
@@ -143,13 +143,7 @@
 }

 float getTemperature() {
-  float tempC = dht.readTemperature();
-  float tempF = tempC * 9.0 / 5.0 + 32.0;
-
-  if (fahrenheit)
-    return tempF;
-  else
-    return tempC;
+  return dht.readTemperature(fahrenheit);
 }

 float getHumidity() {


v 1.0.0

v 1.0.0

--- Master.ino
+++ Master.ino
@@ -1,4 +1,5 @@
-// Yigit Suoglu, Musab Cevik, Onur Calik, Baran Dereli, Ozgun Sensoy Aug 1, 2016
+  // Yigit Suoglu, Musab Cevik, Onur Calik, Baran Dereli, Ozgun Sensoy Aug 3, 2016
+ // version 1.0.0
 // All codes combined

 #include <colorBit_Struct.h>


Fixed stop condition in getIndexOfLargestOpenInterval. findCylinder ready for test in robot.

--- Tests/Ping_findCylinder/Ping_findCylinder.ino
+++ Tests/Ping_findCylinder/Ping_findCylinder.ino
@@ -16,6 +16,7 @@
 long pingDist;
 int  measurements[stepsInFullTurn];
 int  noCylinder[stepsInFullTurn];
+int  stepsToCylinder;

 void setup() {
   // initialize serial communication:
@@ -29,9 +30,14 @@
 }

 void loop(){
-	measure();
+  measure();
   Serial.println(arrayToString(measurements,stepsInFullTurn));
-  delay(2000);
+  delay(1000);
+  stepsToCylinder = findCylinder();
+  for(int i=0; i<stepsToCylinder; i++){
+    rotateStep(counterClockwise);
+  }
+  delay(4000);
 }

 // Performs full turn and saves measurements to array
@@ -41,7 +47,7 @@
     rotateStep(counterClockwise);
     int m = measurePingDist();
     measurements[i] = m;
-    if(m < discardCylDist)
+    if(m > discardCylDist) // TODO Should be "m > discardCylDist"?
       noCylinder[i] = true;
   }
 }
@@ -172,7 +178,9 @@
   int lenLargest = 0;
   int iLeftLargest = 0;
   int iRightLargest = 0;
-  int startIndex = 0;
+  int nbrOfRightChecks = 0;
+  //int startIndex = 0; // TODO This variable was unused
+

   int iLeft;
   int iRight;
@@ -191,6 +199,7 @@
     while(measurements[iRight] < horizonDist){
       iRight = nextIndex(iRight,stepsInFullTurn);
       intervalWidth++;
+      nbrOfRightChecks++;
     }
     if(intervalWidth > lenLargest){
       lenLargest = intervalWidth;
@@ -199,6 +208,11 @@
     }

     i=iRight;
+
+    // When all points have been examined, continue!
+    if(nbrOfRightChecks > stepsInFullTurn){
+      break;
+    }
   }

   return iLeftLargest<iRightLargest ?


Add files via upload

Add files via upload

add altitude and speed to to insert into db

--- test_configSIM808.ino
+++ test_configSIM808.ino
@@ -35,6 +35,8 @@
 char north_south[2]="N";
 char longitude[11]="00000.00000";
 char east_west[2]="W";
+char MSL_altitude[8]="00000.0";
+char Speed[8]="000.000";
 /*char positionFix[2];
 char numSatelite[2];
 char hdop[5];
@@ -49,6 +51,7 @@
 //my variables MKY
 //const int BUFFER_SIZE = 110;
 const int BUFFER_SIZE = 90;
+//char infoLocation[BUFFER_SIZE];

 char buffer[20];                 // WHAT WE ARE READING INTO
 int posBuf;
@@ -214,30 +217,64 @@
 char infoLocation[BUFFER_SIZE];
 posBuf=0;
 int i = 0;
+
+  //Get position
   while(GPRS.available()){
     GPRS.read();
   }
-   GPRS.println("AT+CGPSINF=2");
-
-   //Read response of SIM808 at Serial Port, Uno buffer all data without other activities
-   //otherwise it may lose some bytes
-   //after send the command to GPS, it takes about 100ms to all serial information arrives UNO
-   delay(50);
-
-
-   //for(int i=0;i<7;i++){
-   while((posBuf<=99)&&(i<15)){
-     while((GPRS.available()>0)){
-        infoLocation[posBuf++]=GPRS.read();
-     }
-     delay(10);
-     i++;
-     //delay(15);
-   }
-
- GPSAnalyzer(infoLocation);
-
- SendGPSLocation();
+  GPRS.println("AT+CGPSINF=2");
+
+  //Read response of SIM808 at Serial Port, Uno buffer all data without other activities
+  //otherwise it may lose some bytes
+  //after send the command to GPS, it takes about 100ms to all serial information arrives UNO
+  delay(50);
+
+
+  //for(int i=0;i<7;i++){
+  while((posBuf<=99)&&(i<15)){
+    while((GPRS.available()>0)){
+      infoLocation[posBuf++]=GPRS.read();
+    }
+    delay(10);
+    i++;
+    //delay(15);
+  }
+  GPSAnalyzer(infoLocation);
+
+
+
+
+
+  //Get Speed
+  while(GPRS.available()){
+    GPRS.read();
+  }
+  GPRS.println("AT+CGPSINF=32");
+
+  //Read response of SIM808 at Serial Port, Uno buffer all data without other activities
+  //otherwise it may lose some bytes
+  //after send the command to GPS, it takes about 100ms to all serial information arrives UNO
+  delay(50);
+
+
+  posBuf=0;
+  i=0;
+  //for(int i=0;i<7;i++){
+  while((posBuf<=99)&&(i<15)){
+    while((GPRS.available()>0)){
+      infoLocation[posBuf++]=GPRS.read();
+    }
+    delay(10);
+    i++;
+    //delay(15);
+  }
+
+  GPSAnalyzer32(infoLocation);
+
+
+
+  //Send collected data to mysql server
+  SendGPSLocation();
 }

@@ -270,8 +307,12 @@
  ******************************************************************************************/

 void SendGPSLocation(){
-  //char data2db[]="410.869,111.222";
-  char data2db[21]="0000.0000,00000.0000";
+  //char latitude[10]="0000.0000";
+  //char longitude[11]="00000.00000";
+  //char MSL_altitude[8]="00000.0";
+  //char Speed[8]="000.000";
+  //char data2db[21]="0000.0000,00000.0000";  //"latitude,longitude"
+  char data2db[36]="0000.0000,00000.0000,00000.0,000.000"; //"latitude,longitude,MSL_altitude,Speed"

   //get the local ip number
   //GPRS.println("AT+CIFSR");
@@ -307,6 +348,17 @@
   strncpy(data2db,latitude,sizeof(latitude));
   strcat(data2db,",");
   strcat(data2db,longitude);
+
+  strcat(data2db,",");
+  strcat(data2db,MSL_altitude);
+
+  strcat(data2db,",");
+  strcat(data2db,Speed);
+
+  Serial.println("valor de data2db: ");
+  Serial.println(data2db);
+
+

   if(!SendDataCIPSEND(data2db,sizeof(data2db))){
     Serial.println("CIPSEND => FAIL");
@@ -346,6 +398,8 @@
  *************************************************************************************/
 boolean SendCIPSTART (Protocol ptl)
 {
+  //char bufferC[30];
+
   if(ptl == TCP) {
     if(!sim808_check_with_cmd("AT+CIPSTART=\"TCP\",\"ardugps.hopto.org\",6789\r\n","OK\r\n",CMD)){
       return false;
@@ -359,7 +413,15 @@
       if(!sim808_check_with_cmd("AT+CIPSTART=\"UDP\",\"ardugps.hopto.org\",6789\r\n","ERROR\r\n\r\nALREADY CONNECT\r\n",CMD)){
         return false;
       }
-      else {
+      else {
+
+        //void sim808_read_buffer(char *buffer, int count, unsigned int timeout, unsigned int chartimeout)
+        /*sim808_send_cmd("AT+CDNSGIP=\"ardugps.hopto.org\"\r\n");
+        sim808_read_buffer(bufferC,30,5,500);
+        Serial.println("Result of CDNSGIP");
+        Serial.println(bufferC);*/
+
+
         return true;
       }
     }
@@ -367,7 +429,10 @@
       return false;
     }
   }
-}
+
+
+}
+

 /*************************************************************************************
@@ -393,7 +458,7 @@
   delay(1000);
   sim808_send_End_Mark();
   if(!sim808_wait_for_resp("SEND OK\r\n", DATA, DEFAULT_TIMEOUT * 10, DEFAULT_INTERCHAR_TIMEOUT * 10)) {
-      return 0;
+    return 0;
   }
 }
 return len;
@@ -415,10 +480,11 @@
   }
 }

+
 /********************************************************************************
  * boolean GPSAnalyzer(char *gpsBuffer)
  * Analyze the Serial information received after request the information
- * AT+CCPSINF=2
+ * AT+CCPSINF=0
  * +CGPSINF: 2,050656.000,0030.2706,N,00120.1007,E,1,9,0.90,51.9,M,7.0,M,,
  * AT+CGPSINF=2, get GPS location with format
  * Message ID       = 2
@@ -434,8 +500,7 @@
  * Units            = M
  * Geoid Separation = xxx
  * Units            = M
- * +CGPSINF: 2,050656.000,0030.2706,N,00120.1007,E,1,9,0.90,51.9,M,7.0,M,,
- ********************************************************************************/
+  ********************************************************************************/
 boolean GPSAnalyzer(char *gpsBuffer) {
    char *token;

@@ -510,11 +575,133 @@
       east_west[sizeof(east_west)-1] = '\0';
       Serial.print("E/W INDICATOR   : ");
       Serial.println(east_west);
-      Serial.println("************************************************************ ");
+      //Serial.println("************************************************************ ");

-   }else return false;
+   }else return false;
+
+
+   //Skip Position Fix Indicator
+   token = strtok(NULL, ",");
+   if(token == NULL) {
+      return false;
+   }
+
+   //Skip Satellites Used
+   token = strtok(NULL, ",");
+   if(token == NULL) {
+      return false;
+   }
+
+   //Skip HDOP
+   token = strtok(NULL, ",");
+   if(token == NULL) {
+      return false;
+   }
+
+   //Get MSL Altitude
+   token = strtok(NULL, ",");
+   if(token != NULL) {
+      strncpy(MSL_altitude,token,sizeof(MSL_altitude));
+      MSL_altitude[sizeof(MSL_altitude)-1] = '\0';
+      Serial.print("MSL altitude   : ");
+      Serial.println(MSL_altitude);
+      //Serial.println("************************************************************ ");
+
+   }else return false;

    return true;
-}
+}
+
+/********************************************************************************
+* GPSAnalyzer32(infoLocation);
+* GPRMC
+* AT+CGPSINF=32
+* +CGPSINF: 32,032432.000,A,3016.2261,N,12006.0382,E,0.185,116.11,131017,,,A
+* Message ID          : $GPRMC = 32 (RMC protocol header)
+* UTC Time            : hhmmss.sss
+* Status              : A = data valid or V = data not valid
+* Latitude            : ddmm.mmmmmm
+* N/S Indicator       : N/S
+* Longitude           : dddmm.mmmmmm
+* E/W Indicator       : E/W
+* Speed Over Ground   : knots
+* Course Over Ground  : degrees (TRUE)
+* Date                : ddmmyy
+* Magnetic Variation  : degrees (E/W)
+* East/West Indicator : E/W
+* Mode                : A = Autonomous
+*                       D = DGPS
+*                       E = DR
+*                       N = Output Data Not Valid
+*                       R = Coarse Position
+********************************************************************************/
+boolean GPSAnalyzer32(char *gpsBuffer) {
+   char *token;
+   byte i=0;
+   float Speedkmh;
+   /* get the first token */
+   //Serial.println("****************Content of gpsBuffer*******************");
+   //Serial.println("valor do buffer :");
+   //Serial.println(gpsBuffer);
+
+   //Get Command sent
+   token = strtok(gpsBuffer,"\n\r" );
+   if(token == NULL)  return false;
+
+   //Get "+CGPSINF:" string
+   token = strtok(NULL, ":");
+   if(token == NULL)  return false;
+
+   //Get CGPSINF value
+   token = strtok(NULL, ",");
+
+   while (i<8) {
+     if((token != NULL) && (i==7)){
+       strncpy(Speed,token,sizeof(Speed)); //Speed in Knot
+       Speed[sizeof(Speed)-1] = '\0';
+       Serial.print("SPEED  KNOT      : ");
+       Serial.println(Speed);
+
+       Speedkmh = atof(Speed);
+       Speedkmh = Speedkmh*1.852;
+       dtostrf(Speedkmh,3,3,Speed);
+
+       Serial.print("SPEED  KMH       : ");
+       Serial.println(Speed);
+
+       return true;
+     }else {
+       if (token == NULL){
+         return false;
+       }else{
+        token = strtok(NULL, ",");
+        i++;
+       }
+     }
+   }
+}
+
+
+
+
+/********************************************************************************
+* GPVTG
+* AT+CGPSINF=64
+* +CGPSINF: 64,299.79,T,,M,0.072,N,0.133,K,A
+* Message ID    : $CPVTG = 64
+* Course        : degrees
+* Reference     : TRUE
+* Course        : degrees (Measured heading)
+* Reference     : M (Magnetc)
+* Speed         : knots (Measured horizontal speed)
+* Units         : N (Knots)
+* Speed         : Km/h (Measured horizontal speed)
+* Units         : Kilometers/h
+* Mode          : A = Autonomous
+*                 D = DGPS
+*                 E = DR
+*                 N = Output Data Not Valid
+*                 R = Coarse Position
+********************************************************************************/


Faster update message.

Faster update message.

--- firmware/sentry.ino
+++ firmware/sentry.ino
@@ -215,7 +215,7 @@
   lcd.print("Has");
   lcd.print(numCards);
   lcd.print(" cards.");
-  delay(2000);
+  delay(500);

   resetLCD();
 }


current only test

current only test

--- _49-emontxv2-esp-01-i2c/emontxv2/emontxv2.ino
+++ _49-emontxv2-esp-01-i2c/emontxv2/emontxv2.ino
@@ -3,7 +3,6 @@
 // https://github.com/Makuna/Rtc
 #include <RtcDS1307.h>
 #include "PinChangeInterrupt.h"
-#include "EmonLib.h"

 /*
   atmega328  -  esp - ds1307
@@ -44,9 +43,11 @@

 data sensor_data;

-const int CT2 = 1;
-const int CT3 = 1;
-
+const int CT1 = 1;
+const int CT2 = 1;
+const int CT3 = 1;
+
+#include "EmonLib.h"
 EnergyMonitor ct1, ct2, ct3;

 RtcDS1307 Rtc;
@@ -124,14 +125,18 @@
 }

 void start_measure() {
-  ct1.calcVI(20, 2000);
-  ct2.calcVI(20, 2000);
-  ct3.calcVI(20, 2000);
-
-  sensor_data.ct1_wh == ct1.realPower;
-  sensor_data.ct2_wh == ct2.realPower;
-  sensor_data.ct3_wh == ct3.realPower;
-  sensor_data.ct1_vr = ct1.Vrms * 100 ;
+
+  if (CT1) {
+    sensor_data.ct1_wh = ct1.calcIrms(1480) * 220.0;                         //ct.calcIrms(number of wavelengths sample)*AC RMS voltage
+  }
+
+  if (CT2) {
+    sensor_data.ct2_wh = ct2.calcIrms(1480) * 220.0;
+  }
+
+  if (CT3) {
+    sensor_data.ct3_wh = ct3.calcIrms(1480) * 220.0;
+  }

   sensor_data._salt++;

@@ -169,6 +174,11 @@
 }

 void setup() {
+
+  if (CT1) ct1.currentTX(1, 111.1);                                     // Setup emonTX CT channel (ADC input, calibration)
+  if (CT2) ct2.currentTX(2, 111.1);                                     // Calibration factor = CT ratio / burden resistance
+  if (CT3) ct3.currentTX(3, 111.1);                                     // Calibration factor = (100A / 0.05A) / 33 Ohms
+
   wdt_enable(WDTO_8S);

   // bool
@@ -202,6 +212,7 @@
   sensor_data.ct1_wh = 3;
   sensor_data.ct2_wh = 4;
   sensor_data.ct3_wh = 5;
+  sensor_data.ct1_vr = 0;
   sensor_data.door   = bdoor_now = digitalRead(DOOR_LOCK_PIN);
   sensor_data.pad1   = uint8_t(sensor_data.pls_wh + sensor_data.ct1_wh + sensor_data.ct2_wh + sensor_data.ct3_wh + sensor_data.door);

@@ -209,13 +220,6 @@
   Rtc.Begin();
   Rtc.SetIsRunning(true);
   Rtc.SetSquareWavePin(DS1307SquareWaveOut_1Hz);
-
-  ct1.voltageTX(236.2, 1.7);
-  ct1.currentTX(1, 111.1);
-  ct2.voltageTX(234.26, 1.7);
-  ct2.currentTX(2, 111.1);
-  ct3.voltageTX(234.26, 1.7);
-  ct3.currentTX(3, 111.1);

   // interrupt
   attachInterrupt(digitalPinToInterrupt(SQW_PIN), sqw_isr, FALLING);               //  int 0


http routes setup except for /reset

http routes setup except for /reset

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -8,15 +8,15 @@
  calls through the browser.

  Possible commands created in this shetch:
-
+
  * /arduino/start
  * /arduino/stop
  * /arduino/ping
- * /arduino/reset
+ * /arduino/reset
  * /arduino/state
- * /arduino/time/:val
+ * /arduino/time/:val
  * /arduino/temp/:val
-
+
  This example code is part of the public domain

  http://arduino.cc/en/Tutorial/Bridge
@@ -41,7 +41,7 @@

 struct HttpCommand {
   char* cmd;
-  void (*func)(YunClient);
+  void (*func)(YunClient&);
 };

 void eventCallback(StatusEvent event);
@@ -51,50 +51,50 @@
  * /arduino/start
  * /arduino/stop
  * /arduino/ping
- * /arduino/reset
+ * /arduino/reset
  * /arduino/state
- * /arduino/time/:val
+ * /arduino/time/:val
  * /arduino/temp/:val
  */
-void handle_state(YunClient client);
-void handle_ping(YunClient client);
-void handle_start(YunClient client);
-void handle_stop(YunClient client);
-void handle_reset(YunClient client);
-void handle_set_time(YunClient client);
-void handle_set_temp(YunClient client);
+void handle_state(YunClient& client);
+void handle_ping(YunClient& client);
+void handle_start(YunClient& client);
+void handle_stop(YunClient& client);
+void handle_reset(YunClient& client);
+void handle_set_time(YunClient& client);
+void handle_set_temp(YunClient& client);

 static struct HttpCommand http_endpoints[] = {
-  {"state",handle_state},
-  {"ping",handle_ping},
-  {"start",handle_start},
-  {"stop",handle_stop},
-  {"reset",handle_reset},
-  {"time",handle_set_time},
-  {"temp",handle_set_temp},
-  {0,0}
+  {"state", handle_state},
+  {"ping", handle_ping},
+  {"start", handle_start},
+  {"stop", handle_stop},
+  {"reset", handle_reset},
+  {"time", handle_set_time},
+  {"temp", handle_set_temp},
+  {0, 0}
 };

-SlowCooker slowcooker(HEATER_IO,TEMP_SENSOR_PIN,LID_SWITCH,&eventCallback);
+SlowCooker slowcooker(HEATER_IO, TEMP_SENSOR_PIN, LID_SWITCH, &eventCallback);

 // Listen on default port 5555, the webserver on the Yun
 // will forward there all the HTTP requests for us.
 YunServer server;

 void setup() {
-
+
   Serial.begin(115200);
   Serial.println(F("Initializing..."));
   //setup slowcooker
   slowcooker.setup();
-
+
   Bridge.begin();
-
+
   // Listen for incoming connection only from localhost
   // (no one from the external network could connect)
   server.listenOnLocalhost();
   server.begin();
-
+
   sendEvent(EVENT_POWERED_ON);
   Serial.println(F("Starting main loop."));
 }
@@ -102,7 +102,7 @@
 void loop() {
   // handle slow cooker functions.
   slowcooker.loop();
-
+
   // Get clients coming from server
   YunClient client = server.accept();

@@ -117,24 +117,34 @@
   delay(50); // Poll every 50ms
 }

-void process(YunClient client) {
+void process(YunClient& client) {
   // read the command
   String command = client.readStringUntil('/');
-
-  int i=0;
-  while(1){
-    if(http_endpoints[i].cmd == 0)
-      break;
-
-    if(command == http_endpoints[i].cmd){
+
+  // handle /state with no trailing /
+  if (command[command.length() - 2] == 0xD && command[command.length() - 1] == 0xA) {
+    command = command.substring(0, command.length() - 2);
+  }
+
+  int i = 0;
+  while (1) {
+    if (http_endpoints[i].cmd == 0)
+      break;
+
+    if (command.equals(http_endpoints[i].cmd)) {
       http_endpoints[i].func(client);
       return;
     }
-  }
-}
-
-void eventCallback(StatusEvent event){
-  switch(event){
+
+    i++;
+  }
+  client.println(F("Status: 404"));
+  client.println();
+  client.println(F("{\"error\":\"Command not found.\"}"));
+}
+
+void eventCallback(StatusEvent event) {
+  switch (event) {
     case EVENT_LID_OPENED:
       Serial.println("EVENT: LID Openned.");
       sendEvent(EVENT_LID_OPENED);
@@ -151,11 +161,12 @@
 }

-void sendEvent(StatusEvent event){
-
-}
-
-void handle_state(YunClient client){
+void sendEvent(StatusEvent event) {
+
+}
+
+void handle_state(YunClient& client) {
+  Serial.println(F("Handle state"));
   client.print(F("{\"cookTime\":"));
   client.print(slowcooker.CookTime());
   client.print(F(",\"cookTimeLeft\":"));
@@ -173,44 +184,63 @@
   client.println(F("}"));
 }

-void handle_ping(YunClient client){
-  client.println(F("{}"));
-}
-
-void handle_start(YunClient client){
-  client.println(F("{}"));
-}
-
-void handle_stop(YunClient client){
-  client.println(F("{}"));
-}
-
-void handle_reset(YunClient client){
-  client.println(F("{}"));
-}
-
-void handle_set_time(YunClient client){
-    int time = client.parseInt();
-    if(!slowcooker.setCookTime(time)){
-      client.println(F("{\"error\":\"Failed to set cook time.\"}"));
-      return;
-    }
-
-    client.print(F("{\"time\":"));
-    client.print(time);
-    client.println(F("}"));
-}
-
-void handle_set_temp(YunClient client){
-    int temp = client.parseInt();
-    if(!slowcooker.setCookTemp(temp)){
-      client.println(F("{\"error\":\"Failed to set cook temp.\"}"));
-      return;
-    }
-
-    client.print(F("{\"temp\":"));
-    client.print(temp);
-    client.println(F("}"));
-}
-
-
+void handle_ping(YunClient& client) {
+  client.println(F("{}"));
+}
+
+void handle_start(YunClient& client) {
+  slowcooker.startCook();
+  client.println(F("{}"));
+}
+
+void handle_stop(YunClient& client) {
+  slowcooker.stopCook();
+  client.println(F("{}"));
+}
+
+void handle_reset(YunClient& client) {
+  client.println(F("{}"));
+}
+
+void handle_set_time(YunClient& client) {
+  if(client.available() == 0){
+    client.println(F("Status: 400"));
+    client.println();
+    client.println(F("{\"error\":\"Must supply a time value.\"}"));
+    return;
+  }
+
+  int time = client.parseInt();
+  if (!slowcooker.setCookTime(time)) {
+    client.println(F("Status: 400"));
+    client.println();
+    client.println(F("{\"error\":\"Failed to set cook time.\"}"));
+    return;
+  }
+
+  client.print(F("{\"time\":"));
+  client.print(time);
+  client.println(F("}"));
+}
+
+void handle_set_temp(YunClient& client) {
+  if(client.available() == 0){
+    client.println(F("Status: 400"));
+    client.println();
+    client.println(F("{\"error\":\"Must supply a temp value.\"}"));
+    return;
+  }
+
+  int temp = client.parseInt();
+  if (!slowcooker.setCookTemp(temp)) {
+    client.println(F("Status: 400"));
+    client.println();
+    client.println(F("{\"error\":\"Failed to set cook temp.\"}"));
+    return;
+  }
+
+  client.print(F("{\"temp\":"));
+  client.print(temp);
+  client.println(F("}"));
+}
+