## gps_time_sync_nokia5110.ino - calibrated

--- examples/gps_time_sync_nokia5110/gps_time_sync_nokia5110.ino
+++ examples/gps_time_sync_nokia5110/gps_time_sync_nokia5110.ino
@@ -143,6 +143,10 @@
 	// ATmega328p : _DEBUG = 0 or 1 : frametime for calibrate( 86, 86) = 60.000254s
 	// ATmega32u4 : _DEBUG = 0 or 1 : frametime for calibrate(-6,-6) = 59.999825s
 	wwvb_tx.setPWM_LOW(0);
+	wwvb_tx.calibrate(33,34); // 60.000017s
+	// calibration
+	//(0, 0) = 59.966523s (86, 86) = 60.052528s
+	// 60.052528/(0.086005 / 86) = 52.5249 - so calibrate to (86,86) - (53,52) = (33,34)

 	// set the timezone before you set your time
 	wwvb_tx.setTimezone(0, 0); // Default state - this line is not needed
@@ -292,25 +296,42 @@
 	}
 	else
 	{
-		nokia5110.print(gps.quality); nokia5110.print(" - ");
 		switch (gps.quality)
 		{
+		/*
 		case 1:
-			nokia5110.print("  GPS"); break;
+			nokia5110.print(" 1 - GPS "); break;
 		case 2:
-			nokia5110.print(" DGPS"); break;
+			nokia5110.print(" 2 - DGPS"); break;
 		case 3:
-			nokia5110.print(" PPS"); break;
+			nokia5110.print(" 3 - PPS "); break;
 		case 4:
-			nokia5110.print("  RTK"); break;
+			nokia5110.print(" 4 - RTK "); break;
 		case 5:
-			nokia5110.print(" fRTK"); break;
+			nokia5110.print(" 5 - fRTK"); break;
 		case 6:
-			nokia5110.print("  EST"); break;
+			nokia5110.print(" 6 - EST "); break;
 		case 7:
-			nokia5110.print("  MAN"); break;
+			nokia5110.print(" 7 - MAN "); break;
 		case 8:
-			nokia5110.print("  SIM"); break;
+			nokia5110.print(" 8 - SIM "); break;
+		*/
+		case 1:
+			nokia5110.print("      GPS"); break;
+		case 2:
+			nokia5110.print("     DGPS"); break;
+		case 3:
+			nokia5110.print("      PPS"); break;
+		case 4:
+			nokia5110.print("      RTK"); break;
+		case 5:
+			nokia5110.print("float RTK"); break;
+		case 6:
+			nokia5110.print("DEAD RECN"); break;
+		case 7:
+			nokia5110.print("   MANUAL"); break;
+		case 8:
+			nokia5110.print("SIMULATED"); break;
 		}
 	}
 	nokia5110.display();


Change to the waveform shaping trying to reduce IMD.

--- examples/PSK31-Transmit/PSK31-Transmit.ino
+++ examples/PSK31-Transmit/PSK31-Transmit.ino
@@ -45,16 +45,24 @@
   }
 }

