cleanup

cleanup

--- hal100/hal100.ino
+++ hal100/hal100.ino
@@ -282,181 +282,6 @@
   TFTscreen.text(DisplayValueSWR, 40, 5);
 }

-void displayLSteps() {                                         // display L steps values
-  dtostrf(valueRotateL, 5, 0, DisplayValueL);
-  if (isBusy) {
-    TFTscreen.stroke(255, 255, 0);
-  } else {
-    TFTscreen.stroke(0, 255, 0);
-  }
-  TFTscreen.setTextSize(1);
-  TFTscreen.text(DisplayValueL, 55, 42);
-}
-
-void EraseDisplayLSteps() {                                   // erase display L steps values
-  TFTscreen.stroke(0, 20, 30);
-  TFTscreen.setTextSize(1);
-  TFTscreen.text(DisplayValueL, 55, 42);
-}
-
-void displayValueLuH() {                                         // display L values in uH
-  dtostrf(stepsToMh(valueRotateL), 4, 2, DisplayValueLUH);
-  if (isBusy) {
-    TFTscreen.stroke(255, 255, 0);
-  } else {
-    TFTscreen.stroke(0, 255, 0);
-  }
-  TFTscreen.setTextSize(2);
-  TFTscreen.text(DisplayValueLUH, 40, 25);
-}
-
-void ErasDisplayValueLuH() {                                   // erase display L values in uH
-  TFTscreen.stroke(0, 20, 30);
-  TFTscreen.setTextSize(2);
-  TFTscreen.text(DisplayValueLUH, 40, 25);
-}
-
-void displayL() {                                             // display L steps and uH
-  displayLSteps();
-  displayValueLuH();
-}
-
-void EraseDisplayL() {                                        // erase L steps and uH
-  EraseDisplayLSteps();
-  ErasDisplayValueLuH();
-}
-
- double stepsC1topF(double x) {
-   return  3.5215908593183684e+002 * pow(x,0)
-        + -1.6245967367326516e-001 * pow(x,1)
-        + -8.9757122524750620e-004 * pow(x,2)
-        +  5.3372752892602197e-006 * pow(x,3)
-        + -1.7696527557016530e-008 * pow(x,4)
-        +  3.3363571963309934e-011 * pow(x,5)
-        + -3.6438105893235793e-014 * pow(x,6)
-        +  2.2733846666230038e-017 * pow(x,7)
-        + -7.5016703085658784e-021 * pow(x,8)
-        +  1.0154127876671653e-024 * pow(x,9);
-}
-
-void displayC1steps() {                                       // display C1 steps values
-  dtostrf(valueRotateC1, 5, 0, DisplayValueC1);
-  if (isBusy) {
-    TFTscreen.stroke(255, 255, 0);
-  } else {
-    TFTscreen.stroke(0, 255, 0);
-  }
-  TFTscreen.setTextSize(1);
-  TFTscreen.text(DisplayValueC1, 55, 72);
-}
-
-void EraseDisplayC1steps() {                                   // erase display C1 steps values
-  TFTscreen.stroke(0, 20, 20);
-  TFTscreen.setTextSize(1);
-  TFTscreen.text(DisplayValueC1, 55, 72);
-}
-
-void displayValueC1pF() {                                         // display C1 values in pF
-  dtostrf(stepsC1topF(valueRotateC1), 4, 1, DisplayValueC1pF);
-  if (isBusy) {
-    TFTscreen.stroke(255, 255, 0);
-  } else {
-    TFTscreen.stroke(0, 255, 0);
-  }
-  TFTscreen.setTextSize(2);
-  TFTscreen.text(DisplayValueC1pF, 40, 55);
-}
-
-void ErasDisplayValueC1pF() {                                   // erase display C1 values in pF
-  TFTscreen.stroke(0, 20, 30);
-  TFTscreen.setTextSize(2);
-  TFTscreen.text(DisplayValueC1pF, 40, 55);
-}
-
-void displayC1() {                                             // display C1 values
-  displayC1steps();
-  displayValueC1pF();
-}
-
-void EraseDisplayC1() {                                        // erase C1 values
-  EraseDisplayC1steps();
-  ErasDisplayValueC1pF();
-}
-
- double stepsC2topF(double x) {
-   return  3.5215908593183684e+002 * pow(x,0)
-        + -1.6245967367326516e-001 * pow(x,1)
-        + -8.9757122524750620e-004 * pow(x,2)
-        +  5.3372752892602197e-006 * pow(x,3)
-        + -1.7696527557016530e-008 * pow(x,4)
-        +  3.3363571963309934e-011 * pow(x,5)
-        + -3.6438105893235793e-014 * pow(x,6)
-        +  2.2733846666230038e-017 * pow(x,7)
-        + -7.5016703085658784e-021 * pow(x,8)
-        +  1.0154127876671653e-024 * pow(x,9);
-}
-
-void displayC2steps() {                                       // display C2 steps values
-  dtostrf(valueRotateC2, 5, 0, DisplayValueC2);
-  if (isBusy) {
-    TFTscreen.stroke(255, 255, 0);
-  } else {
-    TFTscreen.stroke(0, 255, 0);
-  }
-  TFTscreen.setTextSize(1);
-  TFTscreen.text(DisplayValueC2, 55, 102);
-}
-
-void EraseDisplayC2steps() {                                   // erase display C2 steps values
-  TFTscreen.stroke(0, 20, 20);
-  TFTscreen.setTextSize(1);
-  TFTscreen.text(DisplayValueC2, 55, 102);
-}
-
-void displayValueC2pF() {                                         // display C2 values in pF
-  dtostrf(stepsC2topF(valueRotateC2), 4, 1, DisplayValueC2pF);
-  if (isBusy) {
-    TFTscreen.stroke(255, 255, 0);
-  } else {
-    TFTscreen.stroke(0, 255, 0);
-  }
-  TFTscreen.setTextSize(2);
-  TFTscreen.text(DisplayValueC2pF, 40, 85);
-}
-
-void ErasDisplayValueC2pF() {                                   // erase display C1 values in pF
-  TFTscreen.stroke(0, 20, 30);
-  TFTscreen.setTextSize(2);
-  TFTscreen.text(DisplayValueC2pF, 40, 85);
-}
-
-void displayC2() {                                             // display C1 values
-  displayC2steps();
-  displayValueC2pF();
-}
-
-void EraseDisplayC2() {                                        // erase C1 values
-  EraseDisplayC2steps();
-  ErasDisplayValueC2pF();
-}
-
-
-//void displayC2() {                                       // display C2 steps values
-//  dtostrf(valueRotateC2, 5, 0, DisplayValueC2);
-//  if (isBusy) {
-//    TFTscreen.stroke(255, 255, 0);
-//  } else {
-//    TFTscreen.stroke(0, 255, 0);
-//  }
-//  TFTscreen.setTextSize(2);
-//  TFTscreen.text(DisplayValueC2, 40, 85);
-//}
-
-//void EraseDisplayC2() {                                   // erase display C2 steps values
-//  TFTscreen.stroke(0, 20, 20);
-//  TFTscreen.setTextSize(2);
-//  TFTscreen.text(DisplayValueC2, 40, 85);
-//}

 double stepsToMh(float x) {
   return  3.2408606623203362e-001 * pow(x, 0)
@@ -474,7 +299,181 @@
           +  9.4929814793314678e-054 * pow(x, 12);
 }

-
+void displayLSteps() {                                         // display L steps values
+  dtostrf(valueRotateL, 5, 0, DisplayValueL);
+  if (isBusy) {
+    TFTscreen.stroke(255, 255, 0);
+  } else {
+    TFTscreen.stroke(0, 255, 0);
+  }
+  TFTscreen.setTextSize(1);
+  TFTscreen.text(DisplayValueL, 55, 42);
+}
+
+void EraseDisplayLSteps() {                                   // erase display L steps values
+  TFTscreen.stroke(0, 20, 30);
+  TFTscreen.setTextSize(1);
+  TFTscreen.text(DisplayValueL, 55, 42);
+}
+
+void displayValueLuH() {                                         // display L values in uH
+  dtostrf(stepsToMh(valueRotateL), 4, 2, DisplayValueLUH);
+  if (isBusy) {
+    TFTscreen.stroke(255, 255, 0);
+  } else {
+    TFTscreen.stroke(0, 255, 0);
+  }
+  TFTscreen.setTextSize(2);
+  TFTscreen.text(DisplayValueLUH, 40, 25);
+}
+
+void ErasDisplayValueLuH() {                                   // erase display L values in uH
+  TFTscreen.stroke(0, 20, 30);
+  TFTscreen.setTextSize(2);
+  TFTscreen.text(DisplayValueLUH, 40, 25);
+}
+
+void displayL() {                                             // display L steps and uH
+  displayLSteps();
+  displayValueLuH();
+}
+
+void EraseDisplayL() {                                        // erase L steps and uH
+  EraseDisplayLSteps();
+  ErasDisplayValueLuH();
+}
+
+double stepsC1topF(double x) {
+  return  3.5215908593183684e+002 * pow(x, 0)
+          + -1.6245967367326516e-001 * pow(x, 1)
+          + -8.9757122524750620e-004 * pow(x, 2)
+          +  5.3372752892602197e-006 * pow(x, 3)
+          + -1.7696527557016530e-008 * pow(x, 4)
+          +  3.3363571963309934e-011 * pow(x, 5)
+          + -3.6438105893235793e-014 * pow(x, 6)
+          +  2.2733846666230038e-017 * pow(x, 7)
+          + -7.5016703085658784e-021 * pow(x, 8)
+          +  1.0154127876671653e-024 * pow(x, 9);
+}
+
+void displayC1steps() {                                       // display C1 steps values
+  dtostrf(valueRotateC1, 5, 0, DisplayValueC1);
+  if (isBusy) {
+    TFTscreen.stroke(255, 255, 0);
+  } else {
+    TFTscreen.stroke(0, 255, 0);
+  }
+  TFTscreen.setTextSize(1);
+  TFTscreen.text(DisplayValueC1, 55, 72);
+}
+
+void EraseDisplayC1steps() {                                   // erase display C1 steps values
+  TFTscreen.stroke(0, 20, 20);
+  TFTscreen.setTextSize(1);
+  TFTscreen.text(DisplayValueC1, 55, 72);
+}
+
+void displayValueC1pF() {                                         // display C1 values in pF
+  dtostrf(stepsC1topF(valueRotateC1), 4, 1, DisplayValueC1pF);
+  if (isBusy) {
+    TFTscreen.stroke(255, 255, 0);
+  } else {
+    TFTscreen.stroke(0, 255, 0);
+  }
+  TFTscreen.setTextSize(2);
+  TFTscreen.text(DisplayValueC1pF, 40, 55);
+}
+
+void ErasDisplayValueC1pF() {                                   // erase display C1 values in pF
+  TFTscreen.stroke(0, 20, 30);
+  TFTscreen.setTextSize(2);
+  TFTscreen.text(DisplayValueC1pF, 40, 55);
+}
+
+void displayC1() {                                             // display C1 values
+  displayC1steps();
+  displayValueC1pF();
+}
+
+void EraseDisplayC1() {                                        // erase C1 values
+  EraseDisplayC1steps();
+  ErasDisplayValueC1pF();
+}
+
+double stepsC2topF(double x) {
+  return  3.5215908593183684e+002 * pow(x, 0)
+          + -1.6245967367326516e-001 * pow(x, 1)
+          + -8.9757122524750620e-004 * pow(x, 2)
+          +  5.3372752892602197e-006 * pow(x, 3)
+          + -1.7696527557016530e-008 * pow(x, 4)
+          +  3.3363571963309934e-011 * pow(x, 5)
+          + -3.6438105893235793e-014 * pow(x, 6)
+          +  2.2733846666230038e-017 * pow(x, 7)
+          + -7.5016703085658784e-021 * pow(x, 8)
+          +  1.0154127876671653e-024 * pow(x, 9);
+}
+
+void displayC2steps() {                                       // display C2 steps values
+  dtostrf(valueRotateC2, 5, 0, DisplayValueC2);
+  if (isBusy) {
+    TFTscreen.stroke(255, 255, 0);
+  } else {
+    TFTscreen.stroke(0, 255, 0);
+  }
+  TFTscreen.setTextSize(1);
+  TFTscreen.text(DisplayValueC2, 55, 102);
+}
+
+void EraseDisplayC2steps() {                                   // erase display C2 steps values
+  TFTscreen.stroke(0, 20, 20);
+  TFTscreen.setTextSize(1);
+  TFTscreen.text(DisplayValueC2, 55, 102);
+}
+
+void displayValueC2pF() {                                         // display C2 values in pF
+  dtostrf(stepsC2topF(valueRotateC2), 4, 1, DisplayValueC2pF);
+  if (isBusy) {
+    TFTscreen.stroke(255, 255, 0);
+  } else {
+    TFTscreen.stroke(0, 255, 0);
+  }
+  TFTscreen.setTextSize(2);
+  TFTscreen.text(DisplayValueC2pF, 40, 85);
+}
+
+void ErasDisplayValueC2pF() {                                   // erase display C1 values in pF
+  TFTscreen.stroke(0, 20, 30);
+  TFTscreen.setTextSize(2);
+  TFTscreen.text(DisplayValueC2pF, 40, 85);
+}
+
+void displayC2() {                                             // display C1 values
+  displayC2steps();
+  displayValueC2pF();
+}
+
+void EraseDisplayC2() {                                        // erase C1 values
+  EraseDisplayC2steps();
+  ErasDisplayValueC2pF();
+}
+
+
+//void displayC2() {                                       // display C2 steps values
+//  dtostrf(valueRotateC2, 5, 0, DisplayValueC2);
+//  if (isBusy) {
+//    TFTscreen.stroke(255, 255, 0);
+//  } else {
+//    TFTscreen.stroke(0, 255, 0);
+//  }
+//  TFTscreen.setTextSize(2);
+//  TFTscreen.text(DisplayValueC2, 40, 85);
+//}
+
+//void EraseDisplayC2() {                                   // erase display C2 steps values
+//  TFTscreen.stroke(0, 20, 20);
+//  TFTscreen.setTextSize(2);
+//  TFTscreen.text(DisplayValueC2, 40, 85);
+//}

 //void eraseFrequency() {                         // when * pressed - erases entered frequency bottom of the screen
 //  EnteredFreqString = "";
@@ -589,9 +588,9 @@
         case 'U':                           // "L" motor move 100 step CW
           incL(+10.0);
           break;
-///        case '*':                           // erase entered frequency
-//          eraseFrequency();
-//          break;
+        ///        case '*':                           // erase entered frequency
+        //          eraseFrequency();
+        //          break;
         case 'S':                           // erase entered frequency
           mechAutoTune();
           break;


remove errored includes that aren't needed for ESP32

--- arduino/ws2812_controller_esp32/ws2812_controller_esp32.ino
+++ arduino/ws2812_controller_esp32/ws2812_controller_esp32.ino
@@ -4,7 +4,6 @@
 */
 #include <Arduino.h>
 #include <WiFi.h>
-#include <Hash.h>
 #include <WiFiUdp.h>
 #include <NeoPixelBus.h>


Forgot to change a small thing

Forgot to change a small thing


Update 7 segment example to uncomment floating point usage.

--- examples/sevenseg/sevenseg.ino
+++ examples/sevenseg/sevenseg.ino
@@ -50,11 +50,9 @@
   delay(500);

   // print a floating point
-  /* this isnt working yet, still hacking on it!
   matrix.print(12.34);
   matrix.writeDisplay();
   delay(500);
-  */

   // print with print/println
   for (uint16_t counter = 0; counter < 9999; counter++) {


6 nets for sorenson

6 nets for sorenson

--- examples/sorenson/sorenson.ino
+++ examples/sorenson/sorenson.ino
@@ -23,21 +23,25 @@
 LEDStrip strip2 = LEDStrip(150);
 LEDStrip strip3 = LEDStrip(150);
 LEDStrip strip4 = LEDStrip(150);
+LEDStrip strip5 = LEDStrip(150);
+LEDStrip strip6 = LEDStrip(150);

 // Triangles strips, group of 3 triangles, split in hardware to make 3 groups
-LEDStrip strip5 = LEDStrip(165);
+LEDStrip strip7 = LEDStrip(165);

 // Curtain LEDs
 LEDs leds1 = LEDs(&strip1, 0, 150);
 LEDs leds2 = LEDs(&strip2, 0, 150);
 LEDs leds3 = LEDs(&strip3, 0, 150);
 LEDs leds4 = LEDs(&strip4, 0, 150);
+LEDs leds5 = LEDs(&strip5, 0, 150);
+LEDs leds6 = LEDs(&strip6, 0, 150);

 // Inner triangles
 int inner_starts[] = {37, 0, 19};
 int inner_lengths[] = {18, 19, 18};

-LEDStrip* strips5[] = {&strip5, &strip5, &strip5};
+LEDStrip* strips7[] = {&strip7, &strip7, &strip7};

 // Outer triangles
 int outer1_starts[] = {92, 55, 74};
@@ -46,21 +50,23 @@
 int outer2_starts[] = {129, 147, 110};
 int outer2_lengths[] = {18, 18, 19};

-LEDs leds5 = LEDs(3, strips5, inner_starts, inner_lengths);
-LEDs leds6 = LEDs(3, strips5, outer1_starts, outer1_lengths);
-LEDs leds7 = LEDs(3, strips5, outer2_starts, outer2_lengths);
-
-LEDs* inner_leds[] = {&leds5};
-LEDs* outer_leds[] = {&leds6, &leds7};
+LEDs leds7 = LEDs(3, strips7, inner_starts, inner_lengths);
+LEDs leds8 = LEDs(3, strips7, outer1_starts, outer1_lengths);
+LEDs leds9 = LEDs(3, strips7, outer2_starts, outer2_lengths);
+
+LEDs* inner_leds[] = {&leds7};
+LEDs* outer_leds[] = {&leds8, &leds9};

 Visualization* viz;
 CurtainAnimation* anim1;
 CurtainAnimation* anim2;
 CurtainAnimation* anim3;
 CurtainAnimation* anim4;
-
-TriangleAnimation* anim5;
-TriangleAnimation* anim6;
+CurtainAnimation* anim5;
+CurtainAnimation* anim6;
+
+TriangleAnimation* anim7;
+TriangleAnimation* anim8;

 // Audio shield setup
 AudioInputI2S audio;
@@ -91,9 +97,11 @@
   anim2 = new CurtainAnimation(viz, leds2);
   anim3 = new CurtainAnimation(viz, leds3);
   anim4 = new CurtainAnimation(viz, leds4);
-
-  anim5 = new TriangleAnimation(viz, inner_leds, 1);
-  anim6 = new TriangleAnimation(viz, outer_leds, 2);
+  anim5 = new CurtainAnimation(viz, leds5);
+  anim6 = new CurtainAnimation(viz, leds6);
+
+  anim7 = new TriangleAnimation(viz, inner_leds, 1);
+  anim8 = new TriangleAnimation(viz, outer_leds, 2);

   // Far right curtain
   anim1->init(
@@ -139,15 +147,37 @@
     -0.7,   // y "
      0.0);  // z "

-  anim5->init(1.0);
-  anim6->init(0.6, true);
+  // Far left curtain
+  anim5->init(
+     25,    // height in pixels
+     6,     // width in pixels
+     1.0,   // height in ratio of visualiation
+     0.25,  // width in ratio of visualiation
+     0.0,   // rotation in radians
+    -0.7,   // x distance from visualization start in ratio of visualization
+    -0.7,   // y "
+     0.0);  // z "
+
+  // Far left curtain
+  anim6->init(
+     25,    // height in pixels
+     6,     // width in pixels
+     1.0,   // height in ratio of visualiation
+     0.25,  // width in ratio of visualiation
+     0.0,   // rotation in radians
+    -0.7,   // x distance from visualization start in ratio of visualization
+    -0.7,   // y "
+     0.0);  // z "
+
+  anim7->init(1.0);
+  anim8->init(0.6, true);

   FastLED.addLeds<WS2811, 21, RGB>(strip4.leds, 150);
   FastLED.addLeds<WS2811, 20, RGB>(strip3.leds, 150);
   FastLED.addLeds<WS2811, 14, RGB>(strip2.leds, 150);
   FastLED.addLeds<WS2811,  7, RGB>(strip1.leds, 150);

-  FastLED.addLeds<WS2811,  2, GRB>(strip5.leds, 165);
+  FastLED.addLeds<WS2811,  2, GRB>(strip7.leds, 165);

   FastLED.setBrightness(255);

@@ -160,6 +190,8 @@
   looper->addAnimation(anim4);
   looper->addAnimation(anim5);
   looper->addAnimation(anim6);
+  looper->addAnimation(anim7);
+  looper->addAnimation(anim8);
   looper->setUpdatesPerSecond(30);

   Log.Info("Finished setup()\n");


Update Ball-Board.ino

Update Ball-Board.ino

--- Firmware/Ball/Ball-Board/Ball-Board.ino
+++ Firmware/Ball/Ball-Board/Ball-Board.ino
@@ -53,26 +53,23 @@
 	k = INVERT the direction of Y
 	h = SET a new HYSTERESSIS

-
-
   < BOOT >
   'BOOT \n'  // LAUNCH TEST for X, Y and Z -> Return X and Y to initial SETPOINT (x90 y90 ) and Z to ZERO

-
-
   < RUN >
   'RUN \n'   // RUN the code in production mode (Recieved all data, X and Y runing for the SETPOINT poistion and Z folow the remote controll

   < STOP >
   'STOP \n'  // STOP the production mode. All motors are stopped.

-
   < ROTATE >
   'ROTATE d1 s100 \n'   // ROTATE Z motor on the RIGHT DIRECTION (d0 LEFT, d1 RIGHT) WITH the SPEED at 1000/100 = 10 step/sec = 18dec/sec

-
   < STAT >
-  // It is all data SENDED to the MASTER-BOARD
+  // It is all data SENDED to the remote
+
+  < ENABLE >
+  'ENABLE a1 x1 z1 \n'    // ENABLE MOTOR AB, XY and Z (a = AB, x=XY, z = Z | 0 = desabled | 1 = enabled )

 */

@@ -82,9 +79,15 @@
 #include <nRF24L01.h>
 #include <RF24.h>

+
+// RF24
 RF24 radio(54, 55);

-
+// MPU6050
+MPU6050 accelgyro;
+
+int16_t ax, ay, az;
+int16_t gx, gy, gz;

 // MOTOR CONFIGURATION // YOU CAN TOUCH THIS

@@ -139,23 +142,6 @@
 #define CurrentBat3      2
 #define CurrentBat4      3
 #define Pinvoltage       6
-
-
-
-
-
-
-
-
-
-
-
-
-// MPU6050
-MPU6050 accelgyro;
-
-int16_t ax, ay, az;
-int16_t gx, gy, gz;

 // I2C
 int adress         = 2;
@@ -198,6 +184,17 @@
 bool yok           = false;
 bool zok           = false;

+long intX          = 0;
+long intY          = 0;
+
+bool production    = false;
+bool LED_PING      = false;
+bool BOOT          = false;
+
+bool enMotAB       = false;
+bool enMotXY       = false;
+bool enMotZ        = false;
+
 unsigned long previousMillisX = 0;
 unsigned long previousMillisY = 0;
 unsigned long previousMillisZ = 0;
@@ -211,22 +208,14 @@
 unsigned long trigG    = 0;
 unsigned long trigS    = 0;

-long                    intX  = 0;
-long                    intY  = 0;
-bool production = false;
-bool LED_PING   = false;
-bool BOOT = false;
-
-bool enMotAB       = false;
-bool enMotXY       = false;
-bool enMotZ        = false;

 //=============================================================================//
 //   SETUP
 //=============================================================================//
 void setup()
 {
-	pinMode( pinEnableAB , OUTPUT );
+    // PINMODE
+    pinMode( pinEnableAB , OUTPUT );
     pinMode( pinEnableXY , OUTPUT );
     pinMode( pinEnableZ  , OUTPUT );
     pinMode( pinDirX     , OUTPUT );
@@ -241,58 +230,49 @@

     pinMode( Z_POSITION  , INPUT  );

-
-
-	Serial.begin(9600);
-
-
+    // SERIAL
+    Serial.begin(9600);
+
+    // Blabla, blablabla
     Serial.println("==================================================");
-	Serial.println("  _______ ______     _     _  ______  ____ ______ ");
-	Serial.println(" (____   (____  )   | |   | |/ ___  |(____|______)");
-	Serial.println("  ____)  )____)  )__| |   | | |   | | | |   | |   ");
-	Serial.println(" |  __  (|  __  (___) |   | | |   | | | |   | |   ");
-	Serial.println(" | |__)  ) |__)  )  | |___| | |   | |_| |_  | |   ");
-	Serial.println(" |______/|______/   |______/|_|   |_(_____) |_|   ");
-	Serial.println("            _ Astromech Industrie _               ");
-	Serial.println("      > https://github.com/Gruniek/BB-UNIT <      ");
-	Serial.println("           > http://r2builders.fr/ <              ");
-	Serial.print("           FIRMWARE VERSION : ");
-	Serial.print(version);
-	Serial.println("               ");
+    Serial.println("  _______ ______     _     _  ______  ____ ______ ");
+    Serial.println(" (____   (____  )   | |   | |/ ___  |(____|______)");
+    Serial.println("  ____)  )____)  )__| |   | | |   | | | |   | |   ");
+    Serial.println(" |  __  (|  __  (___) |   | | |   | | | |   | |   ");
+    Serial.println(" | |__)  ) |__)  )  | |___| | |   | |_| |_  | |   ");
+    Serial.println(" |______/|______/   |______/|_|   |_(_____) |_|   ");
+    Serial.println("            _ Astromech Industrie _               ");
+    Serial.println("      > https://github.com/Gruniek/BB-UNIT <      ");
+    Serial.println("           > http://r2builders.fr/ <              ");
+    Serial.print("           FIRMWARE VERSION : ");
+    Serial.print(version);
+    Serial.println("               ");
     Serial.println("==================================================");

     Serial.println(" ");
-	Serial.println("[1]-Booting up...");
-
-
-
-
+    Serial.println("[1]-Booting up...");
+
+    // Start of the I2C protocol
     Serial.print("[2]-Initializing I2C devices...  I2C ADRESS :");
     Serial.print(adress);
-
     Wire.begin(adress);

-
-
-
+    // Start the MPU6050 Gyroscope
     Serial.print("[3]-Connect to the MPU6050 : ");
     accelgyro.initialize();
     //Serial.println(accelgyro.testConnection());
     Serial.println(accelgyro.testConnection() ? "Connection successful" : "Connection failed");

+    // Start the RF24 Radio controll
     Serial.println("[4]-Initializing RF24 devices...  ");
     radio.begin();
     radio.openReadingPipe(0, 00001);
-
     radio.startListening();
-
-
-
+
+    // END OF BOOT/SETUP
     Serial.println("====================");
     Serial.println("Booting successful !");
     Serial.println("====================");
-
-
 }

 //=============================================================================//
@@ -300,29 +280,28 @@
 //=============================================================================//
 void loop()
 {
-    // GET MOTION
-    //-------------------------------------------------------------------------//
     unsigned long currentG = millis(); // millis();

     if (currentG - trigG  >= trigGyro)
     {
     	trigG = currentG;

-
+         // GET MOTION
+         //-------------------------------------------------------------------------//
     	accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
-		if(invertXY)
-		{
-			y = (((ax/180)+etalonX)+90);
-  			x = (((ay/180)+etalonY)+90);
-		}
-		else
-		{
-			x = (((ax/180)+etalonX)+90);
-  			y = (((ay/180)+etalonY)+90);
-		}
+	if(invertXY)
+	{
+	    y = (((ax/180)+etalonX)+90);
+  	    x = (((ay/180)+etalonY)+90);
+	}
+	else
+	{
+	    x = (((ax/180)+etalonX)+90);
+  	    y = (((ay/180)+etalonY)+90);
+	}
     }

-    // GET SERIAL DATA
+    // GET SERIAL AND RF24 DATA
     //-------------------------------------------------------------------------//

     char msg[64];
@@ -330,63 +309,62 @@
     {
     	Serial.readBytesUntil('\n', msg, sizeof msg);
     	newData = true;
-	}
+    }

-	if (radio.available())
+    if (radio.available())
     {
     	char msg[64] = {0};
     	radio.read(&msg, sizeof(msg));
     	newData = true;
     }

-	if(newData)
-	{
-		Serial.println(msg);
-		newData = false;
+    if(newData)
+    {
+	Serial.println(msg);
+	newData = false;

     	if (strcmp(strtok(msg, " "), "SET") == 0)
     	{
-        	Serial.println("UPDATE SETPOINT");
-      		// trouvé le message
-      		char *p;
-      		while ((p = strtok(NULL, " ")) != NULL)
-      		{
-        		int val = atoi(p + 1);
-        		switch (*p)
-        		{
-          			case 'x': setpointX  = val; break;
-          			case 'y': setpointY  = val; break;
-      	  			case 'm': multiplier = val; break;
-      				case 'i': invertXY   = val; break;
-      				case 'j': invertX    = val; break;
-      				case 'k': invertX    = val; break;
-      				case 'h': hysteresis = val; break;
-        		}
-      		}
+            Serial.println("UPDATE SETPOINT");
+      	    // trouvé le message
+      	    char *p;
+      	    while ((p = strtok(NULL, " ")) != NULL)
+      	    {
+       		int val = atoi(p + 1);
+       		switch (*p)
+       		{
+		    case 'x': setpointX  = val; break;
+          	    case 'y': setpointY  = val; break;
+      	  	    case 'm': multiplier = val; break;
+      		    case 'i': invertXY   = val; break;
+      		    case 'j': invertX    = val; break;
+      		    case 'k': invertX    = val; break;
+      		    case 'h': hysteresis = val; break;
+        	}
+      	    }
     	}

     	if (strcmp(strtok(msg, " "), "RUN") == 0)
     	{
-        	Serial.println("ROll BB-8 ROLL !");
+            Serial.println("ROll BB-8 ROLL !");
       	    production = true;
     	}

     	if (strcmp(strtok(msg, " "), "STOP") == 0)
     	{
-    		Serial.println("STOP");
+    	    Serial.println("STOP");
     	    production = false;
     	}

     	if (strcmp(strtok(msg, " "), "RESET") == 0)
     	{
-    		Serial.println("RESET");
+    	    Serial.println("RESET");
     	    production = false;
     	    emgStop    = false;
     	}

     	if (strcmp(strtok(msg, " "), "BOOT") == 0)
-    	{
-
+    	{
     	    BOOT = true;
     	    Serial.println("BOOTING UP...");
     	    delay(2000);
@@ -394,55 +372,55 @@

     	if (strcmp(strtok(msg, " "), "ROTATE") == 0) // ROTATE d1 s100  <-- Rotate Z right, 18c/sec
     	{
-      		// trouvé le message
-      		char *p;
-      		while ((p = strtok(NULL, " ")) != NULL)
-      		{
-        		int val = atoi(p + 1);
-        		switch (*p)
-        		{
-          			case 'd': directZ  = val; break;
-          			case 's': speedZ   = val; break;
-        		}
-      		}
+      	    // trouvé le message
+      	    char *p;
+      	    while ((p = strtok(NULL, " ")) != NULL)
+      	    {
+                 int val = atoi(p + 1);
+        	 switch (*p)
+        	 {
+          	     case 'd': directZ  = val; break;
+          	     case 's': speedZ   = val; break;
+                 }
+            }
     	}

     	if (strcmp(strtok(msg, " "), "MOVE") == 0)
-    		{
-        		Serial.println("UPDATE SETPOINT");
-      			// trouvé le message
-      			char *p;
-      			while ((p = strtok(NULL, " ")) != NULL)
-      			{
-        			int val = atoi(p + 1);
-        			switch (*p)
-        			{
-          				case 'a': speedA  = val; break;
-          				case 'b': speedB  = val; break;
-      	  				case 'c': dirA    = val; break;
-      					case 'd': dirB    = val; break;
-        			}
-      			}
-    		}
+    	{
+            Serial.println("UPDATE SETPOINT");
+      	    // trouvé le message
+      	    char *p;
+      	    while ((p = strtok(NULL, " ")) != NULL)
+      	    {
+                int val = atoi(p + 1);
+        	switch (*p)
+        	{
+          	     case 'a': speedA  = val; break;
+          	     case 'b': speedB  = val; break;
+      	  	     case 'c': dirA    = val; break;
+      		     case 'd': dirB    = val; break;
+        	}
+      	    }
+        }

     	if (strcmp(strtok(msg, " "), "ENABLE") == 0)
     	{
-       		//Serial.println("UPDATE SETPOINT");
-  			// trouvé le message
-  			char *p;
-      		while ((p = strtok(NULL, " ")) != NULL)
-   			{
-      			int val = atoi(p + 1);
-        		switch (*p)
-        		{
-        	  		case 'a': enMotAB  = val; break;
-        	  		case 'x': enMotXY  = val; break;
-      		  		case 'z': enMotZ   = val; break;
-        		}
-      		}
+       	    //Serial.println("UPDATE SETPOINT");
+  	    // trouvé le message
+  	    char *p;
+      	    while ((p = strtok(NULL, " ")) != NULL)
+   	    {
+      	        int val = atoi(p + 1);
+        	switch (*p)
+        	{
+        	    case 'a': enMotAB  = val; break;
+        	    case 'x': enMotXY  = val; break;
+      		    case 'z': enMotZ   = val; break;
+        	}
+      	    }
     	}

-   }
+    }

    digitalWrite(pinEnableAB, enMotAB);
    digitalWrite(pinEnableXY, enMotXY);
@@ -450,207 +428,202 @@

    if(BOOT)
    {
- 		enMotAB = true;
- 		enMotXY = true;
- 		enMotZ  = true;
-
-
-   	    // SET X IN POSITION
-   		if(x < 90) directX = false;
-  		else directX = true;
-
-  		if(invertX)
-  		{
+ 	enMotAB = true;
+ 	enMotXY = true;
+ 	enMotZ  = true;
+
+   	// SET X IN POSITION
+   	if(x < 90) directX = false;
+  	else directX = true;
+
+  	if(invertX)
+  	{
     		if(directX) directX = false;
     		else directX = true;
-  		}
-  		digitalWrite(pinDirX, directX); // dirX
+  	}
+  	digitalWrite(pinDirX, directX); // dirX

-  		if(x > (setpointX + hysteresis) || (x < setpointX - hysteresis ))
-  		{
-  	        digitalWrite(pinStepX, 1);
-        	delayMicroseconds( 500 );
+  	if(x > (setpointX + hysteresis) || (x < setpointX - hysteresis ))
+  	{
+  	    digitalWrite(pinStepX, 1);
+            delayMicroseconds( 500 );
     	    digitalWrite(pinStepX, 0);
     	    delayMicroseconds( 500 );
-  		}
-  		else
-  		{
-  			if(!xok)
-  			{
-  				Serial.println("BOOT x1 ");
-  				xok = true;
-  				delay(2000);
-  			}
-  		}
+  	}
+  	else
+  	{
+  	    if(!xok)
+            {
+  	        Serial.println("BOOT x1 ");
+  		xok = true;
+  		delay(2000);
+ 	    }
+  	}

+        // SET Y IN POSITION
+   	if(y < 90) directY = false;
+  	else directY = true;
+
+	if(invertY)
+  	{
+    	    if(directY) directY = false;
+    	    else directY = true;
+  	}
+  	digitalWrite(pinDirY, directY); // dirX

-  		// SET Y IN POSITION
-   		if(y < 90) directY = false;
-  		else directY = true;
-
-  		if(invertY)
-  		{
-    		if(directY) directY = false;
-    		else directY = true;
-  		}
-  		digitalWrite(pinDirY, directY); // dirX
-
-  		if(x > (setpointY + hysteresis) || (y < setpointY - hysteresis ))
-  		{
-  	        digitalWrite(pinStepY, 1);
-        	delayMicroseconds( 500 );
+  	if(x > (setpointY + hysteresis) || (y < setpointY - hysteresis ))
+  	{
+  	    digitalWrite(pinStepY, 1);
+            delayMicroseconds( 500 );
     	    digitalWrite(pinStepY, 0);
     	    delayMicroseconds( 500 );
-  		}
-  		else
-  		{
-  			if(!yok)
-  			{
-  				Serial.println("BOOT y1 ");
-  				yok = true;
-  				delay(2000);
-  			}
-  		}
+        }
+  	else
+  	{
+  	    if(!yok)
+  	    {
+  		Serial.println("BOOT y1 ");
+  		yok = true;
+  		delay(2000);
+  	    }
+  	}

-  		// SET Z IN POSITION
-
-  		if(!Z_POSITION)
-  		{
-  		  	digitalWrite(pinStepZ, 1);
-        	delayMicroseconds( 500 );
+  	// SET Z IN POSITION
+  	if(!Z_POSITION)
+  	{
+  	    digitalWrite(pinStepZ, 1);
+            delayMicroseconds( 500 );
     	    digitalWrite(pinStepZ, 0);
     	    delayMicroseconds( 500 );
-  		}
-  		else
-  		{
-  		  	if(!zok)
-  			{
-  				Serial.println("BOOT z1 ");
-  				zok = true;
-  				Zangle = 0;
-  				delay(2000);
-  			}
-  		}
+  	}
+  	else
+  	{
+       	    if(!zok)
+  	    {
+  	        Serial.println("BOOT z1 ");
+  		zok = true;
+  		Zangle = 0;
+  		delay(2000);
+  	    }
+  	}

-  		if( xok && yok && zok)
-  		{
-			Serial.println("STAT b1 ");
-  			Serial.println("Booting UP OK!");
-  			Serial.println("SEND 'RUN \n' for start the production");
-  			BOOT = false;
-  		}
-
-
-   }
+  	if( xok && yok && zok)
+  	{
+	    Serial.println("STAT b1 ");
+  	    Serial.println("Booting UP OK!");
+  	    Serial.println("SEND 'RUN \n' for start the production");
+  	    BOOT = false;
+  	}
+     }

-	// PRODUCTION CODE
+    // PRODUCTION CODE
     //-------------------------------------------------------------------------//
     if(production && !emgStop)  //-
     {
     	enMotAB = true;
- 		enMotXY = true;
- 		enMotZ  = true;
+ 	enMotXY = true;
+ 	enMotZ  = true;

     	//======================================================================
     	//        d8888
     	//       d88888
-     	//		d88P888
-    	//	   d88P 888
-   		//	  d88P  888
-  		//   d88P   888
- 		//	d8888888888
-		// d88P     888
-		//======================================================================
+     	//	d88P888
+    	//     d88P 888
+   	//    d88P  888
+  	//   d88P   888
+ 	//  d8888888888
+	// d88P     888
+	//======================================================================
     	// MOTOR A (Left)

-		// Run the motor
-		if(speedA > 0) runA = true;
-		else runA = false;
-		speedA = 1000 / speedA;
+	// Run the motor
+	if(speedA > 0) runA = true;
+	else runA = false;
+	speedA = 1000 / speedA;

-		// Motor direction / With inversion
-		if(invertA)
-	  	{
-	    	if(dirA) dirA = false;
-	    	else dirA = true;
-	  	}
-		digitalWrite(pinDirA, dirA); // Set the direction
+	// Motor direction / With inversion
+	if(invertA)
+  	{
+    	    if(dirA) dirA = false;
+	    else dirA = true;
+	}
+	digitalWrite(pinDirA, dirA); // Set the direction

-		// Send Step inpultion to the motor
-		unsigned long currentA = millis(); // millis();
-	   	if (currentA - previousMillisA >= speedA)
-	   	{
-	      	previousMillisA = currentA;
-
-	      	if(runA)
-	      	{
-	        	digitalWrite(pinStepA, 1);
-	        	delayMicroseconds( 500 );
-	        	digitalWrite(pinStepA, 0);
-	        	delayMicroseconds( 500 );
-	      	}
-	  	}
+	// Send Step inpultion to the motor
+	unsigned long currentA = millis(); // millis();
+	if (currentA - previousMillisA >= speedA)
+	{
+	    previousMillisA = currentA;
+
+	    if(runA)
+	    {
+	        digitalWrite(pinStepA, 1);
+	        delayMicroseconds( 500 );
+	        digitalWrite(pinStepA, 0);
+	        delayMicroseconds( 500 );
+	    }
+	}

     	//======================================================================
-		// 888888b.
-		// 888  "88b
-		// 888  .88P
-		// 8888888K.
-		// 888  "Y88b
-		// 888    888
-		// 888   d88P
-		// 8888888P"
-		//======================================================================
-		// MOTOR B (Right)
+	// 888888b.
+	// 888  "88b
+	// 888  .88P
+	// 8888888K.
+	// 888  "Y88b
+	// 888    888
+	// 888   d88P
+	// 8888888P"
+	//======================================================================
+	// MOTOR B (Right)

-		// Run the motor
-		if(speedB > 0) runB = true;
-		else runB = false;
-		speedB = 1000 / speedB;
+	// Run the motor
+	if(speedB > 0) runB = true;
+	else runB = false;
+	speedB = 1000 / speedB;
+
+	// Motor direction / With inversion
+	if(invertB)
+ 	{
+	    if(dirB) dirB = false;
+	    else dirB = true;
+	}
+	digitalWrite(pinDirB, dirB); // Set the direction

-		// Motor direction / With inversion
-		if(invertB)
-	  	{
-	    	if(dirB) dirB = false;
-	    	else dirB = true;
-	  	}
-		digitalWrite(pinDirB, dirB); // Set the direction
-
-		// Send Step inpultion to the motor
-		unsigned long currentB = millis(); // millis();
-	   	if (currentB - previousMillisB >= speedB)
-	   	{
-	      	previousMillisB = currentB;
+	// Send Step inpultion to the motor
+	unsigned long currentB = millis(); // millis();
+	if (currentB - previousMillisB >= speedB)
+	{
+	    previousMillisB = currentB;

-	      	if(runB)
-	      	{
-	        	digitalWrite(pinStepB, 1);
-	        	delayMicroseconds( 500 );
-	        	digitalWrite(pinStepB, 0);
-	        	delayMicroseconds( 500 );
-	      	}
-	  	}
+	    if(runB)
+	    {
+	        digitalWrite(pinStepB, 1);
+	        delayMicroseconds( 500 );
+	        digitalWrite(pinStepB, 0);
+	        delayMicroseconds( 500 );
+	     }
+	}

     	//======================================================================
-		// Y88b   d88P
-		//  Y88b d88P
-		//   Y88o88P
-		//    Y888P
-		//    d888b
-		//   d88888b
-		//  d88P Y88b
-		// d88P   Y88b
-		//======================================================================
-
-		// Direction
-  		if(x < 90) directX = false;
-  		else directX = true;
-
-  		if(invertX)
-  		{
-    		if(directX) directX = false;
-    		else directX = true;
-  		}
+        // Y88b   d88P
+	//  Y88b d88P
+	//   Y88o88P
+	//    Y888P
+	//    d888b
+	//   d88888b
+	//  d88P Y88b
+	// d88P   Y88b
+	//======================================================================
+
+	// Direction
+  	if(x < 90) directX = false;
+  	else directX = true;
+
+  	if(invertX)
+  	{
+    	    if(directX) directX = false;
+    	    else directX = true;
+  	}
   		digitalWrite(pinDirX, directX); // dirX

   		// Si ont doit demarer le moteur


Update Integrated_Test_PowerSleep.ino

Update Integrated_Test_PowerSleep.ino

--- src/piggy_back_loggers/Integrated_Test_PowerSleep.ino
+++ src/piggy_back_loggers/Integrated_Test_PowerSleep.ino
@@ -691,7 +691,6 @@
         Serial.print(F("\n>> Logger: Done. \n>> User 1: "));
         break;

-                                // Easter Eggs!
       case 'J':
         Serial.print(F(">> Logger: J <3 J\n>> User 1: "));
         break;


better print, and sending of increasing bytes

--- arduino/examples/slave_sender/slave_sender.ino
+++ arduino/examples/slave_sender/slave_sender.ino
@@ -12,12 +12,19 @@

 #include <Wire.h>

+char val1,val2;
+char *arry;
 void setup()
 {
   Serial.begin(9600);
   Wire.begin(0x12);                // join i2c bus with address #8
   Wire.onRequest(requestEvent); // register event
   Wire.onReceive(receiveEvent);
+  val1 = 0;
+  val2 = 255;
+  arry = new char[2];
+  arry[0] = val1;
+  arry[1] = val2;

 }

@@ -33,15 +40,24 @@
   while(Wire.available())
   {
     char c = Wire.read();
-    Serial.println(c);
+    Serial.println((unsigned char)c);
   }
+  arry[0]++;
+  arry[1]--;
+
 }

 // function that executes whenever data is requested by master
 // this function is registered as an event, see setup()
 void requestEvent()
 {
+
   Serial.println("Bytes requested");
-  Wire.write("hello "); // respond with message of 6 bytes
+
+  Wire.write(arry,2); // respond with message of 6 bytes
   // as expected by master
 }
+
+char c2h(char c)
+{  return "0123456789ABCDEF"[0x0F & (unsigned char)c];
+}


ultrasonic tussen 15 en 30 cm: halfspeed

--- RosChatter.ino
+++ RosChatter.ino
@@ -31,7 +31,7 @@
     return 0.0;
   }
   else if (distance_cm > 0 && distance_cm < 30) {
-    return (float) (distance_cm-15)/15.0;
+    return 0.5//(float) (distance_cm-15)/15.0;
   }
   else {
     return 1.0;


fix WebUpload example

fix WebUpload example

--- libraries/ESP8266WebServer/examples/WebUpdate/WebUpdate.ino
+++ libraries/ESP8266WebServer/examples/WebUpdate/WebUpdate.ino
@@ -30,15 +30,13 @@
         Serial.setDebugOutput(true);
         WiFiUDP::stopAll();
         Serial.printf("Update: %s\n", upload.filename.c_str());
-        uint32_t maxSketchSpace = ((ESP.getFreeSketchSpace() + ESP.getSketchSize()) / 2) & 0xFFFFF000;
+        uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
         if(!Update.begin(maxSketchSpace)){//start with max available size
           Update.printError(Serial);
-          return;
         }
       } else if(upload.status == UPLOAD_FILE_WRITE){
         if(Update.write(upload.buf, upload.currentSize) != upload.currentSize){
           Update.printError(Serial);
-          return;
         }
       } else if(upload.status == UPLOAD_FILE_END){
         if(Update.end(true)){ //true to set the size to the current progress
@@ -59,7 +57,7 @@
     server.begin();
     MDNS.addService("http", "tcp", 80);

-    Serial.println("Ready! Open http:\/\/%s.local in your browser\n", host);
+    Serial.printf("Ready! Open http://%s.local in your browser\n", host);
   } else {
     Serial.println("WiFi Failed");
   }


Added a little more work on arduino node support (with udp messaging).

--- nodes/hapili_arduino_node/hapili_arduino_node.ino
+++ nodes/hapili_arduino_node/hapili_arduino_node.ino
@@ -1,45 +1,86 @@
 #include <SPI.h>
-//#include <utilV2_0.h>
+#include <DhcpV2_0.h>
+//#include <DnsV2_0.h>
 //#include <EthernetClientV2_0.h>
-//#include <DhcpV2_0.h>
 //#include <EthernetServerV2_0.h>
 #include <EthernetV2_0.h>
-//#include <DnsV2_0.h>
-//#include <EthernetUdpV2_0.h>
+#include <EthernetUdpV2_0.h>
+//#include <Messenger.h>
+//#include <utilV2_0.h>

 #define W5200_CS  10
 #define SDCARD_CS 4

 byte mac[] = { 0xDE, 0xAD, 0xBE, 0xFF, 0xFF, 0x01 };

+char buf[UDP_TX_PACKET_MAX_SIZE];
 int dhcpSuccess = 0;
+EthernetServer server = EthernetServer(80);
+EthernetUDP sock;
+//Messenger message = Messenger();
+
+void onMessageReady();

 void setup()
 {
-    Serial.begin(115200);
-    Serial.println("Starting...");
-
-    pinMode(SDCARD_CS, OUTPUT);
-    digitalWrite(SDCARD_CS, HIGH);
-
-    while (dhcpSuccess != 1) {
-        Serial.println("Attempting to obtain DHCP address.");
-        dhcpSuccess = Ethernet.begin(mac);
-        if (dhcpSuccess != 1) {
-            Serial.println("Failed to acquire DHCP address, trying again in 5 seconds.");
-            delay(5000);
-        }
+  Serial.begin(115200);
+  Serial.println("Starting...");
+
+  pinMode(SDCARD_CS, OUTPUT);
+  digitalWrite(SDCARD_CS, HIGH);
+
+  while (dhcpSuccess != 1) {
+    Serial.println("Attempting to obtain DHCP address.");
+    dhcpSuccess = Ethernet.begin(mac);
+    if (dhcpSuccess != 1) {
+      Serial.println("Failed to acquire DHCP address, trying again in 5 seconds.");
+      delay(5000);
     }
-    Serial.print("Acquired DHCP address: ");
-    for (byte i = 0; i < 4; i++) {
-        Serial.print(Ethernet.localIP()[i], DEC);
-        Serial.print(".");
-    }
-    Serial.println();
-
-    Serial.println("Ready.\n");
+  }
+  Serial.print("Acquired DHCP address: ");
+  for (byte i = 0; i < 4; i++) {
+    Serial.print(Ethernet.localIP()[i], DEC);
+    Serial.print(".");
+  }
+  Serial.println();
+
+  server.begin();
+  sock.begin(666);
+
+//  message.attach(onMessageReady);
+
+  Serial.println("Ready.\n");
 }

 void loop()
 {
+  EthernetClient client = server.available();
+  if (client == true) {
+    char c = client.read();
+    Serial.print(c);
+  }
+
+  int nbytes = sock.parsePacket();
+  if (nbytes > 0)
+  {
+
+      Serial.print("udp|recv| nbytes: ");
+      Serial.print(nbytes);
+
+      sock.read(buf, UDP_TX_PACKET_MAX_SIZE);
+      Serial.print(", data: ");
+      Serial.println(String(buf).substring(0, nbytes));
+      sock.beginPacket(sock.remoteIP(), sock.remotePort());
+      sock.write(buf, nbytes);
+//      for (int i = nbytes; i < nbytes; i++)
+//          message.process(buf[i]);
+      sock.endPacket();
+  }
 }
+
+void onMessageReady()
+{
+
+}
+
+


Separate testing case from main

Separate testing case from main

--- seven-segment-integers/src/seven-segment-integers.ino
+++ seven-segment-integers/src/seven-segment-integers.ino
@@ -40,15 +40,10 @@
 const int clockPin = 10;

 const long refreshInterval = 10; //refresh delay in microseconds
-const long countInterval = 100; //counter delay in milliseconds
+long previousRefresh = 0; //previous refresh time
+int refreshLoop = 0;  //counter for refreshing loop

-long previousRefresh = 0; //previous refresh time
-long previousCount = 0; //previous count time
-
-int refreshLoop = 0;  //counter for refreshing loop
-int countLoop = 0; //counter for counting loop
-
-int num[] = {-1,-1,-1,-1};  //array for display numbers, {ones, tens, hundreds, thousands}
+int num[] = {0,-1,-1,-1};  //array for display numbers, {ones, tens, hundreds, thousands}

 void setup() {
   //setup  pin modes to output
@@ -63,7 +58,6 @@
 void loop() {
   //current timer variables to reset at each iteration
   unsigned long currentRefresh = micros();  //get current microseconds for refresh counter
-  unsigned long currentCount = millis();  //get current milliseconds for counting counter

   clearLEDs();

@@ -80,17 +74,7 @@
     refreshLoop++;
   }

-  //test timer loop, increases count by one at each interval of countInterval
-  if (currentCount - previousCount > countInterval) {
-    previousCount = currentCount;
-
-    splitNumber(countLoop);
-
-    countLoop ++;
-
-    if (countLoop == 10000)
-      countLoop = 0;
-  }
+  testCaseAllNum();
 }

 void clearLEDs() {
@@ -100,7 +84,7 @@

 void pickDigit(int j) {
   // pick which digit to display depending on the value passed in j
-  for (int i=0; i<4; i++)
+  for (int i=1; i<4; i++)
     digitalWrite(digits[i], HIGH);

   digitalWrite(digits[j], LOW);
@@ -123,7 +107,7 @@

   //clear previous values of the num array, -1 value allows checking to see if a new value has been placed
   for (int i=0; i<4; i++)
-    num[i]=-1;
+    num[i] = -1;

   //if n is 0-9
   if (n < 10) {
@@ -160,4 +144,26 @@
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, leds);
    digitalWrite(latchPin, HIGH);
+}
+
+//global variables for the test function
+const long testInterval = 500; //counter delay in milliseconds
+long previousTestTime = 0; //previous count time
+int testLoop = 0; //counter for counting loop
+
+void testCaseAllNum() {
+  //test case, a loop timer that runs through each integer from 0 to 9999
+  unsigned long currentTestTime = millis();  //get current milliseconds for counting counter
+
+  if (currentTestTime - previousTestTime > testInterval) {
+    previousTestTime = currentTestTime;
+
+    splitNumber(testLoop);
+
+    testLoop ++;
+
+    //reset loop to 0 at end of displayable integers
+    if (testLoop == 10000)
+      testLoop = 0;
+  }
 }


Simplify heartbeat check

Simplify heartbeat check

--- volvo_hid.ino
+++ volvo_hid.ino
@@ -21,7 +21,6 @@

 #define SYN_FIELD 0x55
 #define SWM_ID 0x20
-#define HEARTBEAT_ID 0xCF

 // Volvo V50 2007 SWM key codes
 //
@@ -91,14 +90,11 @@
 }

 void handle_frame() {
-  byte id = frame.get_byte(0);
-
-  if (id == HEARTBEAT_ID)
-    lastHeartbeat = millis();
-
-  if (id != SWM_ID)
+  if (frame.get_byte(0) != SWM_ID)
     return;

+  lastHeartbeat = millis();
+
   // skip zero values 20 0 0 0 0 FF
   if (frame.get_byte(5) == 0xFF)
     return;


Flash the led on string complete.

Flash the led on string complete.

--- arduino/serial_server/serial_server.ino
+++ arduino/serial_server/serial_server.ino
@@ -1,6 +1,9 @@
 /***************************************************
   Simple serial server
 ****************************************************/
+
+// Pin 13 has an LED connected on most Arduino boards.
+int led_pin = 13;

 //serial
 String inputString = "";         // a string to hold incoming data
@@ -17,6 +20,7 @@
 void loop(){
   // print the string when a newline arrives:
   if (stringComplete) {
+    flash(200);
     Serial.println(inputString);
     // clear the string:
     inputString = "";
@@ -43,3 +47,10 @@
     }
   }
 }
+
+// Flash the led for the given time (milliseconds)
+void flash(int msecs){
+    digitalWrite(led_pin, HIGH);
+    delay(msecs);
+    digitalWrite(led_pin, LOW);
+}


lcd graphics changes

lcd graphics changes

--- master/master.ino
+++ master/master.ino
@@ -242,7 +242,9 @@
 	tft.setTextSize(2);
 	tft.setTextColor(ILI9341_RED);
 	tft.println("entered calibration mode");
-	tft.println("tap anywhere on screen to finish calibration");
+	tft.println("tap anywhere on screen to");
+	tft.println("finish calibration");
+	tft.println();

 	touched = false;
 	while(!touched){
@@ -454,7 +456,7 @@

 	tft.fillRect(0, 32, 320, 145, ILI9341_BLACK);
 	//tft.fillScreen(ILI9341_BLACK);
-	tft.setCursor(0, 50);
+	tft.setCursor(0, 40);
 	tft.setTextColor(ILI9341_RED);
 	tft.println("micros");
 	tft.setTextColor(ILI9341_YELLOW);


Delete Robot_Code.ino

Delete Robot_Code.ino

--- Robot_Code.ino
+++ Robot_Code.ino
@@ -1,1365 +0,0 @@
-//#include <Array.h>
-
-#include <SoftwareSerial.h>
-#include <SPI.h>
-#include <Pixy.h>
-#include <NewPing.h>
-#include <Math.h>
-#include <Time.h>
-#include <SD.h>
-
-#define X_CENTER 160L
-
-int wheel_pwm[] = {2,3,4}; //pins on motor drive to control speed
-int wheel_direction[] = {5,6,7}; //pins to control wheel direction
-double wheel_angles[] = {270, 30, 150}; //wheel angles are defined
-double wheel_speed[3]; //speed of each wheel is stored in this array
-double max_speed = 70; //maximum speed
-double max_speedR = 40; //rotate speed
-
-//create a new instance of Pixy
-Pixy pixy;
-
-double cm[2]; //sensed distance of sonar sensor : 2 represents array(2 sonar sensors)
-
-int trigger[6] = {30, 32, 46, 36, 38, 40}; //trigger pins assignment  (sends)
-int echo[6] = {31, 33, 47, 37, 39, 41}; //echo pins (receives)
-
-int colliDistance_cm = 25; //distances to define collision in cm/in
-int colliDistance_in = 12;
-
-//set up the sonar sensors for NewPing Library
-NewPing sonar[6] =
-{
-  NewPing(trigger[0], echo[0], 500), //500 represents type of sensor
-  NewPing(trigger[1], echo[1], 500),
-  NewPing(trigger[2], echo[2], 500),
-  NewPing(trigger[3], echo[3], 500),
-  NewPing(trigger[4], echo[4], 500),
-  NewPing(trigger[5], echo[5], 500),
-};
-
-int IR_proximity_pins[] = {A0, A1, A2, A3}; // pins for the proximity detection
-int IR_proximity_state[4];              // state of IR pins
-
-double solar[9]; //solar vectors are stored here
-double solar_angles[] = {290, 330, 10, 50, 90, 130, 170, 210, 250}; //solar angles defined
-int solar_pins[] = {A5, A7, A8, A9, A10, A12, A13, A14, A15}; // solar pins
-//analog pins assigned to solar panels
-
-boolean light1_state = false;
-boolean light2_state = false;
-boolean water_state = false;
-boolean CO2_state = false;
-
-const int motor_relay = 8;   //does not want relay to change.
-
-void setup() {     //does not return anything
-  Serial.begin(9600);  // begin serial to computer
-
-  for (int i = 0; i < 3; i++) {
-    pinMode(wheel_direction[i], OUTPUT); //wheel directions are OUTPUT
-  }
-  for (int i = 0; i < 4; i++) { //i++ for adding
-    pinMode(IR_proximity_pins[i], INPUT);
-  }
-  pinMode(motor_relay, OUTPUT);
-  digitalWrite(motor_relay, HIGH);
-
-  Serial3.begin(9600);    // begin serial to BASE ARDUINO
-  Serial1.begin(9600);    // begin serial to SD card
-
-  pixy.init();  // initialize pixy camera library functions
-  delay(100);  //delay of .1 seconds so that you do not compile errors
-  // find_red2();
-  // setTime(7,0,0,1,1,1);    // (hr,min,sec,day,month,yr)
-
-}
-/*
-  #include <SoftwareSerial.h>
-
-  SoftwareSerial mySerial(0, 1); // RX, TX
-
-  void setup()
-  {
-  // Open serial communications and wait for port to open:
-  Serial.begin(57600);
-  while (!Serial) {
-    ; // wait for serial port to connect. Needed for Leonardo only
-  }
-
-
-  Serial.println("Goodnight moon!");
-
-  // set the data rate for the SoftwareSerial port
-  mySerial.begin(4800);
-  mySerial.println("Hello, world?");
-  }
-
-  void loop() // run over and over
-  {
-  if (mySerial.available())
-     Serial.write(mySerial.read());
-  if (Serial.available())
-     mySerial.write(Serial.read());
-  }
-*/
-void loop() {
- // motospd(5,5,5);
-//Pixy_Align();
-//updateSonar();
-sonarInfoDisplay();
-//Do_Thingy();
-//Go_To_Object();
-//wheel_speeds(40,270);
-//motospd(0,0,40);
-  delay(1000);
-}
-void Do_Thingy(){
-  boolean aligned = false;
-  Serial.print(Am_I_Close());
-  if(!aligned){
-    Pixy_Align();
-    aligned = true;
-  }
-  else if (!Am_I_Close()){
-    Go_To_Object();
-  }
-  else{
-    return;
-  }
-}
-void Go_To_Object(){
-  if(Am_I_Close()){
-    motospd(0,0,0);
-  }
-  else{
-    motospd(0,40,-40);
-  }
-  delay(100);
-
-}
-boolean Am_I_Close(){
-   unsigned int uS = sonar[2].ping();
-    cm[1] = sonar[1].convert_cm(uS);
-    cm[2] = sonar[2].convert_cm(uS);
-    Serial.print(cm[1]);
-    Serial.print(cm[2]);
-    if (cm[1] <=30 && cm[1] != 0 || cm[2] <= 30 && cm[2] != 0){
-      return true;
-    }
-    else{
-      return false;
-    }
-
-}
-void Pixy_Align()
-{
-  Serial.println("-------------------------------------------------");
-  Serial.println("-------------------------------------------------");
-  get_coordinates();
-  int rotation_update_delay = 10;
-  int tolerance = 15;
-  int blocks = pixy.getBlocks(17);
-  if (pixy.blocks[0].x < (160 - tolerance) )
-  {
-    Serial.println("Rotating CoutnerClockwise...");
-    motospd(20, 20, 20);
-    delay(rotation_update_delay);
-    Pixy_Align();
-  }
-  else if (pixy.blocks[0].x > (160 + tolerance) )
-  {
-    Serial.println("Rotating Clockwise...");
-    motospd(-20, -20, -20);
-    delay(rotation_update_delay);
-    Pixy_Align();
-  }
-  else {
-//    Pixy_finetune();
- Serial.println("pixy has been aligned");
-    motospd(0, 0, 0);
-    return;
-  }
-
-
-}
-
-void Pixy_finetune() {
-
-  Serial.println("------------||FINE TUNE IN PROGRESS||-----------");
-  Serial.println("-------------------------------------------------");
-  get_coordinates();
-  int rotation_update_delay = 10;
-  int tolerance = 5;
-  int spd = 10;
-  int blocks = pixy.getBlocks(17);
-  if (pixy.blocks[0].x < (160 - tolerance) )
-  {
-    Serial.println("Rotating CoutnerClockwise...");
-    motospd(spd, spd, spd);
-    delay(rotation_update_delay);
-    Pixy_finetune();
-  }
-  else if (pixy.blocks[0].x > (160 + tolerance) )
-  {
-    Serial.println("Rotating Clockwise...");
-    motospd(-1 * spd, -1 * spd, -1 * spd);
-    delay(rotation_update_delay);
-    Pixy_finetune();
-  }
-  else {
-    Serial.println("pixy has been aligned");
-    motospd(0, 0, 0);
-    return;
-  }
-
-}
-
-void get_coordinates()
-{
-
-  int blocks = pixy.getBlocks(17);
-  for (int k = 0; k < blocks; k++) {
-    if (pixy.blocks[k].signature == 1) {
-      Serial.print("The X coordinate is:");
-      Serial.print(pixy.blocks[k].x);
-      Serial.println();
-      Serial.print("The Y coordinate is:");
-      Serial.print(pixy.blocks[k].y);
-      Serial.println();
-
-    }
-  }
-
-}
-void wheel_speeds(float tot_spd, float ang){   //Input speed and direction you want to go from 0 to 360
-  float results[4]; //establish the results arrray for relative angle.
-  Relative_ang(results,ang); //returns relative angle from -30 to 30 and wheels. First two wheels are main wheels, last wheel compensates for directional movement
-
-  float Motor_2 = abs(((((-1/sqrt(3))*tan((results[0]/180)*M_PI))-1)*(tot_spd/(1/cos((results[0]/180)*M_PI))))); //maths
-  float Motor_1 = abs(((((1/sqrt(3))*tan((results[0]/180)*M_PI))-1)*(tot_spd/(1/cos((results[0]/180)*M_PI)))));  //more maths
-
-  float Motor_Comp = .0018*pow(results[0],3) - 0.1019*pow(results[0],2) + 2.446*results[0] + 0.8571; //equaiton for compensator found by experiment and excel curve fit
-
-
-
-//----------------------------------------------------------------------------------------
-//READ ME!!!!!!!
-//
-//What is done below may look confusing, and it is to an extent. This method was done in order to not have a bunch of if/else statements
-//
-// The general idea: Relative_ang() gives values to the array called results. results is an array where the first position is the relative angle and the following
-// three are motors, with the first two being main working motors and the last being a compensator for the direction
-//
-// What we need to do is assign each of these wheels the proper wheel speed. Using the knowledge that the first two motors listed in the results array are the
-// main motors, and that the motors are called (+/-)1,2,3.....we can give the proper value to the proper motor. Since motospd(...,...,...) takes in three values that
-// are always in order from wheel 1 to 3,  we must assign the wheels from results an array value and then assign the proper speed at that specific array value and
-  // asign it to an array that reorganizes the wheels so motospd can distribute the proper speed to the proper wheel....... this is a shitty explanation pls forgive me
-  //
-  //
-int a = abs(results[1])-1; //since the wheels are labled from 1 to 3, we subtract one to give it a proper position in the motors array below
-int b = abs(results[2])-1; // e.g. results[2] = wheel 3.......3-1 = 2.... 'b' will be in the position of motors[2]
-int c = abs(results[3])-1;
-
- float motors[3]; // establish the final wheel speed array to set wheels
- motors[a]= (results[1]/(abs(results[1]))) * Motor_1;  //(results[1]/(abs(results[1]))) is to determine the directon of the wheel rotation (positive or negative)
- motors[b]= (results[2]/(abs(results[2]))) * Motor_2;
- motors[c]= (results[3]/(abs(results[3]))) * Motor_Comp; // so since 'c' corresponds to the value of the wheel in results[3], the compensator value is assigned.
- // this does not mean motor[c] will always be the thrid value in motors. if the compensator wheel is determined to be wheel 2, then 2-1 = 1, and motors[1] will be assinged
- // the compenator value, which is the second value in the array for this case.
-
-Serial.println(results[0]);
-Serial.println(results[1]);
-Serial.println(results[2]);
-Serial.println(results[3]);
-Serial.println("------------------------------------");
-Serial.println("--------------Motors---------------");
-Serial.println("------------------------------------");
-Serial.println(motors[0]);
-Serial.println(motors[1]);
-Serial.println(motors[2]);
-Serial.println("------------------------------------");
-Serial.println("--------------Results---------------");
-Serial.println("------------------------------------");
-
- motospd(motors[0],motors[1],motors[2]); //set all the wheel seeds
-}
-
-
-void Relative_ang(float *ptr, float ang){
-//float a,b,c,d;
-// float new_config[4]={0,0,0,0};
-// float *ptr[4];
- float new_ang;
-
-
-    if(ang >= 0 && ang<= 30){
-      new_ang = ang;
-     //new_config = {new_ang, 3,2,1};
-      ptr[0] = new_ang;
-      ptr[1] = -3;
-      ptr[2] = 2;
-      ptr[3] = -1;
-
-    }
-     else if(ang > 330 && ang<= 360){
-      new_ang = ang;
-     //new_config = {new_ang, 3,2,1};
-      ptr[0] = new_ang - 360;
-      ptr[1] = -3;
-      ptr[2] = 2;
-      ptr[3] = 1;
-
-    }
-    else if (ang > 30 && ang <= 90){
-     new_ang = ang - 60;
-    //new_config = {new_ang, -2,-1,3};
-     ptr[0] = new_ang;
-      ptr[1] = 2;
-      ptr[2] = -1;
-      ptr[3] = -1*(new_ang/abs(new_ang))*3;
-    }
-    else if (ang > 90 && ang <= 150){
-      new_ang = ang - 120;
-     //new_config = {new_ang, 3,1,2};
-      ptr[0] = new_ang;
-      ptr[1] = 3;
-      ptr[2] = -1;
-      ptr[3] = -1*(new_ang/abs(new_ang))*2;
-    }
-    else if(ang > 150 && ang<= 210){
-      new_ang = ang - 180;
-     // new_config = {new_ang, -3,-2,1};
-      ptr[0] = new_ang;
-      ptr[1] = 3;
-      ptr[2] = -2;
-      ptr[3] = -1*(new_ang/abs(new_ang))*1;
-    }
-    else if(ang > 210 && ang<= 270){
-      new_ang = ang - 240;
-     // new_config = {new_ang, 2,1,3};
-      ptr[0] = new_ang;
-      ptr[1] = -2;
-      ptr[2] = 1;
-      ptr[3] = -1*(new_ang/abs(new_ang))*3;
-    }
-    else if(ang > 270 && ang<= 330){
-      new_ang = ang - 300;
-     // new_config = {new_ang, -3,-1,2};
-      ptr[0] = new_ang;
-      ptr[1] = -3;
-      ptr[2] = 1;
-      ptr[3] = -1*(new_ang/abs(new_ang))*2;
-     }
-
-
- return 0;
-
-
-}
-
-//float Relative_ang(float ang){
-// //float a,b,c,d;
-// float new_config[4]={0,0,0,0};
-// float *ptr[4];
-//  float new_ang;
-//
-//
-//     if((ang > 330 && ang<= 360) || (ang >= 0 && ang<= 30)){
-//       new_ang = ang;
-//      new_config = {new_ang, 3,2,1};
-//        a= new_ang;
-//
-//
-//     }
-//     else if (ang > 30 && ang <= 90){
-//      new_ang = ang + 300;
-//     new_config = {new_ang, -2,-1,3};
-//     }
-//     else if (ang > 90 && ang <= 150){
-//       new_ang = ang + 240;
-//      new_config = {new_ang, 3,1,2};
-//     }
-//     else if(ang > 150 && ang<= 210){
-//       new_ang = ang + 180;
-//      new_config = {new_ang, -3,-2,1};
-//     }
-//     else if(ang > 210 && ang<= 270){
-//       new_ang = ang + 120;
-//      new_config = {new_ang, 2,1,3};
-//     }
-//     else if(ang > 270 && ang<= 330){
-//       new_ang = ang + 60;
-//      new_config = {new_ang, -3,-1,2};
-//      }
-//
-//  for(int i = 0; i < 4; i++){
-//    ptr[i] = &new_config[i]; // assign the address of integer.
-//  }
-//  return **ptr;
-//
-//
-//}
-
-
-
-void Lets_Move(double ang, int tot_spd, int comp){
-float Motor_2;
-float Motor_1;
-
-  Motor_2 = ((((-1/sqrt(3))*tan((ang/180)*M_PI))-1)*(tot_spd/(1/cos((ang/180)*M_PI))));
-  Motor_1 = -1*((((1/sqrt(3))*tan((ang/180)*M_PI))-1)*(tot_spd/(1/cos((ang/180)*M_PI))));
-  Serial.println("-----------------------");
-  Serial.println("-----------------------");
-  Serial.print("Motor 1 Speed:");
-  Serial.println(Motor_1);
-  Serial.print("Motor 2 Speed:");
-  Serial.println(Motor_2);
-
- motospd(comp,Motor_1,Motor_2); //At Min Speed, set compensator to 18.
- delay(1000);
-}
-
-// Just a mini test cycle to try and visualize each station without having to wait
-// the actual time it takes for lighting or getting CO2 or whatever its doing
-void test_cycle() {
-  delay(2000);   //waits 2 seconds
-  getWater(1);   //gets water for a minute
-  delay(1000);   //waits 10 seconds
-  Serial.println("preparing to measure moisture");
-  Serial1.write('M');
-  delay(1000);   //waits 1 second
-  delay(1000);                  //turn on lights
-  Serial3.println("7H2");
-  delay(3000); //waits 3 seconds
-  light1_state = true;
-  getSun();
-  Serial3.println("7H1");
-  delay(120000);
-  Serial3.println("7H2");
-  delay(3000);
-  light1_state = true;
-  getSun();
-  Serial3.println("7H1");
-  delay(120000);
-  getCO2(1);
-
-}
-
-// cycle for the entire day
-void day_cycle() {
-  getWater(1);
-  delay(500);
-  Serial.println("preparing to measure moisture");
-  Serial1.write('M');
-
-  // measure after getting water, then again 2 full cycles later
-  for (int i = 0; i < 7; i++) {
-    delay(100);
-    mini_cycle();
-    delay(100);
-    if (i == 2) {
-      Serial.println("preparing to measure moisture");
-      Serial1.write('M');
-    }
-    delay(100);
-  }
-}
-
-//run the full 5 light cycle then get CO2
-void mini_cycle() {
-  light_cycle();
-  delay(2000);
-  getCO2(30);
-  delay(500);
-}
-
-// single light cycle just gets light once then sits
-void light_cycle() { //cycling light
-  for (int i = 0; i < 5; i++) {
-    light_loop();
-    delay(1800000);       //no sun for 30 min
-    motospd(30, 30, 30);  // after getting in a lit position
-    delay(1100);          // rotate a little after each cycle
-    motospd(0, 0, 0);     // to try and be more distributed
-  }
-}
-
-void light_loop() {
-  delay(50);                  //turn on lights
-  Serial3.println("7H3");
-  delay(3000);
-  light1_state = true;   //light is on now because it is true
-  getSun();
-  Serial3.println("7H5");
-  delay(300000);          //get sun for 5 min
-}
-
-void getWater(int water_time) { //time to get water in minutes
-  find_red1();   //indicator for detecting
-  delay(1000);
-  String msg = "5H";
-  msg = msg + water_time;
-  Serial3.println(msg);
-  water_state = true;
-  delay(water_time * 30000);
-  Serial3.println("5L");
-  delay(2000);
-  water_state = false;
-  delay(2000);
-  backAwayFromRed();
-}
-
-void getCO2(int CO2_time) {   // time to sit in CO2 cage in minutes
-  find_green1();
-  delay(1000);
-  String msg = "4H";
-  msg = msg + CO2_time;
-  Serial3.println(msg);  //writes to arduino
-  CO2_state = true;
-  delay(60000);
-  delay(CO2_time * 60000);
-  delay(2000);
-  delay(60000);
-  CO2_state = false;
-  backAwayFromGreen();
-}
-
-void find_red1() {   // parent function to call recursive functions and talk to BASE
-  // turn on the lights temporarily for tracking
-  Serial.println("Searching for red");
-  delay(1000);
-  Serial3.println("6H3");
-  delay(50);
-  light2_state = true;
-
-  digitalWrite(motor_relay, LOW); //turn motors on
-  delay(250);
-
-  find_red2();       // locate, center, and approach target
-  horizontalCenter();// horiztonally center along the wall
-  adjustRed();       // adjust distance to wall to line up with water faucet
-
-  digitalWrite(motor_relay, HIGH); //turn motors off
-  delay(100);
-  Serial3.println("6L");
-  delay(1000);
-}
-
-void find_red2() {
-  motospd(20, 20, 20);    // spin until red is detected
-  locate_red();
-  Serial.println("red detected");
-  /*
-    centerObject2(1);    // center with target
-
-    delay(50);
-
-    static int i = 0;  //only can be changed outside the global scope; can't be changed in a for loop
-    int j;
-    uint16_t blocks;   //allocated integer of 16 bits
-    char buf[32];    //character
-    int32_t xError;
-    blocks = pixy.getBlocks(17);
-
-    int height = pixy.blocks[0].height;;
-    Serial.print("height:  ");
-    Serial.println(height); //prints the height of the variable height
-
-    double dist_away = 1866.0 / height;    // use height to get distance
-    //distance away in inches
-
-    if (dist_away > 100 || dist_away < 0) {      // throw out error when pixy picks up
-     motospd(max_speedR,max_speedR,max_speedR); // small background objects
-     delay(500);
-     motospd(0,0,0);  //not moving
-     find_red2();
-     return;
-    }
-    Serial.print("distance away:  ");
-    Serial.println(dist_away);
-
-    pixyRun2(dist_away, 1);    //approach target
-    delay(10);*/
-}
-
-void locate_red() {    //spin and refresh camera until red is detected
-  static int i = 0;
-  int j;
-  uint16_t blocks;
-  char buf[32];
-  int32_t xError;
-  blocks = pixy.getBlocks(17);
-
-  for (int k = 0; k < blocks; k++) {
-    Serial.println("for loop started");
-    if (pixy.blocks[k].signature == 1) {
-      Serial.println("found block");
-      delay(500);
-      motospd(0, 0, 0);
-      delay(5000);
-      return;
-    }
-  }
-  delay(50);
-  locate_red();
-}
-
-void backAwayFromRed() {     // back away from red wall before performing next task
-  digitalWrite(motor_relay, LOW); //low means on in this case
-  delay(250);
-
-  motospd(0, -max_speed, max_speed);
-  delay(2000);
-  motospd(0, 0, 0);
-
-  digitalWrite(motor_relay, HIGH);
-}
-
-void pixyAlignRed() {     //align straight with the red target
-  Serial.println("Aligning with object");
-  updateSonar();
-  delay(100);
-  updateSonar();
-  sonarInfoDisplay();
-
-  if (abs(cm[0] - cm[1]) < 2) { //spin left or right based on sonar values
-    Serial.println("Aligned");
-    return;
-  } else if (cm[0] > cm[1]) {
-    motospd(40, 10, 10);
-    delay(250);
-    motospd(0, 0, 0);
-    delay(100);
-    pixyAlignRed();
-  } else {
-    motospd(-40, -10, -10);
-    delay(250);
-    motospd(0, 0, 0);
-    delay(100);
-    pixyAlignRed();
-  }
-}
-
-void adjustRed() {   // adjust distance from red to line up with water faucet
-  Serial.println("adjusting");
-  updateSonar();
-  delay(100);
-  updateSonar();
-
-  double adjust = 24 - ((cm[0] + cm[1]) / 2.0);
-  Serial.print("adjust distance: ");
-  Serial.println(adjust);
-
-  if (adjust > 0) {  // move forward or backward based on sonar
-    motospd(0, -max_speed, max_speed);
-    double adjustTime = adjust / 2.54 / 11 * 1000;
-    delay(adjustTime);
-    motospd(0, 0, 0);
-  } else {
-    adjust = -adjust;
-    motospd(0, max_speed, -max_speed);
-    double adjustTime = adjust / 2.54 / 11 * 1000;
-    delay(adjustTime);
-    motospd(0, 0, 0);
-  }
-}
-
-void horizontalCenter() {   // center left or right along the wall to line up with water
-  Serial.println("horizontally center/align to object");
-
-  static int i = 0;
-  int j;
-  uint16_t blocks;
-  char buf[32];
-  int32_t xError;
-  blocks = pixy.getBlocks(17);
-
-  int center = pixy.blocks[0].x;    // use pixy x-axis center function to line it up
-  Serial.print("center: ");
-  Serial.println(center);
-
-  if (abs(center - 150) < 5) {
-    Serial.println("hor. centered with the object - ready for dist. adjust");
-    return;
-  } else if (center < 150) {
-    Serial.println("hor. center - moving left");
-    for (int i = 0; i < 3; i++) {
-      wheel_speed[i] = max_speed * newCos(wheel_angles[i] - 90);
-    }
-    motorWrite();
-    delay(200);
-    motospd(0, 0, 0);
-    delay(1000);
-    horizontalCenter();
-  } else {
-    Serial.println("hor. center - moving right");
-    for (int i = 0; i < 3; i++) {
-      wheel_speed[i] = max_speed * newCos(wheel_angles[i] - 270);
-    }
-    motorWrite();
-    delay(200);
-    motospd(0, 0, 0);
-    delay(1000);
-    horizontalCenter();
-  }
-
-}
-
-void find_green1() {   // parent function to call recursive functions and talk to BASE
-  delay(1500);           // turn on lights temporarily for color tracking
-  Serial3.println("6H5");
-  delay(1000);
-  light2_state = true;
-
-  digitalWrite(motor_relay, LOW);
-  delay(250);
-
-  find_green2();       // locate, center, and approach green
-  horizontalCenterGreen();   // hor line up to object before adjust
-  adjustGreen();       // adjust distance to green to line up with CO2 cage
-
-  digitalWrite(motor_relay, HIGH);
-  delay(100);
-  Serial3.println("6L");
-  delay(1000);
-}
-
-//recursive function to narrow in on the green
-void find_green2() {
-  motospd(-max_speedR, -max_speedR, -max_speedR);    //spin until green is detected
-  delay(300);
-  locate_green();
-  Serial.println("green detected");
-
-
-  centerObject2(3);    // center with green
-
-  delay(50);
-
-  static int i = 0;
-  int j;
-  uint16_t blocks;
-  char buf[32];
-  int32_t xError;
-  blocks = pixy.getBlocks(17);
-
-  int height;
-  //height = pixy.blocks[0].height;
-
-  if (blocks == 1) {
-    height = pixy.blocks[0].height;
-  } else {
-    height = pixy.blocks[1].height;
-  }
-
-  Serial.print("height:  ");
-  Serial.println(height);
-
-  double dist_away = 1800.0 / height;    // use height to find distance away
-  //distance away in inches
-
-  if (dist_away > 100 || dist_away < 0) {  //get rid of background noise detection errors
-    find_green2();
-    return;
-  }
-  Serial.print("distance away:  ");
-  Serial.println(dist_away);
-
-  pixyRun2(dist_away, 3);    // approach target
-  delay(10);
-}
-
-void locate_green() {  //spin and refresh camera until green is detected
-  static int i = 0;
-  int j;
-  uint16_t blocks;
-  char buf[32];
-  int32_t xError;
-  blocks = pixy.getBlocks(17);
-
-  for (int k = 0; k < blocks; k++) {
-    if (pixy.blocks[k].signature == 3) {
-      delay(300);
-      motospd(0, 0, 0);
-      return;
-    }
-  }
-  delay(50);
-  locate_green();
-}
-
-void centerObject2(int color_num) {    // recursive center with target
-
-  Serial.println("centering");
-  delay(50);
-
-  static int i = 0;
-  int j;
-  uint16_t blocks;
-  char buf[32];
-
-  blocks = pixy.getBlocks(17);
-
-  int block_num;
-  int error;  //error if you do not input 1 or 0
-  if (blocks) {
-
-    if (color_num == 1) {
-      block_num = 0;
-    } else {
-      if (blocks == 1) {
-        block_num = 0;
-      } else {
-        block_num = 1;
-      }
-    }
-
-    int height = pixy.blocks[block_num].height;
-    if (height < 10) {
-      if (color_num == 1) {
-        find_red2();
-      } else {
-        find_green2();
-      }
-      return;
-    }
-
-    uint32_t center = pixy.blocks[block_num].x;    // use x-axis center function to align
-    error = X_CENTER - center;                     // robot with target
-    Serial.print("center: ");
-    Serial.print(center);
-    Serial.print("   error: ");
-    Serial.println(error);
-  }
-
-  if (abs(error) < 10) {
-    Serial.println("centered");    // <10 is good enough alignment with margin of error
-    return;
-  }
-
-  int spin_time = abs(error) * 4.5;    // spin time based on size of center error
-  Serial.print("Spin Time:  ");
-  Serial.println(spin_time);
-
-  if (error >= 0) {
-    motospd(max_speedR, max_speedR, max_speedR);
-  } else {
-    motospd(-max_speedR, -max_speedR, -max_speedR);
-  }
-  delay(spin_time);
-  motospd(0, 0, 0);
-
-  centerObject2(color_num);    //recursive call to improve accuracy
-}
-
-void pixyRun2(double dist_away, int color_num) {   //approach target
-  if (anyCollision(5)) {  // if theres a collision, move away
-    getAwayFromWall();
-    if (color_num == 1) {
-      find_red2();
-      return;
-    } else if (color_num == 3) {
-      find_green2();
-      return;
-    }
-  }
-  if (color_num == 1) {    // distance for red is 15 in
-    if (dist_away < 15) {
-      pixyAlignRed();
-      return;
-    }
-  } else if (color_num == 3) { //distance for green is 20 in
-    if (dist_away < 20) {
-      pixyAlignGreen();
-      return;
-    }
-  }
-
-  double approach_time = dist_away / 11 * 1000.0;  // approach time based on distance
-  motospd(0, max_speed, -max_speed);
-  if (color_num == 1) {
-    delay(approach_time / 3.0);    // move part of the way
-  } else if (color_num == 3) {
-    delay(approach_time / 3.0);
-  }
-  motospd(0, 0, 0);
-  delay(10);
-
-  if (color_num == 3) {  //recursive call to continue process
-    delay(50);
-    find_green2();
-  } else if (color_num == 1) {
-    delay(50);
-    find_red2();
-  }
-}
-
-void backAwayFromGreen() {
-  digitalWrite(motor_relay, LOW);
-  delay(250);
-
-  motospd(0, -max_speed, max_speed);
-  delay(4500);
-  motospd(0, 0, 0);
-
-  digitalWrite(motor_relay, HIGH);
-}
-
-void pixyAlignGreen() { //align robot with green to line up with CO2 cage
-  Serial.println("Aligning with object");
-  updateSonar();
-  sonarInfoDisplay();
-
-  if (abs(cm[0] - cm[1]) < 3) { // move left or right based on sonar
-    return;
-  } else if (cm[0] > cm[1]) {
-    motospd(40, 10, 10);
-    delay(300);
-    motospd(0, 0, 0);
-    delay(100);
-    pixyAlignGreen();
-  } else {
-    motospd(-40, -10, -10);
-    delay(300);
-    motospd(0, 0, 0);
-    delay(100);
-    pixyAlignGreen();
-  }
-}
-
-void horizontalCenterGreen() {   // center left/right along the wall to line up with water
-  Serial.println("horizontally center/align to object");
-
-  static int i = 0;
-  int j;
-  uint16_t blocks;
-  char buf[32];
-  int32_t xError;
-  blocks = pixy.getBlocks(17);
-
-  int center = pixy.blocks[0].x;    // use pixy x-axis center function to line it up
-  Serial.print("center: ");
-  Serial.println(center);
-
-  if (abs(center - 150) < 5) {
-    Serial.println("hor. centered with the object - ready for dist. adjust");
-    return;
-  } else if (center < 150) {
-    Serial.println("hor. center - moving left");
-    for (int i = 0; i < 3; i++) {
-      wheel_speed[i] = max_speed * newCos(wheel_angles[i] - 90);
-    }
-    motorWrite();
-    delay(200);
-    motospd(0, 0, 0);
-    delay(1000);
-    horizontalCenterGreen();
-  } else {
-    Serial.println("hor. center - moving right");
-    for (int i = 0; i < 3; i++) {
-      wheel_speed[i] = max_speed * newCos(wheel_angles[i] - 270);
-    }
-    motorWrite();
-    delay(200);
-    motospd(0, 0, 0);
-    delay(1000);
-    horizontalCenterGreen();
-  }
-}
-
-
-void adjustGreen() {   // adjust distance to green to line up with CO2 cage
-  updateSonar();
-
-  double adjust = 48 - ((cm[0] + cm[1]) / 2.0);
-  if (adjust > 0) {  // move forward or backward based on sonar
-    motospd(0, -max_speed, max_speed);
-    double adjustTime = adjust / 2.54 / 11 * 1000;
-    delay(adjustTime);
-    motospd(0, 0, 0);
-  } else {
-    adjust = -adjust;
-    motospd(0, max_speed, -max_speed);
-    double adjustTime = adjust / 2.54 / 11 * 1000;
-    delay(adjustTime);
-    motospd(0, 0, 0);
-  }
-}
-
-void getSun() {  // find light
-  digitalWrite(motor_relay, LOW); //turn on the motor
-
-  updateSolar();
-  delay(100);
-  solarInfoDisplay();
-
-  if (evenSun()) {  // if its evenly distributed in the sun then its done
-    digitalWrite(motor_relay, HIGH);
-    return;
-  }
-
-  double solar_angle = getSolarAngle();  //get angle of light
-  Serial.print("Solar Angle:  ");
-  Serial.println(solar_angle);
-
-  delay(2000);
-
-  rotateToLight2(solar_angle);  //rotate "front" of robot towards that solar angle
-
-  solarRun(solar_angle);    // approach light
-
-}
-
-//calculate the solar angle in degree by
-//using all 3 solar vectors the outcome
-//ranges from 0degree to 360degree
-double getSolarAngle() {
-  double x = 0;
-  double y = 0;
-  for (int i = 0; i < 9; i++) {
-    x += solar[i] * newCos(solar_angles[i]);
-    y += solar[i] * newSin(solar_angles[i]);
-  }
-  return newAtan(x, y);
-}
-
-// see if all the solar sensors are within range of each other
-// to see if its evenly distributed
-boolean evenSun() {
-  for (int i = 0; i < 9; i++) {
-    for (int j = i + 1; j < 9; j++) {
-      if (abs(solar[i] - solar[j]) > 250) {
-        return false;
-      }
-    }
-  }
-  return true;
-}
-
-void rotateToLight(double solar_angle) {   //rotate towards the given angle
-
-  double rotationAngle = solar_angle - 90;
-  if (rotationAngle < 0) {
-    rotationAngle += 360;
-  }
-
-  double spinTime = rotationAngle * 13000 / 360;
-  Serial.print("spin time :");
-  Serial.println(spinTime);
-
-  motospd(max_speedR, max_speedR, max_speedR);
-  delay(spinTime);
-  motospd(0, 0, 0);
-
-  if (anyCollision(25)) {
-    motospd(0, -max_speed, max_speed);
-    delay(500);
-    motospd(0, 0, 0);
-  }
-  delay(50);
-}
-
-void rotateToLight2(double solar_angle) {   // rotate to the solar angle
-  if (solar_angle >= 90 && solar_angle <= 270) {  // if its in this half of the circle,
-    double rotationAngle = solar_angle - 90;      // then rotate CCW
-
-    double spinTime = rotationAngle * 13000 / 360;
-    Serial.print("spin time :");
-    Serial.println(spinTime);
-
-    motospd(max_speedR, max_speedR, max_speedR);
-    delay(spinTime);
-    motospd(0, 0, 0);
-  } else {               // if its in the other half of the circle, then rotate CW
-    double rotationAngle;
-    if (solar_angle < 90) {
-      rotationAngle = 90 - solar_angle;
-    } else {
-      rotationAngle = 90 + (360 - solar_angle);
-    }
-    double spinTime = rotationAngle * 13000 / 360;
-    Serial.print("spin time :");
-    Serial.println(spinTime);
-
-    motospd(-max_speedR, -max_speedR, -max_speedR);
-    delay(spinTime);
-    motospd(0, 0, 0);
-  }
-
-  if (anyCollision(25)) {  //check for collision before moving forward
-    motospd(0, -max_speed, max_speed);        // and move away if needed
-    delay(500);
-    motospd(0, 0, 0);
-  }
-  delay(50);
-}
-
-void solarRun(double solar_angle) {   // movement in the light
-
-  if (anyCollision(20)) {  //check for collision before moving
-    Serial.println("Moving away from wall");
-    getAwayFromWall();
-  }
-  boolean done = false;
-  updateSolar();
-  solarInfoDisplay();
-  for (int i = 0; i < 9; i++) {
-    if (solar[i] < 300) {
-      Serial.println("Moving towards the light");
-      solarRun2();               // solarRun2 moves toward the lighted area
-      done = true;               // if some sensors are too low
-      break;
-    }
-  }
-  if (!done) {
-    Serial.println("Attempting to center in the light");
-    solarRun3(solar_angle);  //already in the lighted are, so solarRun3
-  }                          //tries to center itself better in the light
-}
-
-// move towards the lighted area
-void solarRun2() {
-
-  updateSonar();
-  if (anyCollision(25)) {
-    getAwayFromWall();
-  }
-  motospd(0, max_speed, -max_speed); // its already facing the right direction
-  delay(1000);                     // so it just moves forward
-  motospd(0, 0, 0);
-
-  delay(2000);
-
-  getSun();    //recursive call to improve accuracy
-}
-
-void solarRun3(double solar_angle) { // centering in the lighted area
-  int min = 0;
-  for (int i = 1; i < 9; i++) { // find the smallest light sensor
-    if (solar[i] < solar[min]) {
-      min = i;
-    }
-  }
-  double back_theta = solar_angles[min] - 180; //move away from the smallest one
-  for (int i = 0; i < 3; i++) {
-    wheel_speed[i] = max_speed * newCos(wheel_angles[i] - back_theta);
-  }
-  motorWrite();
-  delay(1000);
-  motospd(0, 0, 0);
-
-  getSun();    // recursive call
-}
-
-boolean anyCollision(int distance_cm) { // check for a collision within a certain distance
-  updateSonar();                        // using the sonar in the front
-  sonarInfoDisplay();
-  for (int i = 0; i < 2; i++) {
-    if (cm[i] < distance_cm && cm[i] > 1) {
-      return true;
-    }
-  }
-  return false;
-}
-
-boolean anyCollision2() {   //check for a close range collision using the IR sensors
-  updateIRprox();
-  delay(50);
-  for (int i = 0; i < 4; i++) {
-    if (IR_proximity_state[i] < 524) {
-      return true;
-    }
-  }
-  return false;
-}
-
-void getAwayFromWall() {   //uses the IR sensors to move away from a detected obstacle
-  int sensorNum = colliSensorNumFeedback();
-  colliFeedbackMotion(sensorNum);
-}
-
-//give the number of the sensor which detected the obstacle
-int colliSensorNumFeedback() {
-  delay(50);
-  updateIRprox();
-  for (int i = 0; i < 4; i++) {
-    if (IR_proximity_state[i] < 300) {
-      Serial.print("backward_sensor:");
-      Serial.print(i);
-      Serial.println( );
-      return i;
-    }
-  }
-  Serial.println("No_backward_sensor");
-  return -1;
-}
-
-// uses the number of the obstacle sensor to move away from that direction
-void colliFeedbackMotion(int sensor_num) {
-  int num = sensor_num;
-  if (num == 0) {
-    motospd(-max_speed, 0, max_speed);
-    delay(2000); //backward 2s
-    motospd(0, 0, 0);
-    delay(10);
-  } else if (num == 1 || num == 2) {
-    motospd(0, -max_speed, max_speed);
-    delay(2000); //backward 2s
-    motospd(0, 0, 0);
-    delay(10);
-  } else if (num == 3) {
-    motospd(max_speed, -max_speed, 0);
-    delay(2000); //backward 2s
-    motospd(0, 0, 0);
-    delay(10);
-  } else {
-    return;
-  }
-}
-
-//writes motor speed values to motor
-// used to move in obscure directions
-void motorWrite() {
-  for (int i = 0; i < 3; i++) {
-    if (wheel_speed[i] < 0) {
-      digitalWrite(wheel_direction[i], LOW);
-    } else {
-      digitalWrite(wheel_direction[i], HIGH);
-    }
-    analogWrite(wheel_pwm[i], abs(wheel_speed[i]));
-  }
-}
-
-//direct way to assign values to motors
-//used for easy angles
-void motospd(int sp1, int sp2, int sp3) {
-  if (sp1 > 0) {
-    digitalWrite(wheel_direction[0], HIGH);
-  } else {
-    digitalWrite(wheel_direction[0], LOW);
-  }
-  if (sp2 > 0) {
-    digitalWrite(wheel_direction[1], HIGH);
-  } else {
-    digitalWrite(wheel_direction[1], LOW);
-  }
-  if (sp3 > 0) {
-    digitalWrite(wheel_direction[2], HIGH);
-  } else {
-    digitalWrite(wheel_direction[2], LOW);
-  }
-  analogWrite(wheel_pwm[0], abs(sp1));
-  analogWrite(wheel_pwm[1], abs(sp2));
-  analogWrite(wheel_pwm[2], abs(sp3));
-}
-
-//display updated wheel speed values
-void speedInfoDisplay() {
-  Serial.print("Speed Display: ");
-  for (int i = 0; i < 3; i++) {
-    Serial.print(wheel_speed[i]);
-    Serial.print("|");
-  }
-  Serial.println(" ");
-  Serial.println(" ");
-  delay(10);
-}
-
-//math tool
-//return the cosine value for an angle in degree
-double newCos(double phi) {
-  return cos(phi * M_PI / 180);
-}
-
-//return the sine value for an angle in degree
-double newSin(double phi) {
-  return sin(phi * M_PI / 180);
-}
-
-//return the tan value when you input y and x;
-//the outcome ranges from 0 to 360 degrees
-double newAtan(double x, double y) {
-  double theta = atan(y / x) * 180 / M_PI;
-  if (x < 0) {
-    return theta + 180;
-  } else if (y < 0) {
-    return theta + 360;
-  } else {
-    return theta;
-  }
-}
-
-//update solar panel values
-void updateSolar() {
-  for (int i = 0; i < 9; i++) {
-    solar[i] = analogRead(solar_pins[i]);
-    delay(50);
-  }
-}
-
-//display updated solar panel values
-void solarInfoDisplay() {
-  Serial.println("Solar Display: ");
-  for (int i = 0; i < 9; i++) {
-    Serial.print("Solar Pin ");
-    Serial.print(i);
-    Serial.print(" : ");
-    Serial.print(solar[i]);
-    Serial.print("     ");
-    delay(50);
-
-    Serial.println();
-  }
-}
-
-//update sonar sensor values in terms of distance
-void updateSonar() {
-  for (int i = 0; i < 6; i++) {
-    //cm[i]=sonar[i].ping_cm();
-    unsigned int uS = sonar[i].ping();
-    cm[i] = sonar[i].convert_cm(uS);
-    delay(50);
-
-    Serial.println(cm[i]);
-
-
-
-  }
-}
-
-//display updated sonar sensor values
-void sonarInfoDisplay() {
-  Serial.println("Distance Display: ");
-  for (int i = 0; i < 6; i++) {
-    Serial.print("Sonar Pin ");
-    Serial.print(i);
-    Serial.print(" : ");
-    Serial.println(cm[i]);
-  }
-  delay(50);
-}
-
-// update IR sensor states
-void updateIRprox() {
-  for (int i = 0; i < 4; i++) {
-    IR_proximity_state[i] = analogRead(IR_proximity_pins[i]);
-    delay(50);
-  }
-  delay(100);
-}
-
-// print updates IR sensor values
-void IRProxInfoDisplay() {
-  Serial.println("Proximity Display: ");
-  for (int i = 0; i < 4; i++) {
-    Serial.print("IR Pin ");
-    Serial.print(i);
-    Serial.print(" : ");
-    Serial.println(IR_proximity_state[i]);
-  }
-  delay(100);
-}
-
-


instrument sequences integrated

instrument sequences integrated

--- msgSeq/msgSeq.ino
+++ msgSeq/msgSeq.ino
@@ -1,7 +1,7 @@
 #include <Process.h>

-String hashTags[] = {"PS", "BD", "SD", "KI", "SN", "CR", "I1", "I2"};
-//PS: play sample, BD: bass drum, SD: snare, KI: kick,SN: snare, CR: crash
+String hashTags[] = {"PS", "BD", "SD", "KI", "CB", "CR", "I1", "I2"};
+//PS: play sample, BD: bass drum, SD: snare, KI: kick,CB: cowbell, CR: crash
 //I1: instrument 1, I2: instrument 2
 // marker // TODO
 const int DRUMSSTART = 1;
@@ -11,7 +11,7 @@
 const int EFFECTSTART = 8;
 const int EFFECTEND = 10;
 //
-const int numIns = 6;
+const int numIns = 8;
 byte patterns[numIns - 1];
 // length
 const int patternL = 8;
@@ -27,24 +27,26 @@
 // sequence-bits
 int bs[] = {1, 2, 4, 8, 16, 32, 64, 128, 256};

-int instrument_1_seq[8];
-int instrument_2_seq[8];
+int instrument_seq[2][8];

 const String sampleFolder = "/mnt/twitterOrchestra/samples/";

 void setup() {
-  Bridge.begin();
+//  Bridge.begin();
   Serial.begin(9600);
-  while (!Serial);
+//  while (!Serial);
   String msg = "#BD 10001000";
   parseMessage(msg);
   String msg2 = "#SD 01010101";
   parseMessage(msg2);
-  String msg3 = "#KI 10001010";
+
+  String msg3 = "#I1 51.37.10.40.53.30.16.49";
   parseMessage(msg3);
-  String msg4 = "#CR 01000000";
-  parseMessage(msg4);
-
+  /*  String msg3 = "#KI 10001010";
+    parseMessage(msg3);
+    String msg4 = "#CR 01000000";
+    parseMessage(msg4);
+  */
   nextBInc = MINUTE / bpm;
 }

@@ -52,31 +54,45 @@
   unsigned long time = millis();
   if (time > nextB) {
     nextB += nextBInc;
-    for (int i = 1; i < numIns; i++) {
+
+    for (int i = DRUMSSTART; i <= DRUMSEND; i++) {
       if (patterns[i - 1] & bs[pos])
         Serial.print(hashTags[i]);
       else
         Serial.print("..");
       Serial.print("-");
     }
+    Serial.print("  ");
+    Serial.print(instrument_seq[0][pos]);
+    Serial.print("-");
+    Serial.print(instrument_seq[1][pos]);
+    Serial.print("  ");
     Serial.println("");
+
+
     pos = (pos + 1) % patternL;
   }
 }

 void parseMessage(String msg) {
   int hashInd = msg.indexOf('#');
-  // instrument
   if (hashInd == -1)
     return;
   int tag = 0;
   String s = msg.substring(hashInd + 1, hashInd + 3);
+  boolean found;
   for (int i = 0; i < numIns; i++) {
     if (s == hashTags[i]) {
       tag = i;
       Serial.println(s);
+      found = true;
       break;
     }
+  }
+  if (!found) {
+    Serial.print("wrong tag ");
+    Serial.println(s);
+    return;
   }
   if (tag == 0)
     playSample(msg.substring(hashInd + 4));
@@ -84,7 +100,8 @@
     String pa = msg.substring(hashInd + 4, hashInd + 4 + patternL);
     drums(tag - DRUMSSTART, pa);
   } else if (tag >= INSTRUMENTSTART && tag <= INSTRUMENTEND) {
-
+    String pa = msg.substring(hashInd + 4);
+    instrument(tag - INSTRUMENTSTART, pa);
   }
 }

@@ -104,12 +121,24 @@
     return;
   }
   byte pattern = 0;
-  Serial.println(patternS);
+  //  Serial.println(patternS);
   for (int i = 0; i < patternL; i++) {
     pattern = pattern << 1;
     byte b = patternS.charAt(i) == '1' ? 1 : 0;
     pattern += b;
   }
-  Serial.println(pattern);
+  //  Serial.println(pattern);
   patterns[tag] = pattern;
 }
+
+void instrument(int tag, String pattern) {
+  //  Serial.println(pattern);
+  for (int i = 0; i < patternL; i++) {
+    Serial.println(pattern.substring(0, 2));
+    instrument_seq[tag][i] = pattern.substring(0, 2).toInt();
+    pattern = pattern.substring(3);
+  }
+  for (int i = 0; i < patternL; i++)
+    Serial.println(instrument_seq[tag][i]);
+}
+


Modified getResponse function to receive packet buffer as parameter

--- module/module.ino
+++ module/module.ino
@@ -34,7 +34,7 @@
 void loop() {
 	bool responseFlag = false;
 	unsigned long elapsedTime = 0;
-	unsigned char readData[bufferSize/2];
+	unsigned char readData[bufferSize];
 	digitalWrite(ledPin, LOW);

 	// Scan for RFID tags
@@ -42,14 +42,15 @@
 		MF_SNR();
 		delay(200);
 		// getResponse determines if the response packet is OK
-		responseFlag = getResponse();
+		responseFlag = getResponse(readData);
 	}

 	// RFID tag detected, read block that contains time data
 	digitalWrite(ledPin, HIGH);
 	MF_READ(0x01, 0x05);
 	delay(200);
-	responseFlag = getResponse();
+	responseFlag = getResponse(readData);
+	// Analyze data
 	if(responseFlag == false) Serial.println("Unexpected result");

 	// Get ready to accumulate time
@@ -58,12 +59,12 @@
 	// Write time data to card
 	MF_WRITE(0x01, 0x05, elapsedTime);
 	delay(200);
-	responseFlag = getResponse();
+	responseFlag = getResponse(readData);
 	if(responseFlag == false) Serial.println("Unexpected result");

 }