+const uint8_t amplitudeShape[41] = {
+  255, 241, 228, 215, 203, 191, 181, 171, 161, 152, 143, 135, 128, 121, 114, 107, 101, 96, 90, 85, 80, 76, 72, 68, 64, 60, 57, 54, 51, 48, 45, 42, 40, 38, 36, 34, 32, 30, 28, 27, 25
+};
+
 // This will trigger at 8kHz
 ISR(ADC_vect) {
   static uint8_t tcnt = 0;
   TIFR1 |= _BV(ICF1);
   // Wave shaping
   PORTD |= _BV(2);
-  if(tcnt < 32)
-    dds.setAmplitude(tcnt<<3);
-  if(tcnt > (255-32))
-    dds.setAmplitude((255 - tcnt)<<3);
+  // TODO: Improve how this would perform.
+  if(tcnt < 82)
+    dds.setAmplitude(amplitudeShape[(82-tcnt)/2]);
+  if(tcnt > (255-82))
+    dds.setAmplitude(amplitudeShape[(tcnt-173)/2]);
+  //else if(tcnt > (255-64))
+  //  dds.setAmplitude((255 - tcnt));
+  //else dds.setAmplitude(255);
   dds.clockTick();
   if(tcnt++ == 0) { // Next bit
     //PORTD ^= _BV(2); // Diagnostic pin (D2)


Update Firmware.ino

Update Firmware.ino

--- src/piggy_back_loggers/SD_Mag_Prototype/Firmware/Firmware.ino
+++ src/piggy_back_loggers/SD_Mag_Prototype/Firmware/Firmware.ino
@@ -4,11 +4,6 @@
 // Updated: 10/25/2018
 // Daniel Henshaw and Josh Tracy
 // Note: F("String") keeps string literals in program memory and out of RAM. Saves RAM space. Very good. Don't remove the F. I know it looks funny. But don't do it. Really. The program might crash if you do. And then you'll have dishonor on yourself, dishonor on your cow...
-
-/* /!\ BUG: Microcontroller Freezes on request to start logging. */ /*Bug fixed.*/
-/* /!\ BUG: Cannot enter serial */ /*Fixed: Pin 3 needs a pull-up resistor.*/
-
-/* /!\ BUG: SD Card not being written to.*/

 /*******************************************************************************************\
 * Hardware Description


the user interface for setting and enabling/disabling alarms is done

--- src/elm_clk.ino
+++ src/elm_clk.ino
@@ -57,7 +57,7 @@
 // ---------------------- //
 //  RTC definitions
 // ---------------------- //
-#define NO_OF_DIGITS 4
+#define N 4

 // ---------------------- //
 //  Globals
@@ -65,7 +65,7 @@
 byte oldFsmState    = 255;
 byte fsmState       = 0;
 byte activeDigit    = 0;
-byte digitValues[4] = {0,0,0,0};
+byte digitValues[N] = {0,0,0,0};
 byte alarmOn		= 0; // default state is OFF
 int  tempInCelsius  = 0;
 unsigned long updateInterval    = 100;
@@ -243,7 +243,7 @@
 	{
 		display.disableBlink(activeDigit);
 		activeDigit+=2;
-		activeDigit %= NO_OF_DIGITS;
+		activeDigit %= N;
 		display.enableBlink(activeDigit);
 	}
 }
@@ -254,7 +254,7 @@
 	{
 		display.disableBlink(activeDigit);
 		activeDigit++;
-		activeDigit %= NO_OF_DIGITS;
+		activeDigit %= N;
 		display.enableBlink(activeDigit);
 	}
 }
@@ -277,21 +277,13 @@
 			if (alarmOn)
 			{
 				alarmOn = 0;
-				display.enableNumericDisplay();
-				display.writeMessage("OFF ");
-				delay(600);
-				updateAlarm();
-				display.enableClockDisplay();
-				display.enableBlink(0);
+				for (int i = 0; i < N; i++)
+					display.disableDecimalPoint(i);
 			} else
 			{
 				alarmOn = 1;
-				display.enableNumericDisplay();
-				display.writeMessage("ON  ");
-				delay(600);
-				updateAlarm();
-				display.enableClockDisplay();
-				display.enableBlink(0);
+				for (int i = 0; i < N; i++)
+					display.enableDecimalPoint(i);
 			}
 			break;

@@ -410,7 +402,8 @@
 				delay(600);
 				updateTime();
 				display.enableClockDisplay();
-				display.enableBlink(0);
+				activeDigit = 0;
+				display.enableBlink(activeDigit);
 			}

 			oldFsmState = fsmState;
@@ -425,7 +418,18 @@
 				delay(600);
 				updateAlarm();
 				display.enableClockDisplay();
-				display.enableBlink(0);
+
+				if (alarmOn)
+				{
+					for (int i = 0; i < N; i++)
+						display.enableDecimalPoint(i);
+				} else {
+					for (int i = 0; i < N; i++)
+						display.disableDecimalPoint(i);
+				}
+
+				activeDigit = 0;
+				display.enableBlink(activeDigit);
 			}

 			oldFsmState = fsmState;


version 19 without bug

version 19 without bug

--- src/resource/Arduino/MRLComm.ino
+++ src/resource/Arduino/MRLComm.ino
@@ -41,7 +41,7 @@
 #endif

 // ----------  MRLCOMM FUNCTION INTERFACE BEGIN -----------
-#define MRLCOMM_VERSION				18
+#define MRLCOMM_VERSION				19

 // serial protocol functions
 #define MAGIC_NUMBER  					170 // 10101010


Improved stability

Improved stability

--- Master.ino
+++ Master.ino
@@ -14,18 +14,19 @@
 #define thErrON 0.9 //threshold multipler HIGH leds
 #define thErrOFF 1.5 //threshold multipler LOW leds
 #define setupWaitTime 1 //(ms) delay at setup time
-#define fbTime 20 //(ms) feedback led on time
-#define cycTime 20 //(ms) feedback led off time
+#define fbTime 30 //(ms) feedback led on time
+#define cycTime 30 //(ms) feedback led off time
 #define sync "MODE_sync" // keyword for start sync seq (transmitter side)
 #define recal "MODE_recal" // keyword for start sync seq (receiver side)
 #define partyM "MODE_party" // keyword for party mode (easter egg)
 #define crdM "MODE_credits" // keyword to show contributors
+#define ledContol "MODE_ledC" //open led control modes
 #define initDelay 30 //(ms) synchronization sequence delay
 #define redONtime 20 //(ms)
 #define redOFFtime 20 //(ms)
 #define trnsDELAY 0 //(ms)
-#define ledContol "MODE_ledC" //open led control modes
-
+
+void randomLed();
 void flashDotOrDash(int color, bool dotOrDash);
 void synchronization();
 void flashSequence(char sequence);
@@ -74,7 +75,7 @@
   digitalWrite(blueLED, LOW);
   digitalWrite(redLED, LOW);
   Serial.begin(250000); //start serial at the highest rate
-
+senscheck:
   if (tcs.begin())  //start sensor
   {
     Serial.println("Found sensor");
@@ -82,7 +83,7 @@
   else
   {
     Serial.println("Cannot find sensor"); //if fail stuck here
-    while (1);
+    goto senscheck;
   }

   Serial.print("Getting enviroment values"); //get env
@@ -210,15 +211,17 @@
   while (true)
   {
     tcs.getRawData(&r, &g, &b, &c); //get env info
+    bool rChange = false;
     if (r > r_h)
     {
+      rChange = true;
       r_h = r;
       if (b_h < b)
       {
         b_h = b;
       }
     }
-    else if (g > g_h)
+    if (g > g_h)
     {
       g_h = g;
       if (b_h < b)
@@ -226,7 +229,7 @@
         b_h = b;
       }
     }
-    else
+    else if (!rChange)
     {
       th_Val[4].r_t = ((float) r_h * thErrON);
       th_Val[4].g_t = ((float) g_h * thErrON);
@@ -249,16 +252,18 @@
   r_h = g_h = b_h = 0;
   while (true)
   {
+    bool rNotChage = true;
     tcs.getRawData(&r, &g, &b, &c); //get env info
     if (r > r_h)
     {
+      rNotChage = false;
       r_h = r;
       if (g_h < g)
       {
         g_h = g;
       }
     }
-    else if (b > b_h)
+    if (b > b_h)
     {
       b_h = b;
       if (g_h < g)
@@ -266,7 +271,7 @@
         g_h = g;
       }
     }
-    else
+    else if (rNotChage)
     {
       th_Val[5].r_t = ((float) r_h * thErrON);
       th_Val[5].g_t = ((float) g_h * thErrOFF);
@@ -290,16 +295,18 @@
   r_h = g_h = b_h = 0;
   while (true)
   {
+    bool bNotCHANGE = true;
     tcs.getRawData(&r, &g, &b, &c); //get env info
     if (b > b_h)
     {
+      bNotCHANGE = false;
       b_h = b;
       if (r_h < r)
       {
         r_h = r;
       }
     }
-    else if (g > g_h)
+    if (g > g_h)
     {
       g_h = g;
       if (r_h < r)
@@ -307,7 +314,7 @@
         r_h = r;
       }
     }
-    else
+    else if (bNotCHANGE)
     {
       th_Val[6].r_t = ((float) r_h * thErrOFF);
       th_Val[6].g_t = ((float) g_h * thErrON);
@@ -330,20 +337,24 @@
   r_h = g_h = b_h = 0;
   while (true)
   {
+    bool anyChange = false;
     tcs.getRawData(&r, &g, &b, &c); //get env info
     if (r > r_h)
     {
+      anyChange = true;
       r_h = r;
     }
-    else if (g > g_h)
-    {
+    if (g > g_h)
+    {
+      anyChange = true;
       g_h = g;
     }
-    else if (b_h < b)
-    {
+    if (b_h < b)
+    {
+      anyChange = true;
       b_h = b;
     }
-    else
+    if (!anyChange)
     {
       th_Val[7].r_t = ((float) r_h * thErrON);
       th_Val[7].g_t = ((float) g_h * thErrON);
@@ -467,6 +478,10 @@
           ledControl(j);
         }
       }
+    }
+    else if (inputHOLD == partyM)
+    {
+      randomLed();
     }
     else if (inputHOLD == recal) //start recalabration seq. wait for synchronization seq.
     {
@@ -593,15 +608,17 @@
       while (true)
       {
         tcs.getRawData(&r, &g, &b, &c); //get env info
+        bool rChange = false;
         if (r > r_h)
         {
+          rChange = true;
           r_h = r;
           if (b_h < b)
           {
             b_h = b;
           }
         }
-        else if (g > g_h)
+        if (g > g_h)
         {
           g_h = g;
           if (b_h < b)
@@ -609,7 +626,7 @@
             b_h = b;
           }
         }
-        else
+        else if (!rChange)
         {
           th_Val[4].r_t = ((float) r_h * thErrON);
           th_Val[4].g_t = ((float) g_h * thErrON);
@@ -632,16 +649,18 @@
       r_h = g_h = b_h = 0;
       while (true)
       {
+        bool rNotChage = true;
         tcs.getRawData(&r, &g, &b, &c); //get env info
         if (r > r_h)
         {
+          rNotChage = false;
           r_h = r;
           if (g_h < g)
           {
             g_h = g;
           }
         }
-        else if (b > b_h)
+        if (b > b_h)
         {
           b_h = b;
           if (g_h < g)
@@ -649,7 +668,7 @@
             g_h = g;
           }
         }
-        else
+        else if (rNotChage)
         {
           th_Val[5].r_t = ((float) r_h * thErrON);
           th_Val[5].g_t = ((float) g_h * thErrOFF);
@@ -673,16 +692,18 @@
       r_h = g_h = b_h = 0;
       while (true)
       {
+        bool bNotCHANGE = true;
         tcs.getRawData(&r, &g, &b, &c); //get env info
         if (b > b_h)
         {
+          bNotCHANGE = false;
           b_h = b;
           if (r_h < r)
           {
             r_h = r;
           }
         }
-        else if (g > g_h)
+        if (g > g_h)
         {
           g_h = g;
           if (r_h < r)
@@ -690,7 +711,7 @@
             r_h = r;
           }
         }
-        else
+        else if (bNotCHANGE)
         {
           th_Val[6].r_t = ((float) r_h * thErrOFF);
           th_Val[6].g_t = ((float) g_h * thErrON);
@@ -713,20 +734,24 @@
       r_h = g_h = b_h = 0;
       while (true)
       {
+        bool anyChange = false;
         tcs.getRawData(&r, &g, &b, &c); //get env info
         if (r > r_h)
         {
+          anyChange = true;
           r_h = r;
         }
-        else if (g > g_h)
-        {
+        if (g > g_h)
+        {
+          anyChange = true;
           g_h = g;
         }
-        else if (b_h < b)
-        {
+        if (b_h < b)
+        {
+          anyChange = true;
           b_h = b;
         }
-        else
+        if (!anyChange)
         {
           th_Val[7].r_t = ((float) r_h * thErrON);
           th_Val[7].g_t = ((float) g_h * thErrON);
@@ -950,3 +975,42 @@
     Serial.println("Please enter a number between 0 and 7!!");
 }

+void randomLed()
+{
+  Serial.println("Party mode ON!!!!!!!!");
+  int readRand;
+  int dly = 50;
+  while (true)
+  {
+    if (Serial.available() > 0)
+    {
+      inputHOLD = Serial.readString();
+      if (inputHOLD == "Quit")
+        break;
+      else
+      {
+        dly = 25 * ((int) inputHOLD[0] - 48);
+        if (dly < 0)
+        {
+          dly = -1 * dly;
+        }
+        if (dly > 500)
+        {
+          Serial.println("Troll was here");
+          dly = 500;
+        }
+        Serial.print("Current delay is ");
+        Serial.println(dly);
+      }
+
+    }
+    readRand = random(8);
+    ledControl(readRand);
+    delay(dly);
+  }
+  digitalWrite(redLED, LOW);
+  digitalWrite(greenLED, LOW);
+  digitalWrite(blueLED, LOW);
+
+}
+


Start temperature example

Start temperature example

--- Examples/ReadTemperatureHumidity/ReadTemperatureHumidity.ino
+++ Examples/ReadTemperatureHumidity/ReadTemperatureHumidity.ino
@@ -0,0 +1,37 @@
+/*
+  ReadTemperatureHumidity.ino - An example for the KISS LoRa device
+
+  The MIT License (MIT)
+
+  Copyright (c) 2017 The Things Industries  https://www.thethingsindustries.com/
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in all
+  copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  SOFTWARE.
+*/
+
+
+#define LED PD6
+
+void setup() {
+  pinMode(LED, OUTPUT);
+
+}
+
+void loop() {
+
+}


Changes restarts to a lot more

Changes restarts to a lot more

--- Exhibit_MomentumTable.ino
+++ Exhibit_MomentumTable.ino
@@ -21,7 +21,7 @@
 #define LOCKEDDISCRPM       30      //RPM to consider as "disc stopped"
 #define ROTATIONVARIANCE    6	      //Variance in RPM before alarm condition
 //#define TRANSMISSIONRATIO   10      //Tranmission drive ratio n:1
-#define NUMBEROFRESTARTS    3      //#of restarts attempted after stopped state
+#define NUMBEROFRESTARTS    30      //#of restarts attempted after stopped state
 #define STARTTIME           10000   //Expected ramp up time, in MS
 #define STOPTIME            10000   //Expected ramp down time, in MS
  /////////


added commutation and PID

added commutation and PID

--- src/pong_launcher/arduino_code/launcher_arduino/launcher_arduino.ino
+++ src/pong_launcher/arduino_code/launcher_arduino/launcher_arduino.ino
@@ -12,7 +12,6 @@
  Date: 4/28/15

  Authors: Hayden Conner and Kory Kraft
-
 */

 #if (ARDUINO >= 100)
@@ -30,32 +29,66 @@
 #include <std_msgs/Bool.h>

 //#include <PID_v1.h>
-#define int2 2
-#define int3 3
-#define int4 4
-
-int MotorA = 6;
-int MotorB = 9;
-int MotorC = 10;
-int val = 0;
+
+//Pin definitions
+//Motor stuff
+int A1top = 3;
+int A2top = 4;
+int A3top = 5;
+int A1bot = 7;
+int A2bot = 8;
+int A3bot = 11;
+
+int B1top = 6;
+int B2top = 9;
+int B3top = 10;
+int B1bot = 12;
+int B2bot = 13;
+int B3bot = A0;
+
+int C1top = A6;
+int C2top = A7;
+int C3top = A8;
+int C1bot = A1;
+int C2bot = A2;
+int C3bot = A3;
+//Hall effect sensors
+int ha1 = 2;
+int ha2 = A5;
+int ha3 = A9;
+
+int hb1 = A10;
+int hb2 = A11;
+int hb3 = A12;
+
+int hc1 = 29;
+int hc2 = 30;
+int hc3 = 31;

 //Hall effect sensor variables
-//int halla_old = 0, hallb_old = 0, hallc_old = 0;
-//double rota = 0, rotb = 0, rotc =0;
-//int timeold = 0;
-//volatile int halla = 0, hallb = 0, hallc = 0;
-//volatile int ina, inb, inc;
+volatile int timeoldA = 0, timeoldB = 0, timeoldC = 0;
+volatile int hallA1 = 0, hallA2 = 0, hallA3 = 0;
+volatile int hallB1 = 0, hallB2 = 0, hallB3 = 0;
+volatile int hallC1 = 0, hallC2 = 0, hallC3 = 0;
+
+//Commute variables
+int 1top, 2top, 3top;
+int 1bot, 2bot, 3bot;
+int dir
+char motor

 //PID variables
 //char motorSelect = 0;
-//double Setpointa, Inputa, Outputa;
-//double Setpointb, Inputb, Outputb;
-//double Setpointc, Inputc, Outputc;
-//double Kp = 1, Kd = 0.25, Ki = .05;
-
-//PID aPID(&Inputa, &Outputa, &Setpointa, Kp, Kd, Ki, DIRECT);
-//PID bPID(&Inputb, &Outputb, &Setpointb, Kp, Kd, Ki, DIRECT);
-//PID cPID(&Inputc, &Outputc, &Setpointc, Kp, Kd, Ki, DIRECT);
+double Setpointa = 0, Inputa;
+double Setpointb = 0, Inputb;
+double Setpointc = 0, Inputc;
+volatile double Outputa = 0, Outputb = 0, Outputc = 0;
+
+double Kp = 1, Kd = 0.25, Ki = .05;
+
+PID aPID(&Inputa, &Outputa, &Setpointa, Kp, Kd, Ki, DIRECT);
+PID bPID(&Inputb, &Outputb, &Setpointb, Kp, Kd, Ki, DIRECT);
+PID cPID(&Inputc, &Outputc, &Setpointc, Kp, Kd, Ki, DIRECT);

 // ROS Stuff
 ros::NodeHandle  nh;
@@ -67,98 +100,290 @@
   // Set the motor specified to the speed given.
   bool is_set = false;
   while (!is_set){
-
+    Inputa = curspeedA;
+    Inputb = curspeedB;
+    Inputc = curspeedC;
+
+    Setpointa = motorSpeedA;
+    Setpointb = motorSpeedB;
+    Setpointc = motorSpeedC;
     // use hall effect and pid to tune
-
-    is_set = true;
-
-  }
+    aPID.compute();
+    bPID.compute();
+    cPID.compute();
+
+	if ((curspeedA - oldspeedA) < 0.05) && ((curspeedB - oldspeedB) < 0.05) && ((curspeedC - oldspeedC) < 0.05){
+		is_set = true;
+	}

 }

+void commute(motor, hall1, hall2, hall3, dir){
+
+	switch (motor) {
+	case 1:
+		1top = A1top;
+		2top = A2top;
+		3top = A3top;
+		1bot = A1bot;
+		2bot = A2bot;
+		3bot = A3bot;
+		spd = Outputa;
+		break;
+	case 2:
+		1top = B1top;
+		2top = B2top;
+		3top = B3top;
+		1bot = B1bot;
+		2bot = B2bot;
+		3bot = B3bot;
+		spd = Outputb;
+		break;
+	case 3:
+		1top = C1top;
+		2top = C2top;
+		3top = C3top;
+		1bot = C1bot;
+		2bot = C2bot;
+		3bot = C3bot;
+		spd = Outputc;
+		break;
+	}
+
+	if ( dir == 1 ){ //Forward
+		//Case 1
+		if ((hall1 == HIGH) && (hall2 == LOW) && (hall3 == HIGH)){
+			analogWrite(1top, spd);
+			analogWrite(2top, 0);
+			analogWrite(3top, 0);
+			digitalWrite(1bot, HIGH);
+			digitalWrite(2bot, HIGH);
+			digitalWrite(3bot, LOW);
+		}
+		//Case 2
+		else if ((hall1 == HIGH) && (hall2 == LOW) && (hall3 == LOW)){
+			analogWrite(1top, spd);
+			analogWrite(2top, 0);
+			analogWrite(3top, 0);
+			digitalWrite(1bot, HIGH);
+			digitalWrite(2bot, LOW);
+			digitalWrite(3bot, HIGH);
+		}
+		//Case 3
+		else if ((hall1 == HIGH) && (hall2 == HIGH) && (hall3 == LOW)){
+			analogWrite(1top, 0);
+			analogWrite(2top, spd);
+			analogWrite(3top, 0);
+			digitalWrite(1bot, LOW);
+			digitalWrite(2bot, HIGH);
+			digitalWrite(3bot, HIGH);
+		}
+		//Case 4
+		else if ((hall1 == LOW) && (hall2 == HIGH) && (hall3 == LOW)){
+			analogWrite(1top, 0);
+			analogWrite(2top, spd);
+			analogWrite(3top, 0);
+			digitalWrite(1bot, HIGH);
+			digitalWrite(2bot, HIGH);
+			digitalWrite(3bot, LOW);
+		}
+		//Case 5
+		else if ((hall1 == LOW) && (hall2 == HIGH) && (hall3 == HIGH)){
+			analogWrite(1top, 0);
+			analogWrite(2top, 0);
+			analogWrite(3top, spd);
+			digitalWrite(1bot, HIGH);
+			digitalWrite(2bot, LOW);
+			digitalWrite(3bot, HIGH);
+		}
+		//Case 6
+		else if ((hall1 == LOW) && (hall2 == LOW) && (hall3 == HIGH)){
+			analogWrite(1top, 0);
+			analogWrite(2top, 0);
+			analogWrite(3top, spd);
+			digitalWrite(1bot, LOW);
+			digitalWrite(2bot, HIGH);
+			digitalWrite(3bot, HIGH);
+		}
+	}
+	else{ //Reverse
+		//Case 1
+		if ((hall1 == HIGH) && (hall2 == LOW) && (hall3 == HIGH)){
+			analogWrite(1top, 0);
+			analogWrite(2top, spd);
+			analogWrite(3top, 0);
+			digitalWrite(1bot, HIGH);
+			digitalWrite(2bot, HIGH);
+			digitalWrite(3bot, LOW);
+		}
+		//Case 2
+		else if ((hall1 == HIGH) && (hall2 == LOW) && (hall3 == LOW)){
+			analogWrite(1top, spd);
+			analogWrite(2top, 0);
+			analogWrite(3top, 0);
+			digitalWrite(1bot, LOW);
+			digitalWrite(2bot, LOW);
+			digitalWrite(3bot, HIGH);
+		}
+		//Case 3
+		else if ((hall1 == HIGH) && (hall2 == HIGH) && (hall3 == LOW)){
+			analogWrite(1top, 0);
+			analogWrite(2top, 0);
+			analogWrite(3top, spd);
+			digitalWrite(1bot, LOW);
+			digitalWrite(2bot, HIGH);
+			digitalWrite(3bot, HIGH);
+		}
+		//Case 4
+		else if ((hall1 == LOW) && (hall2 == HIGH) && (hall3 == LOW)){
+			analogWrite(1top, spd);
+			analogWrite(2top, 0);
+			analogWrite(3top, 0);
+			digitalWrite(1bot, HIGH);
+			digitalWrite(2bot, HIGH);
+			digitalWrite(3bot, LOW);
+		}
+		//Case 5
+		else if ((hall1 == LOW) && (hall2 == HIGH) && (hall3 == HIGH)){
+			analogWrite(1top, spd);
+			analogWrite(2top, 0);
+			analogWrite(3top, 0);
+			digitalWrite(1bot, HIGH);
+			digitalWrite(2bot, LOW);
+			digitalWrite(3bot, HIGH);
+		}
+		//Case 6
+		else if ((hall1 == LOW) && (hall2 == LOW) && (hall3 == HIGH)){
+			analogWrite(1top, 0);
+			analogWrite(2top, spd);
+			analogWrite(3top, 0);
+			digitalWrite(1bot, LOW);
+			digitalWrite(2bot, HIGH);
+			digitalWrite(3bot, HIGH);
+		}
+	}
+}
+
 void motor_controls_cb(const geometry_msgs::Vector3& cmd_msg){

-  // publish command saying that we are adjusting
-  std_msgs::String str;
-  str.data = "adjusting";
-  state_pub.publish(&str);
-
-  // Get motor speed A, B, and C from the message
-  double motorSpeedA = cmd_msg.x;
-  double motorSpeedB = cmd_msg.y;
-  double motorSpeedC = cmd_msg.z;
-
-  // Set each motor speed, verification done in setting motor speed
-  setMotorSpeed(MotorA, motorSpeedA);
-  setMotorSpeed(MotorB, motorSpeedB);
-  setMotorSpeed(MotorC, motorSpeedC);
-
-  // publish command alerting the master system that we are ready
-//  std_msgs::String str;
-  str.data = "ready";
-  state_pub.publish(&str);
-
+	// publish command saying that we are adjusting
+	std_msgs::String str;
+	str.data = "adjusting";
+	state_pub.publish(&str);
+
+	// Get motor speed A, B, and C from the message
+	double motorSpeedA = cmd_msg.x;
+	double motorSpeedB = cmd_msg.y;
+	double motorSpeedC = cmd_msg.z;
+
+	// Set each motor speed, verification done in setting motor speed
+	setMotorSpeed(MotorA, motorSpeedA);
+	setMotorSpeed(MotorB, motorSpeedB);
+	setMotorSpeed(MotorC, motorSpeedC);
+
+	// publish command alerting the master system that we are ready
+	//  std_msgs::String str;
+	str.data = "ready";
+	state_pub.publish(&str);
 }

 ros::Subscriber<geometry_msgs::Vector3> motor_sub("launcher/motor_vel/", motor_controls_cb);

 void setup(){
-  //Pinmodes for the motor's PWM
-  pinMode(MotorA,OUTPUT);
-  pinMode(MotorB,OUTPUT);
-  pinMode(MotorC,OUTPUT);
-
-  //Defining the interupt pins as interrupt, required by the Teensy 3.1
-  pinMode(int2, INPUT);
-  pinMode(int3, INPUT);
-  pinMode(int4, INPUT);
-
-//  aPID.SetMode(AUTOMATIC);
-//  bPID.SetMode(AUTOMATIC);
-//  cPID.SetMode(AUTOMATIC);
-
-//  attachInterrupt(int2, hall_isra, RISING);
-//  attachInterrupt(int3, hall_isrb, RISING);
-//  attachInterrupt(int4, hall_isrc, RISING);
-
-  nh.initNode();
-  nh.subscribe(motor_sub);
+	//Pinmodes for the motor's PWM
+	pinMode(A1top,OUTPUT);
+	pinMode(A2top,OUTPUT);
+	pinMode(A3top,OUTPUT);
+	pinMode(A1bot,OUTPUT);
+	pinMode(A2bot,OUTPUT);
+	pinMode(A3bot,OUTPUT);
+
+
+	pinMode(B1top,OUTPUT);
+	pinMode(B2top,OUTPUT);
+	pinMode(B3top,OUTPUT);
+	pinMode(B1bot,OUTPUT);
+	pinMode(B2bot,OUTPUT);
+	pinMode(B3bot,OUTPUT);
+
+	pinMode(C1top,OUTPUT);
+	pinMode(C2top,OUTPUT);
+	pinMode(C3top,OUTPUT);
+	pinMode(C1bot,OUTPUT);
+	pinMode(C2bot,OUTPUT);
+	pinMode(C3bot,OUTPUT);
+
+
+	//Defining the interupt pins as interrupt, pinMode is required by the Teensy 3.1
+	pinMode(ha1, INPUT);
+	pinMode(ha2, INPUT);
+	pinMode(ha3, INPUT);
+	attachInterrupt(ha1, A, CHANGE);
+	attachInterrupt(ha2, A, CHANGE);
+	attachInterrupt(ha3, A, CHANGE);
+	pinMode(hb1, INPUT);
+	pinMode(hb2, INPUT);
+	pinMode(hb3, INPUT);
+	attachInterrupt(ha1, B, CHANGE);
+	attachInterrupt(ha2, B, CHANGE);
+	attachInterrupt(ha3, B, CHANGE);
+	pinMode(hc1, INPUT);
+	pinMode(hc2, INPUT);
+	pinMode(hc3, INPUT);
+	attachInterrupt(ha1, C, CHANGE);
+	attachInterrupt(ha2, C, CHANGE);
+	attachInterrupt(ha3, C, CHANGE);
+
+	//PID mode set
+	aPID.SetMode(AUTOMATIC);
+	bPID.SetMode(AUTOMATIC);
+	cPID.SetMode(AUTOMATIC);
+
+	nh.initNode();
+	nh.subscribe(motor_sub);
 }

 void loop(){
-
   // ros necesisity
   nh.spinOnce();
-
-//  if( millis() - timeold > 20){
-//    rota = (halla - halla_old)/(millis()-timeold);
-//    rotb = (hallb - hallb_old)/(millis()-timeold);
-//    rotc = (hallc - hallc_old)/(millis()-timeold);
-//    halla_old = halla;
-//    hallb_old = hallb;
-//    hallc_old = hallc;
-//  }
-
   delay(1);
-
-}
-
-//void hall_isra(){
-//  if (ina > (millis()+1)){
-//    halla++;
-//  }
-//}
-//
-//void hall_isrb(){
-//  if (inb > (millis()+1)){
-//    hallb++;
-//  }
-//}
-//
-//void hall_isrc(){
-//  if (inc > (millis()+1)){
-//    hallc++;
-//  }
-//}
-
-
+}
+
+void A(){
+	hallA1 = digitalRead(ha1);
+	hallA2 = digitalRead(ha2);
+	hallA3 = digitalRead(ha3);
+
+	time = millis();
+	curspeedA = 1/(3 * (time - timeold));
+	timeoldA = time;
+	oldspeedA = curspeedA;
+
+	commute(1, hallC1, hallC2, hallC3, 1);
+}
+
+void B() {
+	hallB1 = digitalRead(hb1);
+	hallB2 = digitalRead(hb2);
+	hallB3 = digitalRead(hb3);
+
+	time = millis();
+	curspeedB = 1/(3 * (time - timeold));
+	timeoldB = time;
+	oldspeedB = curspeedB;
+
+	commute(2, hallC1, hallC2, hallC3, 1);
+}
+
+void C() {
+	hallC1 = digitalRead(hc1);
+	hallC2 = digitalRead(hc2);
+	hallC3 = digitalRead(hc3);
+
+	time = millis();
+	curspeedC = 1/(3 * (time - timeold));
+	timeoldC = time;
+	oldspeedC = curspeedC;
+
+	commute(3, hallC1, hallC2, hallC3, 1);
+}


Tidying up the firmware ... fewer variables.

--- PACMAN/arduino_firmware/ArduinoProMini/dusty_acorn/dusty_acorn.ino
+++ PACMAN/arduino_firmware/ArduinoProMini/dusty_acorn/dusty_acorn.ino
@@ -26,7 +26,7 @@
 byte readbuffer[64];
 unsigned int checkSum,checkresult;
 unsigned int FrameLength,Data4,Data5,Data6;
-unsigned int PM1,PM25,PM10,N300,N500,N1000,N2500,N5000,N10000;
+unsigned int PM1,PM25,PM10,N300,N500,N1000,;
 unsigned int timer1,timer0;
 boolean valid_data;
 dht DHT;


Refrech api.github.com x509 certificate (#4306)

The certificate fingerprint included with the HTTPSRequest example seems
to be for an expired api.github.com certificate.  Replace with the current
one to avoid reporting "certificate mismatch" errors when running.

--- libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino
+++ libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino
@@ -27,7 +27,7 @@

 // Use web browser to view and copy
 // SHA1 fingerprint of the certificate
-const char* fingerprint = "CF 05 98 89 CA FF 8E D8 5E 5C E0 C2 E4 F7 E6 C3 C7 50 DD 5C";
+const char* fingerprint = "35 85 74 EF 67 35 A7 CE 40 69 50 F3 C0 F6 80 CF 80 3B 2E 19";

 void setup() {
   Serial.begin(115200);


time fixed

time fixed

--- MTM_MASTER/MTM_MASTER.ino
+++ MTM_MASTER/MTM_MASTER.ino
@@ -33,9 +33,9 @@
 //measurements
 int massFSR();
 int massChange(int initMass);
-void setMass(int milk, int sugar);
+void setTime(int milk, int sugar);
 int threshold = 0;                      //initial FSR value
-float time[] = {BLEED_MASS, MILK_TIME, SUGAR_TIME, TEA_TIME};       //mass change setting for pump modes
+float dispenseTime[] = {BLEED_MASS, MILK_TIME, SUGAR_TIME, TEA_TIME};       //mass change setting for pump modes
 byte test[] = {0,1,2,3,4,5};

 void setup() {
@@ -127,28 +127,28 @@
 ////PUMP MODES////
 int bleed(byte addr) {
     //clear air from both pumps
-    if(!runPump(addr, 0, time[0]))
+    if(!runPump(addr, 0, dispenseTime[0]))
         return error();
-    if(!runPump(addr, 1, time[0]))
+    if(!runPump(addr, 1, dispenseTime[0]))
         return error();
 }
 int dispenseMilk(byte addr){
-    if(!runPump(addr, 0, time[1]))          //pump0 is for milk
+    if(!runPump(addr, 0, dispenseTime[1]))          //pump0 is for milk
         return error();
     return ready = 1;
 }
 int dispenseSugar(byte addr){
-     if(!runPump(addr, 0, time[2]))          //pump1 is for sugar
+     if(!runPump(addr, 0, dispenseTime[2]))          //pump1 is for sugar
         return error();
      return ready = 2;
 }
 int dispenseTea1(byte addr){
-    if(!runPump(addr, 1, time[3]))          //pump2 is for tea1
+    if(!runPump(addr, 1, dispenseTime[3]))          //pump2 is for tea1
         return error();
     return ready = 3;
 }
 int dispenseTea2(byte addr){
-    if(!runPump(addr, 1, time[3]))          //pump3 is for tea2
+    if(!runPump(addr, 1, dispenseTime[3]))          //pump3 is for tea2
         return error();
     return ready = 3;
 }
@@ -172,8 +172,8 @@
     return massFSR()-initMass;
 }
 //allows UI to set milk, sugar amount
-void setMass(int milk, int sugar){
-    time[1] = (milk/100)*MILK_TIME; //% of default milk
-    time[2] = (sugar/100)*SUGAR_TIME; //% of default sugar
-    time[3] = (TOTAL_TIME-time[1]-time[2]); //fills cup w tea
+void setTime(int milk, int sugar){
+    dispenseTime[1] = (milk/100)*MILK_TIME; //% of default milk
+    dispenseTime[2] = (sugar/100)*SUGAR_TIME; //% of default sugar
+    dispenseTime[3] = (TOTAL_TIME-dispenseTime[1]-dispenseTime[2]); //fills cup w tea
 }


minior typos and comments

minior typos and comments

--- MazeSolver/MazeSolver.ino
+++ MazeSolver/MazeSolver.ino
@@ -264,9 +264,9 @@
 //		delay(25);
 //
 //		// These variables record whether the robot has seen a line to the
-//		// left, straight ahead, and right, whil examining the current
+//		// left, straight ahead, and right, while examining the current
 //		// intersection.
-//		unsigned char found_left = 0;
+//		unsigned char found_left = 0; //TODO make this boolean
 //		unsigned char found_straight = 0;
 //		unsigned char found_right = 0;
 //
@@ -294,7 +294,7 @@
 //		//TODO End of the maze
 //	}

-char select_turn(unsigned char found_left, unsigned char found_straight, unsigned char found_right)
+char select_turn(unsigned char found_left, unsigned char found_straight, unsigned char found_right) //TODO make this boolean
 {
 	// Make a decision about how to turn.  The following code
 	// implements a left-hand-on-the-wall strategy, where we always


Completed LCD module, it has ok, off and lost messages now.

--- communication_firmware/lcd_module_firmware/lcd_module_firmware.ino
+++ communication_firmware/lcd_module_firmware/lcd_module_firmware.ino
@@ -4,12 +4,14 @@
 #include <LiquidCrystal_I2C.h>

 struct DataStruct{
-    int Robot;
-    int Message;
+    int Robot=0;
+    int Message=0;
 };

-DataStruct Report;
-
+DataStruct Report, vel, Data[3];
+int ctr=0;
+int state[3] = {49, 49, 49};
+int msg[3] = {0, 0, 0};
 int CE = A0; //pro micro
 int CS = 10; //pro micro

@@ -25,35 +27,24 @@
   // put your setup code here, to run once:
   Serial.begin (9600);
   RadioSetup();
-  Report.Robot = 1;
-  Report.Message = 1;
   lcd.begin(16,2);
   lcd.setBacklight (HIGH);
+  //Report.Robot = 1;

 }

 void loop() {
   // put your main code here, to run repeatedly:
-  //ReceiveReport();
-  Serial.println(Report.Robot);
-  if (Report.Robot == 0){
-    lcd.setCursor (5,0);
-    lcd.print ("UNBALL");
+  ReceiveReport();
+  if(state[0] != Data[0].Message || state[1] != Data[1].Message || state[2] != Data[2].Message){
+    Serial.println(Report.Robot);
+    Serial.println(Report.Message);
+    Print_lcd();
+    state[0] = Data[0].Message;
+    state[1] = Data[1].Message;
+    state[2] = Data[2].Message;
   }
-  if (Report.Robot == 1){
-    lcd.setCursor (5,0);
-    lcd.print ("ROBOT 0");
-  }
-  if (Report.Robot == 2){
-    lcd.setCursor (5,0);
-    lcd.print ("ROBOT 1");
-  }
-  if (Report.Robot == 3){
-    lcd.setCursor (5,0);
-    lcd.print ("ROBOT 2");
-  }
- // lcd_print (Report.Robot, Report.Message);
- delay(1000);
+  delay(500);
 }

 void RadioSetup(){
@@ -72,31 +63,92 @@
     radio.startListening();                 // Start listening
 }

+void NotReceivingFor(){
+  ctr++;
+}
+
 void ReceiveReport(){       //Function to receive data
   if(radio.available()){
-    radio.read(&Report, sizeof(DataStruct));
+    ctr = 0;
+    while(radio.available()){
+        radio.read(&Report, sizeof(DataStruct));
+    }
+    Serial.println("receiving");
+    Data[Report.Robot].Message = Report.Message;
+    Serial.println(Data[Report.Robot].Message);
+  }
+  else{
+    Serial.println("not receiving");
+    NotReceivingFor();
+    if(ctr > 10){
+      Data[0].Message = 0;
+      Data[1].Message = 0;
+      Data[2].Message = 0;
+    }
   }
 }

-/*void lcd_print (int a, int b){
-  if (Report.Robot == 0){
+void Clear_lcd(){
+  lcd.setCursor(0,0);
+    lcd.print("                ");
+    lcd.setCursor(0,1);
+    lcd.print("                ");
+}
+
+void Print_lcd(){
+  if (Data[0].Message == 0 && Data[1].Message == 0 && Data[1].Message == 0){
+    Clear_lcd();
     lcd.setCursor (5,0);
     lcd.print ("UNBALL");
+    lcd.setCursor(0,1);
+    lcd.print("FUTEBOL DE ROBOS");
   }
-  if (Report.Robot == 1){
-    lcd.setCursor (5,0);
-    lcd.print ("ROBOT 0");
+  else{
+    Clear_lcd();
+    lcd.setCursor (1,0);
+    lcd.print ("R00");
+    lcd.setCursor (6,0);
+    lcd.print ("R01");
+    lcd.setCursor (11,0);
+    lcd.print ("R02");
+
+    if (Data[0].Message == 1){
+      lcd.setCursor (1,1);
+      lcd.print ("LOST");
+    }
+    else if(Data[0].Message == 2){
+      lcd.setCursor (2,1);
+      lcd.print ("OK");
+    }
+    else{
+      lcd.setCursor (1,1);
+      lcd.print ("OFF");
+    }
+
+    if (Data[1].Message == 1){
+      lcd.setCursor (6,1);
+      lcd.print ("LOST");
+    }
+    else if(Data[1].Message == 2){
+      lcd.setCursor (7,1);
+      lcd.print ("OK");
+    }
+    else{
+      lcd.setCursor (6,1);
+      lcd.print ("OFF");
+    }
+
+    if (Data[2].Message == 1){
+      lcd.setCursor (11,1);
+      lcd.print ("LOST");
+    }
+    else if(Data[2].Message == 2){
+      lcd.setCursor (12,1);
+      lcd.print ("OK");
+    }
+    else{
+      lcd.setCursor (11,1);
+      lcd.print ("OFF");
+    }
   }
-  if (a == 2){
-    lcd.setCursor (5,0);
-    lcd.print ("ROBOT 1");
-  }
-   if (a == 3){
-    lcd.setCursor (5,0);
-    lcd.print ("ROBOT 2");
-  }
-}*/
-
-
-
-
+}


reformated code
(Arduino IDE auto-reformat)

Former-commit-id: 8f94b2bb865337ba7b0538617857432ea0376aea

--- dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino
+++ dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino
@@ -71,7 +71,7 @@
 // XOR 0x55).  LED data follows, 3 bytes per LED, in order R, G, B,
 // where 0 = off and 255 = max brightness.

-static const uint8_t magic[] = {'A','d','a'};
+static const uint8_t magic[] = {'A', 'd', 'a'};
 #define MAGICSIZE  sizeof(magic)
 #define HEADERSIZE (MAGICSIZE + 3)

@@ -96,31 +96,31 @@
   // masking and/or conditional code every time one of these indices
   // needs to change, slowing things down tremendously.
   uint8_t
-    buffer[256],
-    indexIn       = 0,
-    indexOut      = 0,
-    mode          = MODE_HEADER,
-    hi, lo, chk, i, spiFlag;
+  buffer[256],
+         indexIn       = 0,
+         indexOut      = 0,
+         mode          = MODE_HEADER,
+         hi, lo, chk, i, spiFlag;
   int16_t
-    bytesBuffered = 0,
-    hold          = 0,
-    c;
+  bytesBuffered = 0,
+  hold          = 0,
+  c;
   int32_t
-    bytesRemaining;
+  bytesRemaining;
   unsigned long
-    startTime,
-    lastByteTime,
-    lastAckTime,
-    t;
-  bool
-     data_in_led = false,
-     spi_out_led = false;
-
+  startTime,
+  lastByteTime,
+  lastAckTime,
+  t;
+  bool
+  data_in_led = false,
+  spi_out_led = false;
+
   LED_DDR  |=  LED_PIN; // Enable output for LED
   LED_PORT &= ~LED_PIN; // LED off
   pinMode(DATA_LED, OUTPUT); //data in led
   pinMode(SPI_LED, OUTPUT); //data out led
-
+
   Serial.begin(115200); // Teensy/32u4 disregards baud rate; is OK!

   SPI.begin();
@@ -135,18 +135,18 @@
   // green, blue, then off.  Once you're confident everything is working
   // end-to-end, it's OK to comment this out and reprogram the Arduino.
   uint8_t testcolor[] = { 0, 0, 0, 255, 0, 0 };
-  for(int i=0; i<4; i++){ //Start Frame
-    for(SPDR = 0x00; !(SPSR & _BV(SPIF)); );
+  for (int i = 0; i < 4; i++) { //Start Frame
+    for (SPDR = 0x00; !(SPSR & _BV(SPIF)); );
   }
-  for(char n=3; n>=0; n--) {
-    for(c=0; c<25000; c++) {
-	  for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness byte
-      for(i=0; i<3; i++) {
-        for(SPDR = testcolor[n + i]; !(SPSR & _BV(SPIF)); ); //BGR
+  for (char n = 3; n >= 0; n--) {
+    for (c = 0; c < 25000; c++) {
+      for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness byte
+      for (i = 0; i < 3; i++) {
+        for (SPDR = testcolor[n + i]; !(SPSR & _BV(SPIF)); ); //BGR
       }
     }
-    for(int i=0; i<4; i++){ //Stop Frame
-       for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); );
+    for (int i = 0; i < 4; i++) { //Stop Frame
+      for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); );
     }
     delay(1); // One millisecond pause = latch
     digitalWrite(SPI_LED, spi_out_led = !spi_out_led);
@@ -160,109 +160,109 @@
   // loop() is avoided as even that small bit of function overhead
   // has a measurable impact on this code's overall throughput.

-  for(;;) {
+  for (;;) {
     digitalWrite(DATA_LED, LOW);
     digitalWrite(SPI_LED, LOW);
     // Implementation is a simple finite-state machine.
     // Regardless of mode, check for serial input each time:
     t = millis();
-    if((bytesBuffered < 256) && ((c = Serial.read()) >= 0)) {
+    if ((bytesBuffered < 256) && ((c = Serial.read()) >= 0)) {
       buffer[indexIn++] = c;
       bytesBuffered++;
       lastByteTime = lastAckTime = t; // Reset timeout counters
     } else {
       // No data received.  If this persists, send an ACK packet
       // to host once every second to alert it to our presence.
-      if((t - lastAckTime) > 1000) {
+      if ((t - lastAckTime) > 1000) {
         Serial.print("Ada\n"); // Send ACK string to host
         lastAckTime = t; // Reset counter
       }
       // If no data received for an extended time, turn off all LEDs.
-      if((t - lastByteTime) > serialTimeout) {
-        for(i=0;i<4;i++) { //Start Frame
-          for(SPDR = 0x00; !(SPSR & _BV(SPIF)); );
-        }
-        for(c=0; c<25000; c++) {
-          for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness Byte
-          for(i=0; i<3; i++) {
-            for(SPDR = 0x00; !(SPSR & _BV(SPIF)); ); //BGR
+      if ((t - lastByteTime) > serialTimeout) {
+        for (i = 0; i < 4; i++) { //Start Frame
+          for (SPDR = 0x00; !(SPSR & _BV(SPIF)); );
+        }
+        for (c = 0; c < 25000; c++) {
+          for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness Byte
+          for (i = 0; i < 3; i++) {
+            for (SPDR = 0x00; !(SPSR & _BV(SPIF)); ); //BGR
           }
         }
-        for(i=0;i<4;i++) { //Stop Frame
-          for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); );
+        for (i = 0; i < 4; i++) { //Stop Frame
+          for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); );
         }
         delay(1); // One millisecond pause = latch
         lastByteTime = t; // Reset counter
       }
     }

-    switch(mode) {
-
-     case MODE_HEADER:
-
-      // In header-seeking mode.  Is there enough data to check?
-      if(bytesBuffered >= HEADERSIZE) {
-        // Indeed.  Check for a 'magic word' match.
-        for(i=0; (i<MAGICSIZE) && (buffer[indexOut++] == magic[i++]););
-        if(i == MAGICSIZE) {
-          // Magic word matches.  Now how about the checksum?
-          hi  = buffer[indexOut++];
-          lo  = buffer[indexOut++];
-          chk = buffer[indexOut++];
-          if(chk == (hi ^ lo ^ 0x55)) {
-            // Checksum looks valid.  Get 16-bit LED count, add 1
-            // (# LEDs is always > 0) and multiply by 3 for R,G,B.
-            bytesRemaining = 4L * (256L * (long)hi + (long)lo) +4L + (256L *(long)hi + (long)lo +15)/16;
-            bytesBuffered -= 3;
-            spiFlag        = 0;         // No data out yet
-            mode           = MODE_HOLD; // Proceed to latch wait mode
-            digitalWrite(DATA_LED, data_in_led = !data_in_led);
-          } else {
-            // Checksum didn't match; search resumes after magic word.
-            indexOut  -= 3; // Rewind
+    switch (mode) {
+
+      case MODE_HEADER:
+
+        // In header-seeking mode.  Is there enough data to check?
+        if (bytesBuffered >= HEADERSIZE) {
+          // Indeed.  Check for a 'magic word' match.
+          for (i = 0; (i < MAGICSIZE) && (buffer[indexOut++] == magic[i++]););
+          if (i == MAGICSIZE) {
+            // Magic word matches.  Now how about the checksum?
+            hi  = buffer[indexOut++];
+            lo  = buffer[indexOut++];
+            chk = buffer[indexOut++];
+            if (chk == (hi ^ lo ^ 0x55)) {
+              // Checksum looks valid.  Get 16-bit LED count, add 1
+              // (# LEDs is always > 0) and multiply by 3 for R,G,B.
+              bytesRemaining = 4L * (256L * (long)hi + (long)lo) + 4L + (256L * (long)hi + (long)lo + 15) / 16;
+              bytesBuffered -= 3;
+              spiFlag        = 0;         // No data out yet
+              mode           = MODE_HOLD; // Proceed to latch wait mode
+              digitalWrite(DATA_LED, data_in_led = !data_in_led);
+            } else {
+              // Checksum didn't match; search resumes after magic word.
+              indexOut  -= 3; // Rewind
+            }
+          } // else no header match.  Resume at first mismatched byte.
+          bytesBuffered -= i;
+        }
+        break;
+
+      case MODE_HOLD:
+
+        // Ostensibly "waiting for the latch from the prior frame
+        // to complete" mode, but may also revert to this mode when
+        // underrun prevention necessitates a delay.
+
+        if ((micros() - startTime) < hold) break; // Still holding; keep buffering
+
+        // Latch/delay complete.  Advance to data-issuing mode...
+        LED_PORT &= ~LED_PIN;  // LED off
+        mode      = MODE_DATA; // ...and fall through (no break):
+
+      case MODE_DATA:
+        digitalWrite(SPI_LED, spi_out_led = !spi_out_led);
+        while (spiFlag && !(SPSR & _BV(SPIF))); // Wait for prior byte
+        if (bytesRemaining > 0) {
+          if (bytesBuffered > 0) {
+            SPDR = buffer[indexOut++];   // Issue next byte
+            bytesBuffered--;
+            bytesRemaining--;
+            spiFlag = 1;
           }
-        } // else no header match.  Resume at first mismatched byte.
-        bytesBuffered -= i;
-      }
-      break;
-
-     case MODE_HOLD:
-
-      // Ostensibly "waiting for the latch from the prior frame
-      // to complete" mode, but may also revert to this mode when
-      // underrun prevention necessitates a delay.
-
-      if((micros() - startTime) < hold) break; // Still holding; keep buffering
-
-      // Latch/delay complete.  Advance to data-issuing mode...
-      LED_PORT &= ~LED_PIN;  // LED off
-      mode      = MODE_DATA; // ...and fall through (no break):
-
-     case MODE_DATA:
-      digitalWrite(SPI_LED, spi_out_led = !spi_out_led);
-      while(spiFlag && !(SPSR & _BV(SPIF))); // Wait for prior byte
-      if(bytesRemaining > 0) {
-        if(bytesBuffered > 0) {
-          SPDR = buffer[indexOut++];   // Issue next byte
-          bytesBuffered--;
-          bytesRemaining--;
-          spiFlag = 1;
-        }
-        // If serial buffer is threatening to underrun, start
-       // introducing progressively longer pauses to allow more
-        // data to arrive (up to a point).
-     //  if((bytesBuffered < 32) && (bytesRemaining > bytesBuffered)) {
-     //    startTime = micros();
-     //     hold      = 100 + (32 - bytesBuffered) * 10;
-     //     mode      = MODE_HOLD;
-//}
-      } else {
-        // End of data -- issue latch:
-        startTime  = micros();
-        hold       = 1000;        // Latch duration = 1000 uS
-        LED_PORT  |= LED_PIN;     // LED on
-        mode       = MODE_HEADER; // Begin next header search
-      }
+          // If serial buffer is threatening to underrun, start
+          // introducing progressively longer pauses to allow more
+          // data to arrive (up to a point).
+          //  if((bytesBuffered < 32) && (bytesRemaining > bytesBuffered)) {
+          //    startTime = micros();
+          //     hold      = 100 + (32 - bytesBuffered) * 10;
+          //     mode      = MODE_HOLD;
+          //}
+        } else {
+          // End of data -- issue latch:
+          startTime  = micros();
+          hold       = 1000;        // Latch duration = 1000 uS
+          LED_PORT  |= LED_PIN;     // LED on
+          mode       = MODE_HEADER; // Begin next header search
+        }
     } // end switch
   } // end for(;;)
 }


Testing poll exit time

Testing poll exit time

--- module/module.ino
+++ module/module.ino
@@ -149,7 +149,7 @@
 */
 unsigned long accumulator(void) {
 	unsigned char A[bufferSize];
-	unsigned long startTime, endTime = 0;
+	unsigned long startTime = 0;
 	unsigned int periodX, periodY;
 	unsigned int lastPeriodX, lastPeriodY;
 	unsigned long periodCount, sendCount = 0;
@@ -159,7 +159,7 @@
 	if (debug) {
 		Serial.print(startTime);
 		Serial.print(" ");
-		Serial.print(endTime);
+		Serial.print(sendCount);
 		Serial.print(" ");
 		Serial.println(periodCount);
 	}
@@ -175,9 +175,9 @@
 				soundFeedback(reject);
 				Serial.print(messages.cancel);
 				while(1) {
-					Serial.println(endTime);
+					Serial.println(sendCount);
 				}
-				return endTime;
+				return sendCount;
 			}
 		}
 		else {


Minor corrections to fix glitches in switches, new example

--- examples/interruptSwitchEncoder8574/interruptSwitchEncoder8574.ino
+++ examples/interruptSwitchEncoder8574/interruptSwitchEncoder8574.ino
@@ -7,7 +7,7 @@

  Switch input is designed to work with the task manager class which makes scheduling tasks trivial.

- Circuit / detail: https://www.thecoderscorner.com/products/arduino-libraries/io-abstraction/rotary-encoder-switches-interrupt-PCF8574/
+ Circuit / detail: https://www.thecoderscorner.com/products/arduino-libraries/io-abstraction/rotary-encoder-switches-interrupt-pcf8574/

 */

@@ -40,12 +40,6 @@
 void onSpinwheelClicked(uint8_t pin, bool heldDown) {
   Serial.print("Encoder button pressed ");
   Serial.println(heldDown ? "Held" : "Pressed");
-
-  // Flip the state of the led by reading, fliping then writing it's value
-  // notice the use of the 'S' version of the ioDevice functions, these are
-  // for single operations, where it includes a sync with the io device
-  currentLedState = !currentLedState;
-  ioDeviceDigitalWriteS(switches.getIoAbstraction(), ledPin, currentLedState);
 }

 //
@@ -54,6 +48,12 @@
 void onRepeatButtonClicked(uint8_t pin, bool heldDown) {
   Serial.print("Repeat button ");
   Serial.println(heldDown ? "Held" : "Pressed");
+
+  // Flip the state of the led by reading, fliping then writing it's value
+  // notice the use of the 'S' version of the ioDevice functions, these are
+  // for single operations, where it includes a sync with the io device
+  currentLedState = !currentLedState;
+  ioDeviceDigitalWriteS(switches.getIoAbstraction(), ledPin, currentLedState);
 }

 //


have fun

have fun

--- turtleCode/arduino/final/LCD12864_test/LCD12864_test.ino
+++ turtleCode/arduino/final/LCD12864_test/LCD12864_test.ino
@@ -172,6 +172,7 @@
   return answer;
 }

+int wrong =0;
 void checkInput(int input, int answer){
   if (input == answer){
     writeserial("c");
@@ -183,7 +184,12 @@
     Serial.flush();
   }
   else{
+    wrong++;
     writeserial("w");
+    if(wrong>5){
+      writeserial("n");
+      //displaysingle('e','s','d');
+    }
     openMouth();
     delay(2000);
     waitMouth();


Spacing

Spacing

--- staff/staff.ino
+++ staff/staff.ino
@@ -276,7 +276,6 @@
     dave();
   }

-
   firstTimeRunningThroughPattern = false;

   show_at_max_brightness_for_power();


Corrected the return type of the digitalPotWrite in the SPI/DigitalPotControl example Fixes #1063

--- libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino
+++ libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino
@@ -60,7 +60,7 @@

 }

-int digitalPotWrite(int address, int value) {
+void digitalPotWrite(int address, int value) {
   // take the SS pin low to select the chip:
   digitalWrite(slaveSelectPin,LOW);
   //  send in the address and value via SPI:
@@ -68,4 +68,4 @@
   SPI.transfer(value);
   // take the SS pin high to de-select the chip:
   digitalWrite(slaveSelectPin,HIGH);
-}+}


Serial debugging

Serial debugging

--- sensor/sensor.ino
+++ sensor/sensor.ino
@@ -65,7 +65,7 @@
 {
     watchdog_setup();

-    //Serial.begin(9600);
+    Serial.begin(9600);
     //pinMode(LED_DEBUG, OUTPUT);

     pinMode(PIN_TX, OUTPUT);
@@ -116,7 +116,7 @@
         // temperature string 6 bytes (or is it 5 because the null terminator gets removed?)
         char msg[40]; // string to send
         sprintf(msg, "S,%d,%s,%s,%i,%i,%lu", msgId, temp_internal, temp_external, soil_read, solr_mv, vcc);
-        //Serial.println(msg);
+        Serial.println(msg);
         vw_send((uint8_t *)msg, strlen(msg));
         vw_wait_tx(); // Wait until the whole message is gone
         digitalWrite(PIN_TX_POWER, LOW);


Sweeps three extra steps before deciding on cyl. Resets correctly after first iteration

--- Tests/Ping_findCylinder_factorized/Ping_findCylinder_factorized.ino
+++ Tests/Ping_findCylinder_factorized/Ping_findCylinder_factorized.ino
@@ -13,6 +13,7 @@

 const int discardCylDist = 65;
 const int horizonDist = 300;
+const int extraSwipeSteps = 3;

 int  measurements[stepsInFullTurn];
 int  currentIndex = 0;
@@ -37,12 +38,17 @@
   rotateStep(servoLeft, servoRight, counterClockwise);
   int m = measurePingDist();

-  Serial.println(arrayToString(measurements, stepsInFullTurn));
+  Serial.println(String(currentIndex)+"\t"+arrayToString(measurements, stepsInFullTurn));
   measurements[currentIndex] = m;
-  if(m > discardCylDist)
+  if(m > discardCylDist){
     noCylinder[currentIndex] = true;
-  int cyl = findCylinder(currentIndex);
+  }
+
+  int cyl = -1;
+  if(currentIndex >= extraSwipeSteps)
+    cyl = findCylinder(currentIndex-extraSwipeSteps);
   if(cyl != -1){
+    cyl += extraSwipeSteps;
     Serial.println("found cyl "+String(cyl)+" steps away");
     while(cyl--){
       rotateStep(servoLeft, servoRight, clockwise);
@@ -54,8 +60,13 @@
     }
     stopMovement(servoLeft, servoRight);
     beep();
-    delay(5000);
+    resetMeasurements();
+    delay(5000);
   }
+}
+void resetMeasurements(){
+    currentIndex=0;
+    for(int i=0;i<stepsInFullTurn;i++) {measurements[i]=0; noCylinder[i]=false;}
 }

 // Determines the index of the best cylinder candidate
@@ -66,8 +77,6 @@
 // getIndexOfLargestOpenInterval to get a free new direction
 // to explore.
 int findCylinder(int maxIndex){
-  if(maxIndex < 10)
-    return -1;
   const int l = stepsInFullTurn;

   while(true){
@@ -100,7 +109,7 @@

     Serial.println("intervalLength: "+String(intervalLength));

-    if(intervalLength <= 5){ // TODO Experimenting with the threshold
+    if(couldIntervalBeCylinder(intervalLength, measurements[nearestIndex])){
       return maxIndex-(iL + iR)/2;
     } else {
       for(int i=iL; i<iR; i=nextIndex(i,l)){ // TODO consider the edges
@@ -108,6 +117,14 @@
       }
     }
   }
+}
+
+bool couldIntervalBeCylinder(int intervalLength, int intervalDist){
+  // TODO Experimenting with the condition, use intervalDist
+  return intervalLength <= 5;
+}
+bool equalWithinMargin(int val1, int val2, double margin){
+  return abs(val1-val2) < margin;
 }

 // Index of the broadest open horizon.


Switch to Xinput based emulation More of pain to upload, but seems to work better

--- CocktailUSBGamepadEmulator/CocktailUSBGamepadEmulator.ino
+++ CocktailUSBGamepadEmulator/CocktailUSBGamepadEmulator.ino
@@ -4,54 +4,33 @@
 //
 // *** Currently setup assuming a digital (not-analog) joystick
 //
-// *** This sketch file is for use with Arduino Leonardo and
-//     Arduino Micro only.
+// relies on these:
+//https://www.partsnotincluded.com/tutorials/how-to-emulate-an-xbox-controller-with-arduino-xinput/
+//https://github.com/dmadison/ArduinoXInput_AVR
 //
-// *** Requires this Arduino library
-// https://github.com/MHeironimus/ArduinoJoystickLibrary
 //--------------------------------------------------------------------

-#include <Joystick.h>
-
-Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID+1,JOYSTICK_TYPE_GAMEPAD,
-  8, 0,                  // Button Count, Hat Switch Count
-  true, true, false,     // X and Y, but no Z Axis
-  false, false, false,   // No Rx, Ry, or Rz
-  false, false,          // No rudder or throttle
-  false, false, false);  // No accelerator, brake, or steering
-
-
-  /*//pin values from keyboard version of sketch
-  int upPin = 2;
-  int downPin = 3;
-  int leftPin = 4;
-  int rightPin = 5;
-  int buttonOnePin = 6;
-  int buttonTwoPin = 7;
-  int buttonThreePin = 8;
-  int buttonFourPin = 9;
-  int buttonFivePin = 10;
-  int buttonSixPin = 11;
-  int playerSelectBitOnePin = 12;
-  int playerSelectBitTwoPin = 13;
-  */
+#include <XInput.h>
 #define pinGamepadButtonPairs_SIZE 12
 int pinGamepadButtonPairs[] =
 {
-  6, 3,
-  7, 4,
-  8, 5,
-  9, 0,
-  10, 1,
-  11, 2
+  6, 4,
+  7, 5,
+  8, 6,
+  9, 1,
+  10, 2,
+  11, 3
 };

 int lastQuitButtonChordState;
 #define quitButtonPinChord_LENGTH 3
 int quitButtonPinChord[] = { 9, 10, 11 };
 #define USE_QUIT_BUTTON_CHORD true
-#define QUIT_JOYSTICK_BUTTON 7
-
+#define QUIT_JOYSTICK_BUTTON 8
+#define ADC_MAX 4095
+#define JOYMIN -32768
+#define JOYMID 0
+#define JOYMAX 32767

 //UP >  DOWN > LEFT > RIGHT
 #define pinJoystickDirectionPins_SIZE 4
@@ -84,14 +63,15 @@
     pinMode(pin, INPUT_PULLUP);
   }

-
-  pinMode(A0, INPUT_PULLUP);
-
   // Initialize Joystick Library
-  Joystick.begin();
-  Joystick.setXAxisRange(-1, 1);
-  Joystick.setYAxisRange(-1, 1);
-  Joystick.setButton(6,0); //set button 7 off
+  //Joystick.begin();
+  //Joystick.setXAxisRange(-1, 1);
+  //Joystick.setYAxisRange(-1, 1);
+  //Joystick.setZAxisRange(-1, 1);
+  //Joystick.setButton(6,0); //set button 7 off
+  //XInput.setJoystickRange(0, ADC_MAX);  // Set joystick range to the ADC
+  XInput.setAutoSend(false);
+  XInput.begin();
 }

@@ -106,41 +86,64 @@
     int currentButtonState = !digitalRead(pin);
     if (currentButtonState != lastButtonState[i])
     {
-      Joystick.setButton(joystickButton, currentButtonState);
+      //Joystick.setButton(joystickButton, currentButtonState);
+      if (currentButtonState)
+      {
+        XInput.press(joystickButton);
+      }
+      else
+      {
+         XInput.release(joystickButton);
+      }
       lastButtonState[i] = currentButtonState;
     }
   }

+int finalX = JOYMID;
+int finalY = JOYMID;
   for (int i = 0; i < pinJoystickDirectionPins_SIZE / 2; i++)
   {
-    int posPin = !digitalRead(pinJoystickDirectionPins[(2 * i) + 1]);
-    int negativePin = !digitalRead(pinJoystickDirectionPins[(2 * i)]);
+    int posPin;
+    int negativePin;

-    int finalAxisVal = 0;
+
+    int finalAxisVal = JOYMID;

     bool isHorizontal = i == 1;
-
+
+    if (!isHorizontal)
+    {
+       posPin = !digitalRead(pinJoystickDirectionPins[(2 * i)]);
+      negativePin = !digitalRead(pinJoystickDirectionPins[(2 * i) + 1]);
+    }
+    else
+    {
+      posPin = !digitalRead(pinJoystickDirectionPins[(2 * i) + 1]);
+      negativePin = !digitalRead(pinJoystickDirectionPins[(2 * i)]);
+    }
     if (posPin)
     {

-      finalAxisVal = 127;
+      finalAxisVal = JOYMAX;

     }
     else if (negativePin)
     {
-      finalAxisVal = -127;
+      finalAxisVal = JOYMIN;
     }

     if (isHorizontal)
     {
-      Joystick.setXAxis(finalAxisVal);
+      finalX = finalAxisVal;
+     // Joystick.setXAxis(finalAxisVal);
     }
     else
     {
-      Joystick.setYAxis(finalAxisVal);
+      finalY = finalAxisVal;
     }
   }
+  XInput.setJoystick(JOY_LEFT, finalX, finalY);

   //--- QUIT BUTTON SIMULATED ----
   if (USE_QUIT_BUTTON_CHORD)
@@ -154,19 +157,31 @@

     if (currentQuitButtonChordState != lastQuitButtonChordState)
     {
-      Joystick.setButton(QUIT_JOYSTICK_BUTTON, currentQuitButtonChordState);
+      if (currentQuitButtonChordState)
+      {
+        XInput.press(QUIT_JOYSTICK_BUTTON);
+      }
+      else
+      {
+         XInput.release(QUIT_JOYSTICK_BUTTON);
+      }
+      //Joystick.setButton(QUIT_JOYSTICK_BUTTON, currentQuitButtonChordState);
     }

     lastQuitButtonChordState = currentQuitButtonChordState;
   }
   //------
  ZeroUnusedAxes();
-  delay(10);
+  XInput.send();
 }

 void ZeroUnusedAxes()
 {
   //fishy looking, but without this line, Unity games with default input
   //get constant spurious input
-  Joystick.setZAxis(-127);
+  //Joystick.setZAxis(0);
+  //Joystick.setRxAxis(0);
+  //Joystick.setRyAxis(0);
+  //Joystick.setHatSwitch(0, -1);
+  //Joystick.setHatSwitch(1, -1);
 }


COH:25: $Id$ working?

COH:25: $Id$ working?

--- Arduino/COHEAT2015/testBranch20150719/V0p2_Main/V0p2_Main.ino
+++ Arduino/COHEAT2015/testBranch20150719/V0p2_Main/V0p2_Main.ino
@@ -173,7 +173,7 @@
   {
   serialPrintAndFlush(F("board V0.2 REV"));
   serialPrintAndFlush(V0p2_REV);
-  serialPrintAndFlush(F("; code $Id$ ")); // Expect SVN to substitute the Id keyword here with svn:keywords property set.
+  serialPrintAndFlush(F("; code $Id: ebf1e586609ba1370e863d4011681e8f73d1713f $ ")); // Expect SVN/git to substitute the Id keyword here with svn:keywords property set.
   serialPrintAndFlush(_YYYYMmmDD);
   serialPrintAndFlush(F(" " __TIME__));
   serialPrintlnAndFlush();


Fix comment for gyro conversion. (#40)

Fix comment for gyro conversion. (#40)

--- Arduino/victoria_teensy_ros_node/victoria_teensy_ros_node.ino
+++ Arduino/victoria_teensy_ros_node/victoria_teensy_ros_node.ino
@@ -391,8 +391,8 @@
 geometry_msgs::Vector3 convertGyro(const LSM6& imu) {
   // LSM6DS33 data sheet has accelerometer default
   // full scale setting with a conversion factor of
-  // 0.061/LSB mg. Convert to g (* .001),
-  // and 1 g = 9.81 m/s^2.
+  // 4.375/LSB mdps. Convert to dps (* .001),
+  // and 1 dps = 0.01745329251994 rad/sec.
   static const double conversionFactor(4.375 * 0.001 * 0.01745329251994);

   geometry_msgs::Vector3 converted;


Fixed StringLength example

Fixed StringLength example

--- build/shared/examples/08.Strings/StringLength/StringLength.ino
+++ build/shared/examples/08.Strings/StringLength/StringLength.ino
@@ -23,7 +23,7 @@

   // send an intro:
   Serial.println("\n\nString  length():");
-  Serial.ptintln();
+  Serial.println();
 }

 void loop() {


Typo fix

Typo fix

--- alarm.ino
+++ alarm.ino
@@ -203,7 +203,7 @@
     linked_list_t * iterator = alarms;
     while (iterator != NULL) {
         current_alarm = GET_MEMBER(iterator, alarm_t, timestamp);
-        if (current_timestamp < current_timestamp && current_alarm < lowest_time)
+        if (current_timestamp < current_alarm && current_alarm < lowest_time)
             lowest_time = current_alarm;
         NEXT(iterator);
     }


add buggy code

add buggy code

--- MASTER_crusher/MASTER_crusher.ino
+++ MASTER_crusher/MASTER_crusher.ino
@@ -2,16 +2,13 @@
 #include <ZumoReflectanceSensorArray.h>
 #include <Pushbutton.h>
 #include <ZumoMotors.h>
-
 #include <NewServo.h>

-#define treshold 1800

-ZumoReflectanceSensorArray reflectanceSensors;
+ZumoReflectanceSensorArray reflectanceSensors(QTR_NO_EMITTER_PIN);
 ZumoMotors motors;

 double lastDistance = 100;
-
 bool flipServo = false;

 unsigned int reflectanceValues[6];
@@ -23,6 +20,7 @@
 #define echoPin 5
 #define servoPin 4

+#define treshold 1800
 #define REVERSE_SPEED     200 // 0 is stopped, 400 is full speed
 #define TURN_SPEED        400
 #define FORWARD_SPEED     100
@@ -44,28 +42,21 @@
 void loop() {
   int distance = getDistance();

-  Serial.println(servoPin);
-  detectLine(reflectanceValues);
-  rotateServoNext();
-  killOpponent(servoPosition, distance);
-  detectLine(reflectanceValues);
+  detectLine();
   rotateServoNext();
   detectOpponent(servoPosition, distance);
-  detectLine(reflectanceValues);
+  killOpponent(servoPosition, distance);
   motors.setSpeeds(0, 0);
 }

-void detectLine(int reflectanceValues[]) {
-  reflectanceSensors.read(reflectanceValues);
-  Serial.println(reflectanceValues[1]);
-  Serial.println(reflectanceValues[4]);
+void detectLine() {
+  //reflectanceSensors.read(reflectanceValues);
   if (isLineLeft(reflectanceValues)) {
     // if leftmost sensor detects line, reverse and turn to the right
     motors.setSpeeds(-REVERSE_SPEED, -REVERSE_SPEED);
     delay(REVERSE_DURATION);
     motors.setSpeeds(TURN_SPEED, -TURN_SPEED);
     delay(TURN_DURATION);
-    motors.setSpeeds(FORWARD_SPEED, FORWARD_SPEED);
   }
   else if (isLineRight(reflectanceValues))
   {
@@ -74,7 +65,6 @@
     delay(REVERSE_DURATION);
     motors.setSpeeds(-TURN_SPEED, TURN_SPEED);
     delay(TURN_DURATION);
-    motors.setSpeeds(FORWARD_SPEED, FORWARD_SPEED);
   }
 }

@@ -105,21 +95,22 @@
 }

 void rotateServoNext() {
+  Serial.println("SERVO POSITION:");
   Serial.println(servoPosition);
   if (servoPosition > 160 || servoPosition < 20) {
     flipServo = !flipServo;
   }
   if (flipServo) {
-     rotateServo((servoPosition + 20) % 181);
+     rotateServo(servoPosition + 10);
   } else {
-      rotateServo((servoPosition - 20) % 0);
+      rotateServo(servoPosition - 10);
   }
 }

 void rotateServo(int sPosition) {
   servo.write(sPosition);
   servoPosition = sPosition;
-  delay(100);
+  delay(50);
 }

 void killOpponent(int positionServo, double distance) {
@@ -139,7 +130,6 @@
 }

 void detectOpponent(int positionServo, double distance) {
-   Serial.println(distance);
   if (distance < 20) {
     if (positionServo > 90) {
       // turn left
@@ -157,6 +147,7 @@
       motors.setSpeeds(0, 0);
     }
     rotateServo(90);
+    flipServo = !flipServo;
     delay(200);
   }
 }


Make the traffic intelligent.

Make the traffic intelligent.

--- src/main/main.ino
+++ src/main/main.ino
@@ -20,16 +20,20 @@
 // Light delays
 unsigned long amberLightDelay = 2000; //2sec
 unsigned long minimumGreenLight = 20000; //20 sec
+unsigned long minimumNSGreenLight = 20000; //20 sec
+unsigned long minimumEWGreenLight = 20000; //20 sec
 unsigned long vehicleTime = 5000; //5s
 unsigned long redLightDelay = 3000; //3 sec

 int vehicleNSCounter = 0;   // counter for the number of vehicles in NS
 int vehicleNSState = 0;        // current state of the vehicleNS button
 int lastVehicleNSState = 0;    // previous state of the vehicleNS button
+int maxVehicleNSCount = 20; //maximum sensor can read

 int vehicleEWCounter = 0;   // counter for the number of vehicleNS in EW
 int vehicleEWState = 0;        // current state of the vehicleNS button
 int lastVehicleEWState = 0;    // previous state of the vehicleNS button
+int maxVehicleEWCount = 20; //maximum sensor can read

 // time since processing started
 unsigned long timeSinceStart;
@@ -49,31 +53,40 @@
 };

 enum trafficStates traffic = NS_GREEN;
+enum trafficStates previousSignalState = NS_GREEN;

 //FUNCTIONS

 // Keep track of the number of vehicles in NS
 void countNSVehicles() {
-  if (vehicleNSState != lastVehicleNSState) {
-    if (vehicleNSState == HIGH) {
-      vehicleNSCounter = vehicleNSCounter + 1;
-      Serial.print("North-South vehicle total count: ");
-      Serial.println(vehicleNSCounter);
-    }
-  }
-  lastVehicleNSState = vehicleNSState;
+  if (maxVehicleNSCount > vehicleNSCounter) {
+    if (vehicleNSState != lastVehicleNSState) {
+      if (vehicleNSState == HIGH) {
+        vehicleNSCounter = vehicleNSCounter + 1;
+        Serial.print("North-South vehicle total count: ");
+        Serial.println(vehicleNSCounter);
+      }
+    }
+    lastVehicleNSState = vehicleNSState;
+  } else {
+    Serial.println("Stop pressing the push button NS sensor can't detect anymore vehicle");
+  }
 }

 // Keep track of the number of vehicles in EW
 void countEWVehicles() {
-  if (vehicleEWState != lastVehicleEWState) {
-    if (vehicleEWState == HIGH) {
-      vehicleEWCounter = vehicleEWCounter + 1;
-      Serial.print("East-West vehicle total count: ");
-      Serial.println(vehicleEWCounter);
-    }
-  }
-  lastVehicleEWState = vehicleEWState;
+  if (maxVehicleEWCount > vehicleEWCounter) {
+    if (vehicleEWState != lastVehicleEWState) {
+      if (vehicleEWState == HIGH) {
+        vehicleEWCounter = vehicleEWCounter + 1;
+        Serial.print("East-West vehicle total count: ");
+        Serial.println(vehicleEWCounter);
+      }
+    }
+    lastVehicleEWState = vehicleEWState;
+  } else {
+    Serial.println("Stop pressing the push button EW sensor can't detect anymore vehicle");
+  }
 }

 /**
@@ -105,10 +118,44 @@
   }
 }

+void sampleVehicles() {
+  if (previousSignalState != traffic) {
+    if (traffic == NS_GREEN && vehicleNSCounter < 8) {
+      minimumNSGreenLight = minimumGreenLight;
+      previousSignalState = NS_GREEN;
+      Serial.print("NS_GREEN normal green signal time: ");
+      Serial.println(minimumNSGreenLight/1000);
+    }
+
+    if (traffic == NS_GREEN && vehicleNSCounter >= 8) {
+      minimumNSGreenLight = minimumGreenLight * (vehicleNSCounter / 4);
+      previousSignalState = NS_GREEN;
+      Serial.print("NS_GREEN calculated green signal time: ");
+      Serial.println(minimumNSGreenLight/1000);
+    }
+
+    if (traffic == EW_GREEN && vehicleEWCounter < 8) {
+      minimumEWGreenLight = minimumGreenLight;
+      previousSignalState = EW_GREEN;
+      Serial.print("EW_GREEN normal green signal time: ");
+      Serial.println(minimumEWGreenLight/1000);
+    }
+
+    if (traffic == EW_GREEN && vehicleEWCounter >= 8) {
+      minimumEWGreenLight = minimumGreenLight * (vehicleEWCounter / 4);
+      previousSignalState = EW_GREEN;
+      Serial.print("EW_GREEN calculated Green signal time: ");
+      Serial.println(minimumEWGreenLight/1000);
+    }
+  }
+}
+
 //creates a couple timers that will fire repeatedly every x ms
 TimedAction vehiclesNSThread = TimedAction(50, countNSVehicles); // checks for NS vehicle every 50 sec and count the total vehicle
 TimedAction vehiclesEWThread = TimedAction(50, countEWVehicles); // checks for ES vehicle every 50 sec and count the total vehicle
 TimedAction vehicleRemovalThread = TimedAction(1000, passVehicles); //a vehicle take minimum 5 to pass
+TimedAction signalThread = TimedAction(5000, sampleVehicles); //samples vehicle at both end
+

 // where's our third task? well, it's the loop itself :) the task
@@ -139,12 +186,12 @@
   switch (traffic) {
     case NS_GREEN:
       if (vehicleEWCounter > 0) {
-        changeEWGreenToAmber();
+        changeNSGreenToAmber();
       }
       break;
     case EW_GREEN:
       if (vehicleNSCounter > 0) {
-        changeNSGreenToAmber();
+        changeEWGreenToAmber();
       }
       break;
     case NS_AMBER:
@@ -168,6 +215,7 @@
   vehiclesNSThread.check();
   vehiclesEWThread.check();
   vehicleRemovalThread.check();
+  signalThread.check();

   vehicleEWState = digitalRead(vehicleEW);
   vehicleNSState = digitalRead(vehicleNS);
@@ -182,8 +230,8 @@
   }
 }

-void changeEWGreenToAmber() {
-  if (timeSinceStart - previousTimeSinceStart > minimumGreenLight) {
+void changeNSGreenToAmber() {
+  if (timeSinceStart - previousTimeSinceStart > minimumNSGreenLight) {
     Serial.println("Vehicle EAST-WEST direction. Changing signal EAST-WEST to green");

     //change NS to amber
@@ -193,15 +241,19 @@
     previousTimeSinceStart = timeSinceStart;
   }
   else {
-    //if waiting for green light
-    Serial.print("Time left for changing EAST WEST to green in : ");
-    Serial.print((long(minimumGreenLight) - (timeSinceStart - previousTimeSinceStart)) / long(1000));
-    Serial.println("s");
-  }
-}
-
-void changeNSGreenToAmber() {
-  if (timeSinceStart - previousTimeSinceStart > minimumGreenLight) {
+    //limit printing
+    long remainingTime =  (minimumNSGreenLight - (timeSinceStart - previousTimeSinceStart)) / long(1000);
+    if (remainingTime % 3 == 0) {      //if waiting for green light
+      //if waiting for green light
+      Serial.print("Time left for changing EAST WEST to green in : ");
+      Serial.print(remainingTime);
+      Serial.println("s");
+    }
+  }
+}
+
+void changeEWGreenToAmber() {
+  if (timeSinceStart - previousTimeSinceStart > minimumEWGreenLight) {
     Serial.println("Vehicle NORTH-SOUTH direction. Changing signal NORTH-SOUTH to green");

     //change EW to amber
@@ -209,10 +261,13 @@
     traffic = EW_AMBER;
     previousTimeSinceStart = timeSinceStart;
   } else {
-    //if waiting for green light
-    Serial.print("Time left for changing NORTH SOUTH to green in : ");
-    Serial.print((long(minimumGreenLight) - (timeSinceStart - previousTimeSinceStart)) / long(1000));
-    Serial.println("s");
+    //limit printing
+    long remainingTime =  (minimumEWGreenLight - (timeSinceStart - previousTimeSinceStart)) / long(1000);
+    if (remainingTime % 3 == 0) {      //if waiting for green light
+      Serial.print("Time left for changing NORTH SOUTH to green in : ");
+      Serial.print(remainingTime);
+      Serial.println("s");
+    }
   }
 }


remove unnecessary logs on the serial connection to prevent slowdowns

--- colorduino/colorduino_serial.ino
+++ colorduino/colorduino_serial.ino
@@ -124,7 +124,6 @@
 void doCommand() {
   switch(opcode) {
     case BMP:
-      Serial.println("bmp");
       drawFullColorBitmap();
       break;
     case COL:
@@ -143,7 +142,6 @@

   opcode = NO_CMD;
   bufferIndex = 0;
-  Serial.println("ack");
 }

 void setup() {
@@ -153,7 +151,6 @@

   // Set port mode, load data structures and start the timer
   Colorduino.init();
-  // Set white balance
   Colorduino.setWhiteBalance(36, 63, 63);

   Serial.println("ready.");


basic framework in place

basic framework in place

--- controller/firmware/firmware.ino
+++ controller/firmware/firmware.ino
@@ -3,43 +3,43 @@
 Adafruit_MCP23017 mcp0, mcp1;

 typedef struct encoder {
-	Adafruit_MCP23017 mcpX;		// which mcp chip is this encoder on
+	Adafruit_MCP23017 *mcpX;	// which mcp chip is this encoder on
 	uint8_t pinA, pinB, pinSW;	// which pins are A, B, and SW
 	boolean A, B, sw;			// last value of A and B and SW
-	unsigned int value;			// value of encoder
-	unsigned int min_value;		// min value encoder can have
-	unsigned int max_value;		// max value encoder can have
+	int16_t value;				// value of encoder
+	int16_t min_value;			// min value encoder can have
+	int16_t max_value;			// max value encoder can have
 } encoder_t;

 #define ENCODERS 8
 // setup the encoder data structures
 encoder_t encoders[ENCODERS] = {
-	{ mcp0, 0, 1, 2,    true, true, false, 0, 0, 20 },
-	{ mcp0, 3, 4, 5,    true, true, false, 0, 0, 20 },
-	{ mcp0, 8, 9, 10,   true, true, false, 0, 0, 20 },
-	{ mcp0, 11, 12, 13, true, true, false, 0, 0, 20 },
-	{ mcp1, 0, 1, 2,    true, true, false, 0, 0, 20 },
-	{ mcp1, 3, 4, 5,    true, true, false, 0, 0, 20 },
-	{ mcp1, 8, 9, 10,   true, true, false, 0, 0, 20 },
-	{ mcp1, 11, 12, 13, true, true, false, 0, 0, 20 }
+	{ &mcp0, 0, 1, 2,    true, true, false, 0, 0, 20 },
+	{ &mcp0, 3, 4, 5,    true, true, false, 0, 0, 20 },
+	{ &mcp0, 8, 9, 10,   true, true, false, 0, 0, 20 },
+	{ &mcp0, 11, 12, 13, true, true, false, 0, 0, 20 },
+	{ &mcp1, 0, 1, 2,    true, true, false, 0, 0, 20 },
+	{ &mcp1, 3, 4, 5,    true, true, false, 0, 0, 20 },
+	{ &mcp1, 8, 9, 10,   true, true, false, 0, 0, 20 },
+	{ &mcp1, 11, 12, 13, true, true, false, 0, 0, 20 }
 };

 typedef struct button {
-	Adafruit_MCP23017 mcpX;		// which mcp is this button on, NULL if teensy pin
+	Adafruit_MCP23017 *mcpX;	// which mcp is this button on, NULL if teensy pin
 	uint8_t pin;				// pin #
 	boolean sw;					// state of switch
 } button_t;

 #define BUTTONS 16
 button_t buttons[BUTTONS] = {
-	{ mcp0, 6,  false },
-	{ mcp0, 7,  false },
-	{ mcp0, 14, false },
-	{ mcp0, 15, false },
-	{ mcp1, 6,  false },
-	{ mcp1, 7,  false },
-	{ mcp1, 14, false },
-	{ mcp1, 15, false },
+	{ &mcp0, 6,  false },
+	{ &mcp0, 7,  false },
+	{ &mcp0, 14, false },
+	{ &mcp0, 15, false },
+	{ &mcp1, 6,  false },
+	{ &mcp1, 7,  false },
+	{ &mcp1, 14, false },
+	{ &mcp1, 15, false },
 	{ NULL, 2,  false },
 	{ NULL, 3,  false },
 	{ NULL, 4,  false },
@@ -72,32 +72,99 @@
 void setup() {
 	int i;

+	// intialize the i2c devices
 	mcp0.begin(0);
 	mcp1.begin(1);

 	// setup input pins for encoders, note the encoder
 	// pins have their own pullups
 	for (i = 0; i < ENCODERS; ++i) {
-		encoder[i].mcpX.pinMode(encoder[i].pinA, INPUT);
-		encoder[i].mcpX.pinMode(encoder[i].pinB, INPUT);
-		encoder[i].mcpX.pinMode(encoder[i].pinSW, INPUT);
+		encoders[i].mcpX->pinMode(encoders[i].pinA, INPUT);
+		encoders[i].mcpX->pinMode(encoders[i].pinB, INPUT);
+		encoders[i].mcpX->pinMode(encoders[i].pinSW, INPUT);
 	}

 	// setup input pins and enable pullups
 	for (i = 0; i < BUTTONS; ++i) {
-		if (button[i].mcpX) {
-			button[i].mcpX.pinMode(button[i].pin, INPUT);
-			button[i].mcpX.pullUp(button[i].pin, HIGH);
+		if (buttons[i].mcpX) {
+			buttons[i].mcpX->pinMode(buttons[i].pin, INPUT);
+			buttons[i].mcpX->pullUp(buttons[i].pin, HIGH);
 		} else {
-			pinMode(button[i].pin, INPUT_PULLUP);
+			pinMode(buttons[i].pin, INPUT_PULLUP);
 		}
 	}

 	// read initial values in, assumes all strings are unobstructed
 	for (i = 0; i < STRINGS; ++i) {
-		string[i].value = analogRead(string[i].pin);
+		strings[i].value = analogRead(strings[i].pin);
 	}
 }

+uint16_t gpioAB[2];
+boolean A, B, sw;
+unsigned int value;
+
 void loop() {
+	int i;
+
+	// read all the ports on the mcps
+	gpioAB[0] = mcp0.readGPIOAB();
+	gpioAB[1] = mcp1.readGPIOAB();
+
+	// process the encoders
+	for (i == 0; i < ENCODERS; ++i) {
+		if (encoders[i].mcpX == &mcp0) {
+			A = bitRead(gpioAB[0], encoders[i].pinA);
+			B = bitRead(gpioAB[0], encoders[i].pinB);
+			sw = bitRead(gpioAB[0], encoders[i].pinSW);
+		} else {
+			A = bitRead(gpioAB[1], encoders[i].pinA);
+			B = bitRead(gpioAB[1], encoders[i].pinB);
+			sw = bitRead(gpioAB[1], encoders[i].pinSW);
+		}
+		// this needs to actually do something here
+		// like report the state change over midi
+		if (sw != encoders[i].sw) {
+			encoders[i].sw = sw;
+		}
+		// the encoder has changed state
+		// increase?
+		if (A != encoders[i].A) {
+			encoders[i].A = !encoders[i].A;
+			if (encoders[i].A && !encoders[i].B) {
+				encoders[i].value += 1;
+				if (encoders[i].value > encoders[i].max_value)
+					encoders[i].value = encoders[i].max_value;
+			}
+		}
+		// decrease?
+		if (B != encoders[i].B) {
+			encoders[i].B = !encoders[i].B;
+			if (encoders[i].B && !encoders[i].A) {
+				encoders[i].value -= 1;
+			if (encoders[i].value < encoders[i].min_value)
+				encoders[i].value = encoders[i].min_value;
+		}
+	}
+
+	// process the buttons
+	for (i = 0; i < BUTTONS; ++i) {
+		if (buttons[i].mcpX == &mcp0) {
+			sw = bitRead(gpioAB[0], buttons[i].pin);
+		} else if (buttons[i].mcpX == &mcp1) {
+			sw = bitRead(gpioAB[1], buttons[i].pin);
+		} else {
+			sw = digitalRead(buttons[i].pin);
+		}
+		// this needs to actually do something here
+		// like report the state change over midi
+		if (sw != buttons[i].sw) {
+			buttons[i].sw = sw;
+		}
+	}
+
+	// this needs to do something with the new value
+	for (i = 0; i < STRINGS; ++i) {
+		strings[i].value = analogRead(strings[i].pin);
+	}
 }


Send feedback after order(to allow to modify it based on order for simulation purpose)

--- Arduino/GroundUnit/GroundUnit.ino
+++ Arduino/GroundUnit/GroundUnit.ino
@@ -158,9 +158,9 @@
    processSerialInput();
    processRFInput();
    computeFeedback();
-   sendFeedback();
    computeOrder();
    sendOrder();
+   sendFeedback();
    delay(10);
 }
 void processRFInput()


arduino parse BitSmang

arduino parse BitSmang

--- Arduino/TurquoiseBicuspidBLE.ino
+++ Arduino/TurquoiseBicuspidBLE.ino
@@ -3,8 +3,7 @@
 SoftwareSerial btSerial(9, 10); // TX, RX

 // Global
-String BUFFER = "";
-int BUT = 2;
+int BUTT = 2;
 int BUTT_STATE = 0;
 int TIME_START = 0;
 int REDPIN = 6;
@@ -37,7 +36,7 @@
 int TYPE = 0;
 int NUMB = 0;
 int TIME = 0;
-int PETE = 0;
+int REPT = 0;

 char API;
 char R;
@@ -46,7 +45,7 @@

 void setup()
 {
-  pinMode(BUT, INPUT);
+  pinMode(BUTT, INPUT);
   pinMode(REDPIN, OUTPUT);
   pinMode(GREPIN, OUTPUT);
   pinMode(BLUPIN, OUTPUT);
@@ -79,7 +78,7 @@
 void loop()
 {
   // clear button
-  BUTT_STATE = digitalRead(BUT);
+  BUTT_STATE = digitalRead(BUTT);
   if(BUTT_STATE == HIGH) {
     Serial.println("Clear");
   }
@@ -87,25 +86,54 @@
   int index = 0;
   if(btSerial.available()) {
     while(btSerial.available()) {
-      if(index == 0) {
-        API = btSerial.read();
-      }
-      else if(index == 1) {
-        R = btSerial.read();
-      }
-      else if(index == 2) {
-        G = btSerial.read();
-      }
-      else if(index == 3) {
-        B = btSerial.read();
-      }
-      index++;
-      delay(1);
-    }
+      API = btSerial.read();
+      delay(1);
+      R = btSerial.read();
+      delay(1);
+      G = btSerial.read();
+      delay(1);
+      B = btSerial.read();
+      delay(1);
+    }
+
     Serial.print("API:");
     Serial.print(API, DEC);
     Serial.print(", Binary:");
     Serial.println(API, BIN);
+
+    // parse API
+    REPT = 0;
+    TIME = 0;
+    NUMB = 0;
+    TYPE = 0;
+
+    REPT = API & 3;
+    API >>= 2;
+    TIME = API & 3;
+    API >>= 2;
+    NUMB = API & 3;
+    API >>= 2;
+    TYPE = API &3;
+
+    Serial.print("TYPE:");
+    Serial.print(TYPE, DEC);
+    Serial.print(", Binary:");
+    Serial.println(TYPE, BIN);
+
+    Serial.print("NUMB:");
+    Serial.print(NUMB, DEC);
+    Serial.print(", Binary:");
+    Serial.println(NUMB, BIN);
+
+    Serial.print("TIME:");
+    Serial.print(TIME, DEC);
+    Serial.print(", Binary:");
+    Serial.println(TIME, BIN);
+
+    Serial.print("REPT:");
+    Serial.print(REPT, DEC);
+    Serial.print(", Binary:");
+    Serial.println(REPT, BIN);

     Serial.print("R:");
     Serial.print(R, DEC);


Adding Light and buttons

Adding Light and buttons

--- sensomatic.ino
+++ sensomatic.ino
@@ -4,28 +4,32 @@

 #define PIN_RX     1 // Serial
 #define PIN_TX     2 // Serial
-#define PIN_LED_R  3 // LED
-#define PIN_D4     4 //
+#define PIN_LED_G  3 // LED
+#define PIN_D4     4 // Button
 #define PIN_DHT    5 // Hum and Temp Sensor
-#define PIN_D6     6 //
-#define PIN_D7     7 //
-#define PIN_D8     8 //
-#define PIN_LED_G  9 // LED
-#define PIN_LED_B 10 // LED
+#define PIN_D6     6 // Button
+#define PIN_D7     7 // Button
+#define PIN_D8     8 // Button
+#define PIN_LED_B  9 // LED
+#define PIN_LED_R 10 // LED
 #define PIN_MOSI  11 // Programming
 #define PIN_MISO  12 // Programming
 #define PIN_SCK   13 // Programming
 #define PIN_A1    A1 //
 #define PIN_A2    A2 //
-#define PIN_A3    A3 //
+#define PIN_LIGHT A3 // Light
 #define PIN_A4    A4 //
-#define PIN_A5    A5 // fff
+#define PIN_A5    A5 //

-#define sampleDelay 1000
+#define SAMPLE_DELAY    1000
+#define BUTTON_DELAY     500
+#define AVERAGE_COUNTER  100
+#define NUM_BUTTONS        4

 dht          DHT;
 CmdMessenger cmdMessenger = CmdMessenger(Serial, ',', ';');
 uint32_t     lastSampleTime;
+uint32_t     lastButtonTime[NUM_BUTTONS];

 enum{
   kAcknowledge,
@@ -36,16 +40,22 @@
   kSetB,
   kGetTemp,
   kGetHumidity,
+  kGetLight,
+  kTemp,
+  kHumidity,
+  kLight,
+  kButtonPressed,
 };

 void attachCommandCallbacks(){
-  cmdMessenger.attach(OnUnknownCommand);
-  cmdMessenger.attach(kSetRgb,   OnSetRgb);
-  cmdMessenger.attach(kSetR,        OnSetR);
-  cmdMessenger.attach(kSetG,        OnSetG);
-  cmdMessenger.attach(kSetB,        OnSetB);
-  cmdMessenger.attach(kGetTemp,     OnGetTemp);
-  cmdMessenger.attach(kGetHumidity, OnGetHumidity);
+  cmdMessenger.attach(              OnUnknownCommand);
+  cmdMessenger.attach(kSetRgb,      OnSetRgb        );
+  cmdMessenger.attach(kSetR,        OnSetR          );
+  cmdMessenger.attach(kSetG,        OnSetG          );
+  cmdMessenger.attach(kSetB,        OnSetB          );
+  cmdMessenger.attach(kGetTemp,     OnGetTemp       );
+  cmdMessenger.attach(kGetHumidity, OnGetHumidity   );
+  cmdMessenger.attach(kGetLight,    OnGetLight      );
 }

 void OnUnknownCommand(){
@@ -53,44 +63,58 @@
 }

 void OnSetRgb(){
-  cmdMessenger.sendCmd(kAcknowledge);
+  int16_t r = cmdMessenger.readInt16Arg();
+  int16_t g = cmdMessenger.readInt16Arg();
+  int16_t b = cmdMessenger.readInt16Arg();
+
+  analogWrite(PIN_LED_R, r);
+  analogWrite(PIN_LED_G, g);
+  analogWrite(PIN_LED_B, b);
+
+  cmdMessenger.sendCmdStart(kAcknowledge);
 }

 void OnSetR(){
-  uint16_t r = cmdMessenger.readInt16Arg();
+  int16_t r = cmdMessenger.readInt16Arg();
   analogWrite(PIN_LED_R, r);
-  cmdMessenger.sendCmd(kAcknowledge);
+  cmdMessenger.sendCmd(kAcknowledge, r);
 }

 void OnSetG(){
-  uint16_t g = cmdMessenger.readInt16Arg();
+  int16_t g = cmdMessenger.readInt16Arg();
   analogWrite(PIN_LED_G, g);
-  cmdMessenger.sendCmd(kAcknowledge);
+  cmdMessenger.sendCmd(kAcknowledge, g);
 }

 void OnSetB(){
-  uint16_t b = cmdMessenger.readInt16Arg();
+  int16_t b = cmdMessenger.readInt16Arg();
   analogWrite(PIN_LED_B, b);
-  cmdMessenger.sendCmd(kAcknowledge);
+  cmdMessenger.sendCmd(kAcknowledge, b);
 }

 void checkSampleTime(){
-  if( (millis() - lastSampleTime) > sampleDelay){
-    wdt_reset();
+  if( (millis() - lastSampleTime) > SAMPLE_DELAY){
     DHT.read22(PIN_DHT);
-    wdt_reset();
     lastSampleTime = millis();
   }
 }

 void OnGetTemp(){
   checkSampleTime();
-  cmdMessenger.sendCmd(kAcknowledge, DHT.temperature);
+  cmdMessenger.sendCmd(kTemp, DHT.temperature);
 }

 void OnGetHumidity(){
   checkSampleTime();
-  cmdMessenger.sendCmd(kAcknowledge, DHT.humidity);
+  cmdMessenger.sendCmd(kHumidity, DHT.humidity);
+}
+
+void OnGetLight(){
+  uint32_t light = 0;
+  for (uint16_t i = 0; i < AVERAGE_COUNTER; i++){
+    light += analogRead(PIN_LIGHT);
+  }
+  cmdMessenger.sendCmd(kLight, light / AVERAGE_COUNTER);
 }

 void setup() {
@@ -100,14 +124,37 @@
   cmdMessenger.sendCmd(kAcknowledge, "Arduino ready!");
   wdt_enable(WDTO_2S);
   lastSampleTime = 0;
-  analogWrite(PIN_LED_R, 255);
-  analogWrite(PIN_LED_G, 255);
-  analogWrite(PIN_LED_B, 255);
+  for(uint8_t i = 0; i < NUM_BUTTONS; i++){
+    lastButtonTime[i] = 0;
+  }
+  analogWrite(PIN_LED_R, 0);
+  analogWrite(PIN_LED_G, 0);
+  analogWrite(PIN_LED_B, 0);
+  pinMode(PIN_D4, INPUT_PULLUP);
+  pinMode(PIN_D6, INPUT_PULLUP);
+  pinMode(PIN_D7, INPUT_PULLUP);
+  pinMode(PIN_D8, INPUT_PULLUP);
+}
+
+void buttonCheck(uint16_t pin, uint8_t button){
+  if(!digitalRead(pin)) {
+    if( (millis() - lastButtonTime[button]) > BUTTON_DELAY){
+      cmdMessenger.sendCmd(kButtonPressed, button);
+      lastButtonTime[button] = millis();
+    }
+  }
+}
+
+void parseButtons(){
+  buttonCheck(PIN_D4, 0);
+  buttonCheck(PIN_D6, 1);
+  buttonCheck(PIN_D7, 2);
+  buttonCheck(PIN_D8, 3);
 }

 void loop() {
   cmdMessenger.feedinSerialData();
+  parseButtons();
   wdt_reset();
 }

-


mi-test: modifications

mi-test: modifications

--- prototype/mi-test/mi-test.ino
+++ prototype/mi-test/mi-test.ino
@@ -9,30 +9,50 @@

 void setup()
 {
+    Serial.begin(9600);
+
     motor_init(&motor_conveyor, 0.36, MOTOR_CONVEYOR_PIN,
         MOTOR_CONVEYOR_INT_PIN, motor_conveyor_interrupt);
     motor_init(&motor_feeder, 1.0, MOTOR_FEEDER_PIN, MOTOR_FEEDER_INT_PIN,
         motor_feeder_interrupt);
     distance_sensor_init(&distance_sensor, RANGE_TRIG, RANGE_ECHO);

+    distance_to_wall = calibrate_ultra_sound_sensor();
+    delay(1000);
+    Serial.print("Distance to wall: ");
+    Serial.println(distance_to_wall);
+    delay(2500);
     motor_turn(&motor_conveyor);
-    distance_to_wall = calibrate_ultra_sound_sensor();
+    feed_ball();
 }

 void loop()
 {
-    int32_t test_dist = distance_sensor_measure_distance(&distance_sensor);
-    if (test_dist >= distance_to_wall)
+    int32_t test_dist = distance_sensor_double_take(); //distance_sensor_measure_distance(&distance_sensor);
+    //Serial.println(test_dist);
+
+    if(test_dist + 10 < distance_to_wall)
     {
-        delay(100);
-        return;
+        Serial.print("Log: ");
+        Serial.println(millis());
     }
+
+    static uint32_t time = millis();
+    if (time + 5000 < millis())
+    {
+        feed_ball();
+        time = millis();
+    }
+
+    return;
     uint32_t pos = motor_get_degrees(&motor_conveyor);
     // Change TARGET1 for delay before requesting image
-    while(pos + TARGET1 > motor_get_degrees(&motor_conveyor)) {}
-    Serial.print("b");
+    while(pos + 225 > motor_get_degrees(&motor_conveyor)) {}
+    Serial.print("Command:");
+    Serial.print(2);
+    Serial.println("end");
     // Change TARGET2 for delay after requesting image
-    while(pos + TARGET2 > motor_get_degrees(&motor_conveyor)) {}
+    while(pos + 720 > motor_get_degrees(&motor_conveyor)) {}
     feed_ball();
 }

@@ -48,23 +68,13 @@

 void feed_ball()
 {
-  const uint8_t feed_iteration = 8;
-  static uint8_t feed_counter = feed_iteration;
   static int16_t deg = 90;

-  // We only feed a ball every x iterations
-  if (feed_counter == feed_iteration)
-  {
     motor_turn_to_degree(&motor_feeder, deg);

     deg += 90;
     if (deg == 360)
-      deg = 0;
-
-    feed_counter = 0;
-  }
-
-  feed_counter++;
+        deg = 0;
 }

 int32_t calibrate_ultra_sound_sensor()
@@ -81,4 +91,18 @@
   }

   return min;
+}
+
+uint32_t distance_sensor_double_take()
+{
+    uint32_t reading_1 = distance_sensor_measure_distance(&distance_sensor);
+    uint32_t reading_2 = distance_sensor_measure_distance(&distance_sensor);
+    if (reading_1 == reading_2)
+    {
+        return reading_1;
+    }
+    else
+    {
+        return INT16_MAX;
+    }
 }


Deleted Software Serial TwoPortRXExample because it was a duplicate of TwoPortReceive example

--- libraries/SoftwareSerial/examples/TwoPortRXExample/TwoPortRXExample.ino
+++ libraries/SoftwareSerial/examples/TwoPortRXExample/TwoPortRXExample.ino
@@ -1,50 +0,0 @@
-#include <SoftwareSerial.h>
-
-SoftwareSerial ss(2, 3);
-SoftwareSerial ss2(4, 5);
-
-/* This sample shows how to correctly process received data
-   on two different "soft" serial ports.  Here we listen on
-   the first port (ss) until we receive a '?' character.  Then
-   we begin listening on the other soft port.
-*/
-
-void setup()
-{
-  // Start the HW serial port
-  Serial.begin(57600);
-
-  // Start each soft serial port
-  ss.begin(4800);
-  ss2.begin(4800);
-
-  // By default, the most recently "begun" port is listening.
-  // We want to listen on ss, so let's explicitly select it.
-  ss.listen();
-
-  // Simply wait for a ? character to come down the pipe
-  Serial.println("Data from the first port: ");
-  char c = 0;
-  do
-    if (ss.available())
-    {
-      c = (char)ss.read();
-      Serial.print(c);
-    }
-  while (c != '?');
-
-  // Now listen on the second port
-  ss2.listen();
-
-  Serial.println("Data from the second port: ");
-}
-
-void loop()
-{
-  if (ss2.available())
-  {
-    char c = (char)ss2.read();
-    Serial.print(c);
-  }
-}
-


send raw data in readable data

send raw data in readable data

--- arduino-raw-tx/arduino-raw-tx.ino
+++ arduino-raw-tx/arduino-raw-tx.ino
@@ -1,18 +1,39 @@
 #include <Wire.h> // enable to communicate with I2C / TWI devices
-#include <L3G4200D.h>
+#include <L3G4200D.h> // gyroscope library
+#include <ADXL345.h>  // accelerometer library
+#include <HMC5883L.h> // digital compass library
+#include <BMP085.h>   // barometric pressure & temperature sensor library

+ADXL345 accel;
+Vector raw, norm;

 void setup() {

 	Serial.begin(9600);
 	Wire.begin();
+
+	Serial.println("Initialize ADXL345...");
+	if (!accel.begin()) {
+		Serial.println("Initialize ADXL345 failed...");
+		delay(1000);
+	}
+
+	accel.setRange(ADXL345_RANGE_2G);
+	accel.setDataRate(ADXL345_DATARATE_100HZ);
 }

 void loop() {

-	Serial.println("Hello");
-	delay(1000);
+	raw = accel.readRaw();

+	Serial.print("RAW:  ");
+	Serial.print(raw.XAxis);
+	Serial.print("\t");
+	Serial.print(raw.YAxis);
+	Serial.print("\t");
+	Serial.println(raw.ZAxis);
+
+	delay(10);
 }


send sensible pixel data

send sensible pixel data

--- arduino/led_matrix/led_matrix.ino
+++ arduino/led_matrix/led_matrix.ino
@@ -17,7 +17,7 @@
 }

 void loop() {
-  for (i = 0; i < NUM_LEDS; ++i) {
+  for (i = 0; i < NUM_LEDS; i++) {
     while (Serial.available() < 3);

     r = Serial.read();


Moved GPSBaud to after other setup options

--- libraries/FreeIMU/examples/FreeIMU_serial_ARM_CPU/FreeIMU_serial_ARM_CPU.ino
+++ libraries/FreeIMU/examples/FreeIMU_serial_ARM_CPU/FreeIMU_serial_ARM_CPU.ino
@@ -38,6 +38,7 @@

 #define HAS_GPS 0
 #define BaudRate 57600
+static const unsigned long GPSBaud = 38400;

 KalmanFilter kFilters[4];
 int k_index = 3;
@@ -54,7 +55,6 @@

 #if HAS_GPS
   #include <TinyGPS++.h>
-  static const unsigned long GPSBaud = 57600;
   // The TinyGPS++ object
   TinyGPSPlus gps;
   // The serial connection to the GPS device


added initial PID controller

added initial PID controller

--- Firmware/JBC-Soldering-Controller/JBC-Soldering-Controller.ino
+++ Firmware/JBC-Soldering-Controller/JBC-Soldering-Controller.ino
@@ -15,6 +15,7 @@
 #include <DigitalIO.h>          //https://github.com/greiman/DigitalIO
 #include <dell_psu.h>           //https://github.com/timothyjager/DellPSU
 #include <EEWrap.h>             //https://github.com/Chris--A/EEWrap
+#include <PID_v1.h>             //https://github.com/br3ttb/Arduino-PID-Library/

 #include "ads1118.h"

@@ -39,7 +40,8 @@
 const int SPARE_18         = 18;
 const int SPARE_19         = 19;
 const int CURRENT_FEEDBACK = 20;
-const int CRADLE_SENSOR    = 21;
+const int CRADLE_SENSOR    = 21;
+const int OLED_RESET       = 4; //the library asks for a reset pin, but our OLED doesn't have one

 //EEProm parameter data (https://github.com/Chris--A/EEWrap)
 //Use the xxx_e types rather than the standard types like uint8_t
@@ -55,12 +57,16 @@
 //Volatile Variables used by the interrupt handlers
 volatile int16_t adc_value=0;          //ADC value read by ADS1118
 volatile int16_t temperature_value=0;  //internal temp of ADS1118
+double kP=2, kI=0, kD=0;

 //Global Objects
 #define OLED_RESET 4
 Adafruit_SSD1306 display(OLED_RESET);  //TODO: look into this reset pin. The LCD i'm using does not have a reset pin, just PWR,GND,SDA,SCL

-DellPSU dell(1);   //specify the desired Arduino pin number
+DellPSU dell(DELL_PSU);   //specify the desired Arduino pin number
+double Setpoint, Input, Output;
+//Specify the links and initial tuning parameters
+PID myPID(&Input, &Output, &Setpoint,kP,kI,kD, DIRECT); //TODO: map this properly

 //----------------Setup-------------------------
@@ -117,9 +123,14 @@
   */
   //setup PWM and interrupts. These use the 16 bit timer1
   #define PWM_PERIOD_US 20000 //20000us = 20ms = 50Hz PWM frequency. We have to go slow enough to allow time for sampling the ADC during the PWM off time
-  #define PWM_PERIOD_MS (PWM_PERIOD_US/1000)
+  #define PWM_PERIOD_MS (PWM_PERIOD_US/1000)
+  #define PWM_MAX_DUTY 1023 //the timer 1 libray scales the PWM duty cycle from 0 to 1023 where 0=0% and 1023=100%
+  #define ADC_SAMPLE_WINDOW_US 1200 //1200us = 1.2ms //we need 1.2 ms to sample the ADC. assuming 860 SPS setting
+  #define ADC_SAMPLE_WINDOW_PWM_DUTY (((PWM_PERIOD_US-ADC_SAMPLE_WINDOW_US)*PWM_MAX_DUTY)/PWM_PERIOD_US)  // we set our PWM duty to as close to 100% as possible while still leaving enough time for the ADC sample.
+  #define MAX_HEATER_PWM_DUTY ADC_SAMPLE_WINDOW_PWM_DUTY //our maximum allowable heater PWM duty is equal to the sampling window PWM duty.
+
   Timer1.initialize(PWM_PERIOD_US);
-  Timer1.pwm(LPINB, 1023-61); //we need 1.2 ms to sample the ADC. assuming 860 SPS setting
+  Timer1.pwm(LPINB, ADC_SAMPLE_WINDOW_PWM_DUTY);
   Timer1.pwm(LPINA, 2); //100% = 1023
   delay(PWM_PERIOD_MS); //make sure both PWM's have run at least one full period before enabling interrupts

@@ -129,6 +140,10 @@
   //enable comparator A interrupt vector.
   //This will fire an interrupt on each edge of our main PWM. we only use this once to synchronise the B sampling interrupt.
   TIMSK1 = _BV(OCIE1A);
+
+
+  //enable the PID loop
+  myPID.SetMode(AUTOMATIC);
 }

 void PulsePin(int pin)
@@ -196,6 +211,8 @@
 void loop(void)
 {

+  static long next_millis = millis()+1000;
+
  //block interrupts while retreiving the temperature values.
  noInterrupts();
  int16_t adc_copy=adc_value;
@@ -214,14 +231,27 @@
     display.setTextSize(1);
     display.setTextColor(WHITE);
     display.setCursor(0,0);
+float tempfloat = (float)adc_copy * 0.1901 + 1.6192+(float)temperature_copy;

   display.print(temperature_copy);
  display.print(" ");
- display.println(adc_copy);
+ display.print(adc_copy);
+  display.print(" ");
+   display.print(tempfloat);

 display.display();
-
- delay(300);
+ Serial.print(millis());
+ Serial.print(" ");
+ Serial.print(adc_copy);
+ Serial.print(" ");
+ Serial.println(tempfloat);
+ //delay(1000);
+
+while (millis()<next_millis);
+
+next_millis+=1000;
+
+
 }


Make init match standard init for example

--- examples/FirebaseTranscriber_ESP8266/FirebaseTranscriber_ESP8266.ino
+++ examples/FirebaseTranscriber_ESP8266/FirebaseTranscriber_ESP8266.ino
@@ -21,10 +21,10 @@
 #include <Transcriber.h>

 // Set these to run example.
-#define FIREBASE_HOST ""
-#define FIREBASE_AUTH ""
-#define WIFI_SSID ""
-#define WIFI_PASSWORD ""
+#define FIREBASE_HOST "example.firebaseio.com"
+#define FIREBASE_AUTH "token_or_secret"
+#define WIFI_SSID "SSID"
+#define WIFI_PASSWORD "PASSWORD"

 #define FIREBASE_PATH "/fthing"
 #define DIGITAL_IN D1


Improved YunSerialTerminal

Improved YunSerialTerminal

Removing calls to Serial.available() adds more CPU time to better
handle a sustained 250kbps flow

--- libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino
+++ libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino
@@ -43,14 +43,14 @@
 boolean commandMode = false;

 void loop() {
-  // copy from virtual serial line to uart and vice versa
-  if (Serial.available()) {           // got anything from USB-Serial?
-    char c = (char)Serial.read();     // read from USB-serial
+  // copy from USB-CDC to UART
+  int c = Serial.read();              // read from USB-CDC
+  if (c != -1) {                      // got anything?
     if (commandMode == false) {       // if we aren't in command mode...
       if (c == '~') {                 //    Tilde '~' key pressed?
         commandMode = true;           //       enter in command mode
       } else {
-        Serial1.write(c);             //    otherwise write char to Linino
+        Serial1.write(c);             //    otherwise write char to UART
       }
     } else {                          // if we are in command mode...
       if (c == '0') {                 //     '0' key pressed?
@@ -65,18 +65,21 @@
       } else if (c == '3') {          //     '3' key pressed?
         Serial1.begin(500000);        //        set speed to 500000
         Serial.println("Speed set to 500000");
-      } else if (c == '~') {
+      } else if (c == '~') {          //     '~` key pressed?
+                                      //        send "bridge shutdown" command
         Serial1.write((uint8_t *)"\xff\0\0\x05XXXXX\x7f\xf9", 11);
         Serial.println("Sending bridge's shutdown command");
       } else {                        //     any other key pressed?
-        Serial1.write('~');           //        write '~' to Linino
-        Serial1.write(c);             //        write char to Linino
+        Serial1.write('~');           //        write '~' to UART
+        Serial1.write(c);             //        write char to UART
       }
       commandMode = false;            //     in all cases exit from command mode
     }
   }
-  if (Serial1.available()) {          // got anything from Linino?
-    char c = (char)Serial1.read();    // read from Linino
-    Serial.write(c);                  // write to USB-serial
+
+  // copy from UART to USB-CDC
+  c = Serial1.read();                 // read from UART
+  if (c != -1) {                      // got anything?
+    Serial.write(c);                  //    write to USB-CDC
   }
 }