-bool getResponse(unsigned char ) {
+bool getResponse(unsigned char response[]) {
 	int i = 0;
 	// buffer for response packet
 	unsigned char response[bufferSize];


Debug functions added

Debug functions added

--- module/module.ino
+++ module/module.ino
@@ -151,9 +151,8 @@
 	unsigned char serialNumber[bufferSizeSNR];
 	unsigned long startTime, elapsedTime = 0;
 	unsigned int periodX, periodY;
-	unsigned int lastPeriodX, lastPeriodY;
-	unsigned int pulseCount = 0;
-	unsigned int pollCounter = 0;
+	//unsigned int lastPeriodX, lastPeriodY;
+	unsigned int pulseCount, pollCounter = 0;
 	int i = 0;
 	bool signals[sampleSize];

@@ -281,8 +280,13 @@
 	}
 	//delay(1);
   	//Serial.print(signals[0]); Serial.print(signals[1]); Serial.print(signals[2]); Serial.print(" ");
-	Serial.print(numValid); Serial.print(numInvalid);
-	Serial.print(" ");
+	if (debug) {
+		Serial.print(numValid); Serial.print(numInvalid);
+		Serial.print(" ");
+	}
+	else {
+		delay(1);
+	}

 	if (numValid == sampleSize) {
 		return flag.detectedJobStart;


Use TimerThree library to blink motor

Use TimerThree library to blink motor

--- usbvibration/usbvibration.ino
+++ usbvibration/usbvibration.ino
@@ -1,59 +1,16 @@
-// https://github.com/thomasfredericks/Metro-Arduino-Wiring
-#include <Metro.h>
+// https://www.pjrc.com/teensy/td_libs_TimerOne.html
+#include <TimerThree.h>

-const int MOTORPIN = 2;
+const int MOTORPIN = 5;

-Metro blink = Metro(400);
-bool isVibrationOn = false;
-bool isMotorOn = false;
-uint32_t now;
-
-void onMotor(void)
-{
-    digitalWrite(MOTORPIN, HIGH);
-    isMotorOn = true;
-}
-
-void offMotor(void)
-{
-    digitalWrite(MOTORPIN, LOW);
-    isMotorOn = false;
-}
-
-void beginVibration(void)
-{
-    blink.reset();
-    isVibrationOn = true;
-}
-
-void endVibration(void)
-{
-    offMotor();
-    isVibrationOn = false;
-}
-
-void vibrationLoop(void)
-{
-    if (!isVibrationOn) {
-        return;
-    }
-    if (blink.check()) {
-        if (isMotorOn) {
-            offMotor();
-        } else {
-            onMotor();
-        }
-    }
-}
-
-void parseMessage(char letter)
+void parseMessage(int letter)
 {
     switch (letter) {
     case 'v':
-        beginVibration();
+        Timer3.pwm(MOTORPIN, 512);
         break;
     case 'V':
-        endVibration();
+        Timer3.pwm(MOTORPIN, 0);
         break;
     default:
         break;
@@ -64,26 +21,11 @@
 {
     Serial.begin(115200);
     Mouse.begin();
-    pinMode(MOTORPIN, OUTPUT);
-}
-
-static void mouseLoop()
-{
-    // move mouse to avoid screen saver
-    static uint32_t mprevms = 0;
-    const uint32_t PCLOCKMS = 540000; // 9 [min]
-    if (now - mprevms > PCLOCKMS) {
-        mprevms = now;
-        Mouse.move(1, 0, 0);
-        //Serial.write("M");
-    }
+    Timer3.initialize(400000);
 }

 void loop()
 {
-    now = millis();
-    vibrationLoop();
-    mouseLoop();
     while (Serial.available()) {
         char letter = Serial.read();
         parseMessage(letter);