Got wiggly ears working.

Got wiggly ears working.

--- frankenbear.ino
+++ frankenbear.ino
@@ -17,41 +17,41 @@
 //     Wiggle ears.
 // NOTE: I fear that this isn't going to work. We're going to probably have to use an IR proximity sensor.
 //TMP36 Pin Variables
-int sensorPin = 0; // the analog pin the TMP36's Vout (sense) pin is connected to
+//int sensorPin = 0; // the analog pin the TMP36's Vout (sense) pin is connected to
 // the resolution is 10 mV / degree centigrade with a
 // 500 mV offset to allow for negative temperatures
 // This code assumes the temperature sensor is plugged into A0, 5V, and GND. Looking at the flat side of the temperature sensor, the left pin is power, middle is analog input, and right is GND.
-void setup()
-{
-  Serial.begin(9600);  // Start the serial connection with the computer to view the result open the serial monitor.
-}
-
-void loop()
-{
-  //getting the voltage reading from the temperature sensor
-  int reading = analogRead(sensorPin);
-
-  // converting that reading to voltage, for 3.3v arduino use 3.3
-  float voltage = reading * 5.0;
-  voltage /= 1024.0;
-
-  // print out the voltage
-  Serial.print(voltage);
-  Serial.println(" volts");
-
-  // now print out the temperature
-  float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree with 500 mV offset
-  //to degrees ((voltage - 500mV) times 100)
-  Serial.print(temperatureC);
-  Serial.println(" degrees C");
-
-  // now convert to Fahrenheit
-  float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
-  Serial.print(temperatureF);
-  Serial.println(" degrees F");
-
-  delay(1000);                                     // waiting 1 second
-}
+//void setup()
+//{
+//  Serial.begin(9600);  // Start the serial connection with the computer to view the result open the serial monitor.
+//}
+//
+//void loop()
+//{
+//  //getting the voltage reading from the temperature sensor
+//  int reading = analogRead(sensorPin);
+//
+//  // converting that reading to voltage, for 3.3v arduino use 3.3
+//  float voltage = reading * 5.0;
+//  voltage /= 1024.0;
+//
+//  // print out the voltage
+//  Serial.print(voltage);
+//  Serial.println(" volts");
+//
+//  // now print out the temperature
+//  float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree with 500 mV offset
+//  //to degrees ((voltage - 500mV) times 100)
+//  Serial.print(temperatureC);
+//  Serial.println(" degrees C");
+//
+//  // now convert to Fahrenheit
+//  float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
+//  Serial.print(temperatureF);
+//  Serial.println(" degrees F");
+//
+//  delay(1000);                                     // waiting 1 second
+//}

@@ -75,74 +75,109 @@
  * BSD license, all text above must be included in any redistribution
  ****************************************************/

-//#include <Wire.h>
-//#include <Adafruit_PWMServoDriver.h>
-//
-//// called this way, it uses the default address 0x40
-//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
-//// you can also call it with a different address you want
-////Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
-//
-//// Depending on your servo make, the pulse width min and max may vary, you
-//// want these to be as small/large as possible without hitting the hard stop
-//// for max range. You'll have to tweak them as necessary to match the servos you
-//// have!
-//#define SERVOMIN 160 // this is the 'minimum' pulse length count (out of 4096)
-//#define SERVOMAX 585 // this is the 'maximum' pulse length count (out of 4096)
-//
-//// our servo # counter
-////uint8_t servonum = 0;
-//uint8_t left_arm = 0;
-//uint8_t right_arm = 1;
-//
-//void setup() {
-//  Serial.begin(9600);
-//  Serial.println("16 channel Servo test!");
-//
-//  pwm.begin();
-//
-//  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
-//
-//  // Sets left_arm and right_arm at their min and max values.
-//  pwm.setPWM(left_arm, 0, SERVOMIN);
-//  pwm.setPWM(right_arm, 0, SERVOMAX);
-//}
-//
-//// you can use this function if you'd like to set the pulse length in seconds
-//// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. its not precise!
-//void setServoPulse(uint8_t n, double pulse) {
-//  double pulselength;
-//
-//  pulselength = 1000000;   // 1,000,000 us per second
-//  pulselength /= 60;   // 60 Hz
-//  Serial.print(pulselength); Serial.println(" us per period");
-//  pulselength /= 4096;  // 12 bits of resolution
-//  Serial.print(pulselength); Serial.println(" us per bit");
-//  pulse *= 1000;
-//  pulse /= pulselength;
-//  Serial.println(pulse);
-//  pwm.setPWM(n, 0, pulse);
-//}
-//
-//void loop() {
-//  // Drive each servo one at a time
-//  //  Serial.println(servonum);
-//  uint16_t pulselen_right = SERVOMAX;
-//  for (uint16_t pulselen_left = SERVOMIN; pulselen_left < SERVOMAX && pulselen_right > SERVOMIN; pulselen_left++) {
-//    pwm.setPWM(left_arm, 0, pulselen_left);
-//    pwm.setPWM(right_arm, 0, pulselen_right);
-//    pulselen_right--;
-//  }
-//  delay(500);
-//  uint16_t pulselen_left = SERVOMAX;
-//  for (uint16_t pulselen_right = SERVOMIN; pulselen_right < SERVOMAX && pulselen_left > SERVOMIN; pulselen_right++) {
-//    pwm.setPWM(right_arm, 0, pulselen_right);
-//    pwm.setPWM(left_arm, 0, pulselen_left);
-//    pulselen_left--;
-//  }
-//  delay(500);
-////
-////  servonum ++;
-////  if (servonum > 3) servonum = 0;
-//}
+#include <Wire.h>
+#include <Adafruit_PWMServoDriver.h>

+// Uses the default address 0x40.
+Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
+
+#define BIG_SERVO_MIN 160 // this is the 'minimum' pulse length count (out of 4096)
+#define BIG_SERVO_MAX 584 // this is the 'maximum' pulse length count (out of 4096)
+#define MICRO_SERVO_MIN 160
+#define MICRO_SERVO_MAX 584
+
+#define LEFT_ARM_OPEN    266
+#define LEFT_ARM_CLOSED  372
+#define RIGHT_ARM_CLOSED 372
+#define RIGHT_ARM_OPEN   478
+
+#define LEFT_EAR_BACK 475
+#define LEFT_EAR_FORWARD 265
+#define RIGHT_EAR_BACK 265
+#define RIGHT_EAR_FORWARD 475
+#define MIDDLE_EAR 370
+
+uint8_t left_arm = 0;
+uint8_t right_arm = 1;
+uint8_t left_ear = 2;
+uint8_t right_ear = 3;
+
+int flag = 0;
+int kissed_flag = 1;
+
+void setup()
+{
+  // Initialize serial port.
+  Serial.begin(9600);
+
+  pwm.begin();
+
+  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
+
+  // Sets left_arm and right_arm at their min and max values.
+//  pwm.setPWM(left_arm, 0, LEFT_ARM_OPEN);
+//  delay(1000);
+//  pwm.setPWM(right_arm, 0, RIGHT_ARM_OPEN);
+//  delay(1000);
+
+  // Sets left_arm and right_arm at their min and max values.
+  pwm.setPWM(left_ear, 0, MIDDLE_EAR);
+//  delay(1000);
+  pwm.setPWM(right_ear, 0, MIDDLE_EAR);
+//  delay(1000);
+}
+
+void loop()
+{
+  // When kissed or hugged (proximity sensor)
+  if ( kissed_flag > 0 )
+  {
+    wiggle_ears();
+    kissed_flag++;
+
+    if ( kissed_flag > 4 )
+    {
+      kissed_flag = 0;
+    }
+  }
+
+  // On button press?
+  if ( flag )
+  {
+    hug();
+    flag = 0;
+  }
+}
+
+void wiggle_ears()
+{
+  pwm.setPWM(left_ear, 0, LEFT_EAR_FORWARD);
+  pwm.setPWM(right_ear, 0, RIGHT_EAR_BACK);
+  delay(500);
+  pwm.setPWM(left_ear, 0, LEFT_EAR_BACK);
+  pwm.setPWM(right_ear, 0, RIGHT_EAR_FORWARD);
+  delay(500);
+}
+
+void hug()
+{
+  // Bring arms in together.
+  uint16_t pulselen_right = RIGHT_ARM_OPEN;
+  for (uint16_t pulselen_left = LEFT_ARM_OPEN; pulselen_left < LEFT_ARM_CLOSED && pulselen_right > RIGHT_ARM_CLOSED; pulselen_left++) {
+    pwm.setPWM(left_arm, 0, pulselen_left);
+    pwm.setPWM(right_arm, 0, pulselen_right);
+    pulselen_right--;
+    delay(1);
+  }
+  delay(1000);
+
+  // Release arms.
+  uint16_t pulselen_left = LEFT_ARM_CLOSED;
+  for (uint16_t pulselen_right = RIGHT_ARM_CLOSED; pulselen_right < RIGHT_ARM_OPEN && pulselen_left > LEFT_ARM_OPEN; pulselen_right++) {
+    pwm.setPWM(right_arm, 0, pulselen_right);
+    pwm.setPWM(left_arm, 0, pulselen_left);
+    pulselen_left--;
+    delay(1);
+  }
+  delay(1000);
+}


Cleanup comments & minor fixes

Cleanup comments & minor fixes


Code update ...

Code update ...

--- i2c_cmd_master_esp8266/i2c_cmd_master_esp8266.ino
+++ i2c_cmd_master_esp8266/i2c_cmd_master_esp8266.ino
@@ -120,202 +120,202 @@
       // ********************
       // * STDPB1_1 Command *
       //*********************
-    case 'a': case 'A': {
-      byte cmdTX[1] = { STDPB1_1 };
-      byte txSize = sizeof(cmdTX), rxSize = 0;
-      Serial.print("ESP8266 - Sending Opcode >>> ");
-      Serial.print(cmdTX[0]);
-      Serial.println("(STDPB1_1)");
-      // Transmit command
-      byte transmitData[1] = { 0 };
-      for (int i = 0; i < txSize; i++) {
-        transmitData[i] = cmdTX[i];
-        Wire.beginTransmission(slaveAddress);
-        Wire.write(transmitData[i]);
-        Wire.endTransmission();
-      }
-      // Receive acknowledgement
-      blockRXSize = Wire.requestFrom(slaveAddress, (byte)1);
-      byte ackRX[1] = { 0 };   // Data received from slave
-      for (int i = 0; i < blockRXSize; i++) {
-        ackRX[i] = Wire.read();
-      }
-      if (ackRX[0] == AKDPB1_1) {
-        Serial.print("ESP8266 - Command ");
-        Serial.print(cmdTX[0]);
-        Serial.print(" parsed OK <<< ");
-        Serial.println(ackRX[0]);
-      }
-      else {
-        Serial.print("ESP8266 - Error parsing ");
-        Serial.print(cmdTX[0]);
-        Serial.print(" command! <<< ");
-        Serial.println(ackRX[0]);
-      }
-      break;
-    }
-              // ********************
-              // * STDPB1_0 Command *
-              //*********************
-    case 's': case 'S': {
-      byte cmdTX[1] = { STDPB1_0 };
-      byte txSize = sizeof(cmdTX), rxSize = 0;
-      Serial.print("ESP8266 - Sending Opcode >>> ");
-      Serial.print(cmdTX[0]);
-      Serial.println("(STDPB1_0)");
-      // Transmit command
-      byte transmitData[1] = { 0 };
-      for (int i = 0; i < txSize; i++) {
-        transmitData[i] = cmdTX[i];
-        Wire.beginTransmission(slaveAddress);
-        Wire.write(transmitData[i]);
-        Wire.endTransmission();
-      }
-      // Receive acknowledgement
-      blockRXSize = Wire.requestFrom(slaveAddress, (byte)1);
-      byte ackRX[1] = { 0 };   // Data received from slave
-      for (int i = 0; i < blockRXSize; i++) {
-        ackRX[i] = Wire.read();
-      }
-      if (ackRX[0] == AKDPB1_0) {
-        Serial.print("ESP8266 - Command ");
-        Serial.print(cmdTX[0]);
-        Serial.print(" parsed OK <<< ");
-        Serial.println(ackRX[0]);
-      }
-      else {
-        Serial.print("ESP8266 - Error parsing ");
-        Serial.print(cmdTX[0]);
-        Serial.print(" command! <<< ");
-        Serial.println(ackRX[0]);
-      }
-      break;
-    }
-              // ********************
-              // * STANAPB3 Command *
-              //*********************
-    case 'd': case 'D': {
-      byte cmdTX[3] = { STANAPB3, 0, 0 };
-      //byte txSize = sizeof(cmdTX);
-      byte txSize = 3;
-      byte operandValue = 0;
-      Serial.print("ESP8266 - Sending Opcode >>> ");
-      Serial.print(cmdTX[0]);
-      Serial.println("(STANAPB3)");
-      Serial.print("Please enter a value from 0 to 255 for this command: ");
-      while (newByte == false) {
-        //operandValue = random(1, 255);
-        operandValue = ReadByte();
-      }
-      if (newByte == true) {
-        Serial.println("");
-        Serial.print("Command STANAPB3 Operand Value (decimal): ");
-        Serial.println(operandValue);
-        Serial.println("");
-        cmdTX[1] = operandValue;
+      case 'a': case 'A': {
+        byte cmdTX[1] = { STDPB1_1 };
+        byte txSize = sizeof(cmdTX), rxSize = 0;
         Serial.print("ESP8266 - Sending Opcode >>> ");
         Serial.print(cmdTX[0]);
-        Serial.println("(STANAPB3)");
-        cmdTX[2] = CalculateCRC(cmdTX, 2);
+        Serial.println("(STDPB1_1)");
         // Transmit command
         byte transmitData[1] = { 0 };
         for (int i = 0; i < txSize; i++) {
-          if (i > 0) {
-            Serial.print("ESP8266 - Sending Operand >>> ");
-            Serial.println(cmdTX[i]);
-          }
           transmitData[i] = cmdTX[i];
           Wire.beginTransmission(slaveAddress);
           Wire.write(transmitData[i]);
           Wire.endTransmission();
         }
-      newByte = false;
-      }
-      // Receive acknowledgement
-      blockRXSize = Wire.requestFrom(slaveAddress, (byte)2);
-      byte ackRX[2] = { 0 };   // Data received from slave
-      for (int i = 0; i < blockRXSize; i++) {
-        ackRX[i] = Wire.read();
-      }
-      if (ackRX[0] == ACKNAPB3) {
-        Serial.print("ESP8266 - Command ");
+        // Receive acknowledgement
+        blockRXSize = Wire.requestFrom(slaveAddress, (byte)1);
+        byte ackRX[1] = { 0 };   // Data received from slave
+        for (int i = 0; i < blockRXSize; i++) {
+          ackRX[i] = Wire.read();
+        }
+        if (ackRX[0] == AKDPB1_1) {
+          Serial.print("ESP8266 - Command ");
+          Serial.print(cmdTX[0]);
+          Serial.print(" parsed OK <<< ");
+          Serial.println(ackRX[0]);
+        }
+        else {
+          Serial.print("ESP8266 - Error parsing ");
+          Serial.print(cmdTX[0]);
+          Serial.print(" command! <<< ");
+          Serial.println(ackRX[0]);
+        }
+        break;
+      }
+      // ********************
+      // * STDPB1_0 Command *
+      //*********************
+      case 's': case 'S': {
+        byte cmdTX[1] = { STDPB1_0 };
+        byte txSize = sizeof(cmdTX), rxSize = 0;
+        Serial.print("ESP8266 - Sending Opcode >>> ");
         Serial.print(cmdTX[0]);
-        Serial.print(" parsed OK <<< ");
-        Serial.println(ackRX[0]);
-        Serial.print("ESP8266 - Operand ");
-        Serial.print(cmdTX[1]);
-        Serial.print(" parsed OK <<< ");
-        Serial.println(ackRX[1]);
-      }
-      else {
-      	Serial.print("ESP8266 - Error parsing ");
-      	Serial.print(cmdTX[0]);
-      	Serial.print(" command! <<< ");
-      	Serial.println(ackRX[0]);
-      }
-      break;
-    }
-              // ********************
-              // * READADC2 Command *
-              //*********************
-    case 'f': case 'F': {
-      byte cmdTX[1] = { READADC2 };
-      byte txSize = sizeof(cmdTX), rxSize = 0;
-      Serial.print("ESP8266 - Sending Opcode >>> ");
-      Serial.print(cmdTX[0]);
-      Serial.println("(READADC2)");
-      // Transmit command
-      byte transmitData[1] = { 0 };
-      for (int i = 0; i < txSize; i++) {
-        transmitData[i] = cmdTX[i];
-        Wire.beginTransmission(slaveAddress);
-        Wire.write(transmitData[i]);
-        Wire.endTransmission();
-      }
-      // Receive acknowledgement
-      blockRXSize = Wire.requestFrom(slaveAddress, (byte)4);
-      byte ackRX[4] = { 0 };   // Data received from slave
-      for (int i = 0; i < blockRXSize; i++) {
-        ackRX[i] = Wire.read();
-      }
-      if (ackRX[0] == ACKNADC2) {
-        Serial.print("ESP8266 - Command ");
+        Serial.println("(STDPB1_0)");
+        // Transmit command
+        byte transmitData[1] = { 0 };
+        for (int i = 0; i < txSize; i++) {
+          transmitData[i] = cmdTX[i];
+          Wire.beginTransmission(slaveAddress);
+          Wire.write(transmitData[i]);
+          Wire.endTransmission();
+        }
+        // Receive acknowledgement
+        blockRXSize = Wire.requestFrom(slaveAddress, (byte)1);
+        byte ackRX[1] = { 0 };   // Data received from slave
+        for (int i = 0; i < blockRXSize; i++) {
+          ackRX[i] = Wire.read();
+        }
+        if (ackRX[0] == AKDPB1_0) {
+          Serial.print("ESP8266 - Command ");
+          Serial.print(cmdTX[0]);
+          Serial.print(" parsed OK <<< ");
+          Serial.println(ackRX[0]);
+        }
+        else {
+          Serial.print("ESP8266 - Error parsing ");
+          Serial.print(cmdTX[0]);
+          Serial.print(" command! <<< ");
+          Serial.println(ackRX[0]);
+        }
+        break;
+      }
+      // ********************
+      // * STANAPB3 Command *
+      //*********************
+      case 'd': case 'D': {
+        byte cmdTX[3] = { STANAPB3, 0, 0 };
+        //byte txSize = sizeof(cmdTX);
+        byte txSize = 3;
+        byte operandValue = 0;
+        Serial.print("ESP8266 - Sending Opcode >>> ");
         Serial.print(cmdTX[0]);
-        Serial.print(" parsed OK <<< ");
-        Serial.println(ackRX[0]);
-
-        Serial.print("ESP8266 - Data ");
-        Serial.print(1);
-        Serial.print(" received <<< ");
-        Serial.println(ackRX[1]);
-
-        Serial.print("ESP8266 - Data ");
-        Serial.print(2);
-        Serial.print(" received <<< ");
-        Serial.println(ackRX[2]);
-
-        Serial.print("ESP8266 - Data ");
-        Serial.print(3);
-        Serial.print(" received <<< ");
-        Serial.println(ackRX[3]);
-      }
-      else {
-        Serial.print("ESP8266 - Error parsing ");
+        Serial.println("(STANAPB3)");
+        Serial.print("Please enter a value from 0 to 255 for this command: ");
+        while (newByte == false) {
+          //operandValue = random(1, 255);
+          operandValue = ReadByte();
+        }
+        if (newByte == true) {
+          Serial.println("");
+          Serial.print("Command STANAPB3 Operand Value (decimal): ");
+          Serial.println(operandValue);
+          Serial.println("");
+          cmdTX[1] = operandValue;
+          Serial.print("ESP8266 - Sending Opcode >>> ");
+          Serial.print(cmdTX[0]);
+          Serial.println("(STANAPB3)");
+          cmdTX[2] = CalculateCRC(cmdTX, 2);
+          // Transmit command
+          byte transmitData[1] = { 0 };
+          for (int i = 0; i < txSize; i++) {
+            if (i > 0) {
+              Serial.print("ESP8266 - Sending Operand >>> ");
+              Serial.println(cmdTX[i]);
+            }
+            transmitData[i] = cmdTX[i];
+            Wire.beginTransmission(slaveAddress);
+            Wire.write(transmitData[i]);
+            Wire.endTransmission();
+          }
+        newByte = false;
+        }
+        // Receive acknowledgement
+        blockRXSize = Wire.requestFrom(slaveAddress, (byte)2);
+        byte ackRX[2] = { 0 };   // Data received from slave
+        for (int i = 0; i < blockRXSize; i++) {
+          ackRX[i] = Wire.read();
+        }
+        if (ackRX[0] == ACKNAPB3) {
+          Serial.print("ESP8266 - Command ");
+          Serial.print(cmdTX[0]);
+          Serial.print(" parsed OK <<< ");
+          Serial.println(ackRX[0]);
+          Serial.print("ESP8266 - Operand ");
+          Serial.print(cmdTX[1]);
+          Serial.print(" parsed OK <<< ");
+          Serial.println(ackRX[1]);
+        }
+        else {
+      	  Serial.print("ESP8266 - Error parsing ");
+      	  Serial.print(cmdTX[0]);
+      	  Serial.print(" command! <<< ");
+      	  Serial.println(ackRX[0]);
+        }
+        break;
+      }
+      // ********************
+      // * READADC2 Command *
+      //*********************
+      case 'f': case 'F': {
+        byte cmdTX[1] = { READADC2 };
+        byte txSize = sizeof(cmdTX), rxSize = 0;
+        Serial.print("ESP8266 - Sending Opcode >>> ");
         Serial.print(cmdTX[0]);
-        Serial.print(" command! <<< ");
-        Serial.println(ackRX[0]);
-      }
-      break;
-    }
-              // *******************
-              // * Unknown Command *
-              //********************
-    default: {
-      Serial.print("ESP8266 - Command '");
-      Serial.print(key);
-      Serial.println("' unknown ...");
-      break;
-    }
+        Serial.println("(READADC2)");
+        // Transmit command
+        byte transmitData[1] = { 0 };
+        for (int i = 0; i < txSize; i++) {
+          transmitData[i] = cmdTX[i];
+          Wire.beginTransmission(slaveAddress);
+          Wire.write(transmitData[i]);
+          Wire.endTransmission();
+        }
+        // Receive acknowledgement
+        blockRXSize = Wire.requestFrom(slaveAddress, (byte)4);
+        byte ackRX[4] = { 0 };   // Data received from slave
+        for (int i = 0; i < blockRXSize; i++) {
+          ackRX[i] = Wire.read();
+        }
+        if (ackRX[0] == ACKNADC2) {
+          Serial.print("ESP8266 - Command ");
+          Serial.print(cmdTX[0]);
+          Serial.print(" parsed OK <<< ");
+          Serial.println(ackRX[0]);
+
+          Serial.print("ESP8266 - Data ");
+          Serial.print(1);
+          Serial.print(" received <<< ");
+          Serial.println(ackRX[1]);
+
+          Serial.print("ESP8266 - Data ");
+          Serial.print(2);
+          Serial.print(" received <<< ");
+          Serial.println(ackRX[2]);
+
+          Serial.print("ESP8266 - Data ");
+          Serial.print(3);
+          Serial.print(" received <<< ");
+          Serial.println(ackRX[3]);
+        }
+        else {
+          Serial.print("ESP8266 - Error parsing ");
+          Serial.print(cmdTX[0]);
+          Serial.print(" command! <<< ");
+          Serial.println(ackRX[0]);
+        }
+        break;
+      }
+      // *******************
+      // * Unknown Command *
+      //********************
+      default: {
+        Serial.print("ESP8266 - Command '");
+        Serial.print(key);
+        Serial.println("' unknown ...");
+        break;
+      }
     }
     Serial.println("");
     Serial.println("Please type a command ('a', 's', 'd' or 'f'):");


refine IR broadcast part

refine IR broadcast part

--- glass/glass.ino
+++ glass/glass.ino
@@ -46,7 +46,7 @@
 int XBeeReturnCount;
 boolean ir_bcast_mode = true;
 unsigned long ir_time;
-unsigned int ir_cycle = 300;
+unsigned int ir_cycle = 200;  // broadcat IR signal every X ms
 unsigned int ir_response_threshold = 300;

 // EXPERIMENT
@@ -145,6 +145,7 @@
         if(msgStr.substring(6,9) == "001") {
           //exp list mode
           exp_mode = MODE_IR;
+          ir_bcast_mode = true;

         }else if(msgStr.substring(6,9) == "002") {
           exp_mode = MODE_LIST;


Changing motor setSpeed to setMaxSpeed

Changing motor setSpeed to setMaxSpeed

--- arduino/autofowl/autofowl.ino
+++ arduino/autofowl/autofowl.ino
@@ -184,7 +184,7 @@
   );

   // Set the motors desired constant speed in steps per second
-  Motor.setSpeed( MOTOR_SPEED_STEPS_PER_SECOND );
+  Motor.setMaxSpeed( MOTOR_SPEED_STEPS_PER_SECOND );
   // Set the motors desired acceleration in steps per second per second
   Motor.setAcceleration(MOTOR_ACCEL_STEPS_PER_SEC_PER_SEC);


Removed logging

Removed logging

--- arduino/fasnacht/fasnacht.ino
+++ arduino/fasnacht/fasnacht.ino
@@ -99,11 +99,11 @@
     ChannelFrq = ChannelCount * 100 / (time / 10) / 2;

     //get channel data and write output LEFT AUIO CHANNEL
-    printf("Left Max:%4i Min:%4i Count:%4i | Right Max:%4i Min:%4i Count:%4i | Frq: ", ValueHighest, ValueLowest, ValueCount, ChannelHighest, ChannelLowest, ChannelCount);
-    Serial.print(ValueFrq);
-    Serial.print(" ");
-    Serial.print(ChannelFrq);
-    Serial.println(" ");
+    //printf("Left Max:%4i Min:%4i Count:%4i | Right Max:%4i Min:%4i Count:%4i | Frq: ", ValueHighest, ValueLowest, ValueCount, ChannelHighest, ChannelLowest, ChannelCount);
+    //Serial.print(ValueFrq);
+    //Serial.print(" ");
+    //Serial.print(ChannelFrq);
+    //Serial.println(" ");
     if( (ValueFrq >= 100) && (ValueFrq <= 199) ) {
       digitalWrite(3, 1); //B
       digitalWrite(5, 0); //D


Arduino voltage accuracy fix

Arduino voltage accuracy fix

--- arduino/sketch/src/sketch.ino
+++ arduino/sketch/src/sketch.ino
@@ -7,7 +7,7 @@
 int plant1_value = 0;
 int plant2_value = 0;
 int plant3_value = 0;
-int voltage_value = 0;
+long voltage_value = 0;
 int temperature_value = 0;
 int light_value = 0;

@@ -41,8 +41,18 @@
     light_value = analogRead(A4);
     temperature_value = analogRead(A5);

+    // voltage probing (takes 2s)
+    long sum=0;
+    for(int i=0;i<1000;i++)
+    {
+        sum=voltage_value+sum;
+        voltage_value=analogRead(A3);
+        delay(2);
+    }
+    sum=sum/1000;
+
     // voltage mapping
-    battery_value = (10 * (float)voltage_value * 4980)/1023000;
+    battery_value = 10*sum*4980/(1023.00*1000) * 12.96/14.07; // voltmeter used to determine last factor

     // set led bar accordingly to solar value
     led_bar_value = round((battery_value-10.0)/4.0*10); // min: 10V max: 14V
@@ -70,7 +80,7 @@
         } else if (incomingByte == 51) { // turn relay on if input was ASCII "3"
             digitalWrite(relay_pin,HIGH);
             Serial.println("{ \"relay_state\": 1 }");
-            relay_delay = 30 *4; //30s
+            relay_delay = 30 /2; //30s
             relay_delay_counting = true;
         } else { // otherwise, reply with sensor data

@@ -94,8 +104,6 @@
         delay(100);
         digitalWrite(led_pin,LOW);
     } else {
-        // delay the loop if there was no input
-        delay(250);
         if(relay_delay_counting){
             if(relay_delay > 0){
                 relay_delay--;


buoy: Fix flaot parsing.

buoy: Fix flaot parsing.

--- arduino_buoy/arduino_buoy.ino
+++ arduino_buoy/arduino_buoy.ino
@@ -24,7 +24,7 @@
 #define BATTV_FUDGE 1.098
 #endif
 #define BEACON_INTERVAL 20
-uint8_t rfm_power = 20; // dBmW
+uint8_t rfm_power = 10; // dBmW

 //************* Sensors ****************/
 // Battery Voltage Measurement - Also enables zombie mode
@@ -46,8 +46,8 @@
 DallasTemperature sensors(&ow);

 uint8_t buf[60];
-uint8_t lock =0, sats = 0, nolock=0;
-int GPSerror = 0,navmode = 0,psm_status = 0,lat_int=0,lon_int=0;
+uint8_t lock =0, sats = 0, nolock=0, psm_status = 0;
+int16_t GPSerror = 0,navmode = 0,lat_int=0,lon_int=0;
 int32_t lat = 0, lon = 0, alt = 0, maxalt = 0, lat_dec = 0, lon_dec =0 ,tslf=0;

 #ifdef ENABLE_BATTV_SENSOR
@@ -91,7 +91,7 @@
     nolock=0;
   }

-  sprintf(data,"%sL%s%i.%05d,%s%i.%05d,%ldS%d",data,lat < 0 ? "-" : "",lat_int,lat_dec,lon < 0 ? "-" : "",lon_int,lon_dec,maxalt,sats);
+  sprintf(data,"%sL%s%d.%05ld,%s%d.%05ld,%ldS%d",data,lat < 0 ? "-" : "",lat_int,lat_dec,lon < 0 ? "-" : "",lon_int,lon_dec,maxalt,sats);

   sensors.setWaitForConversion(false);
   sensors.requestTemperatures();


whoops, forgot that we're using pull up resistors

--- lesson-2/simple_digital_input_modes.ino
+++ lesson-2/simple_digital_input_modes.ino
@@ -23,8 +23,8 @@
   // read input
   int reading = digitalRead(buttonPin);

-  // advance our mode by 1!
-  if (reading==HIGH){
+  // advance our mode by 1 if the pin is low
+  if (reading==LOW){
     currentPinMode = currentPinMode + 1;
     if (currentPinMode>3) {
       currentPinMode = 0;


Extend black box tests of the control bytes.

--- tests/HILTester/HILTester.ino
+++ tests/HILTester/HILTester.ino
@@ -174,7 +174,7 @@
 	serialSendLong(0x9697);Serial.flush();
 	serialSendLong(0x9899);Serial.flush();
 	serialSendLong(0x9A9B);Serial.flush();
-	serialSendLong(0x9C9D);Serial.flush();
+	serialSendLong(0x9D);Serial.flush(); // 0x9C is the terminating byte that unblocks the terminal. Skip it.
 	serialSendLong(0x9E9F);Serial.flush();
 	serialSendLong(0x8788);Serial.flush();
 	serialSendLong(0x898A);Serial.flush();
@@ -186,7 +186,7 @@
 	serialSendLong(0x9596);Serial.flush();
 	serialSendLong(0x9798);Serial.flush();
 	serialSendLong(0x999A);Serial.flush();
-	serialSendLong(0x9B9C);Serial.flush();
+	serialSendLong(0x9B);Serial.flush(); // 0x9C is the terminating byte that unblocks the terminal. Skip it.
 	serialSendLong(0x9D9E);Serial.flush();
 	Serial.write(0x9F);
 	Serial.flush(); // Wait for the outgoing buffer to be cleared.
@@ -195,37 +195,85 @@
 void sendControl(void)
 /* Send all C0 and C1 control characters from WikiPedia:
  https://en.wikipedia.org/wiki/C0_and_C1_control_codes#DCS) interweaved with
-  'normal' ones to make sure the replacement works.
+  'normal' ones and 'A's to make sure the replacement works.
   Send each byte at a time. */
 {
-	Serial.write(0x0);Serial.write(0x1);Serial.write(0x2);Serial.write(0x3);
-	Serial.write(0x4);Serial.write(0x5);Serial.write(0x6);Serial.write(0x7);
-	Serial.write(0x8);Serial.write(0x9);Serial.write(0x0A);Serial.write(0x0B);
-	Serial.write(0x0C);Serial.write(0x0D);Serial.write(0x0E);Serial.write(0x0F);
-	Serial.write(0x10);Serial.write(0x11);Serial.write(0x12);Serial.write(0x13);
-	Serial.write(0x14);Serial.write(0x15);Serial.write(0x16);Serial.write(0x17);
-	Serial.write(0x18);Serial.write(0x19);Serial.write(0x1A);Serial.write(0x1B);
-	Serial.write(0x1C);Serial.write(0x1D);Serial.write(0x1E);Serial.write(0x1F);
-	Serial.write(0x20);Serial.write(0x7F);Serial.write(0x0B);Serial.write(0x0C);
-	Serial.write(0x0D);Serial.write(0x0E);Serial.write(0x0F);Serial.write(0x11);
-	Serial.write(0x12);Serial.write(0x13);Serial.write(0x18);Serial.write(0x19);
-	Serial.write(0x1C);Serial.write(0x1D);Serial.write(0x1E);Serial.write(0x1F);
-	Serial.write(0x80);Serial.write(0x81);Serial.write(0x82);Serial.write(0x83);
-	Serial.write(0x84);Serial.write(0x85);Serial.write(0x86);Serial.write(0x87);
-	Serial.write(0x88);Serial.write(0x89);Serial.write(0x8A);Serial.write(0x8B);
-	Serial.write(0x8C);Serial.write(0x8D);Serial.write(0x8E);Serial.write(0x8F);
-	Serial.write(0x90);Serial.write(0x91);Serial.write(0x92);Serial.write(0x93);
-	Serial.write(0x94);Serial.write(0x95);Serial.write(0x96);Serial.write(0x97);
-	Serial.write(0x98);Serial.write(0x99);Serial.write(0x9A);Serial.write(0x9B);
-	Serial.write(0x9C);Serial.write(0x9D);Serial.write(0x9E);Serial.write(0x9F);
-	Serial.write(0x87);Serial.write(0x88);Serial.write(0x89);Serial.write(0x8A);
-	Serial.write(0x8B);Serial.write(0x8C);Serial.write(0x8D);Serial.write(0x8E);
-	Serial.write(0x8F);Serial.write(0x90);Serial.write(0x91);Serial.write(0x92);
-	Serial.write(0x93);Serial.write(0x94);Serial.write(0x95);Serial.write(0x96);
-	Serial.write(0x97);Serial.write(0x98);Serial.write(0x99);Serial.write(0x9A);
-	Serial.write(0x9B);Serial.write(0x9C);Serial.write(0x9D);Serial.write(0x9E);
-	Serial.write(0x9F);
-	Serial.flush(); // Wait for the outgoing buffer to be cleared.
+	Serial.write(0x0);Serial.write(0x41);Serial.write(0x1);Serial.write(0x41);
+	Serial.write(0x2);Serial.write(0x41);Serial.write(0x3);Serial.write(0x41);
+	Serial.write(0x4);Serial.write(0x41);Serial.write(0x5);Serial.write(0x41);
+	Serial.write(0x6);Serial.write(0x41);Serial.write(0x7);Serial.write(0x41);
+	Serial.write(0x8);Serial.write(0x41);Serial.write(0x9);Serial.write(0x41);
+	Serial.write(0x0A);Serial.write(0x41);Serial.write(0x0B);Serial.write(0x41);
+	Serial.write(0x0C);Serial.write(0x41);Serial.write(0x0D);Serial.write(0x41);
+	Serial.write(0x0E);Serial.write(0x41);Serial.write(0x0F);Serial.write(0x41);
+	Serial.write(0x10);Serial.write(0x41);Serial.write(0x11);Serial.write(0x41);
+	Serial.write(0x12);Serial.write(0x41);Serial.write(0x13);Serial.write(0x41);
+	Serial.write(0x14);Serial.write(0x41);Serial.write(0x15);Serial.write(0x41);
+	Serial.write(0x16);Serial.write(0x41);Serial.write(0x17);Serial.write(0x41);
+	Serial.write(0x18);Serial.write(0x41);Serial.write(0x19);Serial.write(0x41);
+	Serial.write(0x1A);Serial.write(0x41);Serial.write(0x1B);Serial.write(0x41);
+	Serial.write(0x1C);Serial.write(0x41);Serial.write(0x1D);Serial.write(0x41);
+	Serial.write(0x1E);Serial.write(0x41);Serial.write(0x1F);Serial.write(0x41);
+	Serial.write(0x20);Serial.write(0x41);Serial.write(0x7F);Serial.write(0x41);
+	Serial.write(0x0B);Serial.write(0x41);Serial.write(0x0C);Serial.write(0x41);
+	Serial.write(0x0D);Serial.write(0x41);Serial.write(0x0E);Serial.write(0x41);
+	Serial.write(0x0F);Serial.write(0x41);Serial.write(0x11);Serial.write(0x41);
+	Serial.write(0x12);Serial.write(0x41);Serial.write(0x13);Serial.write(0x41);
+	Serial.write(0x18);Serial.write(0x41);Serial.write(0x19);Serial.write(0x41);
+	Serial.write(0x1C);Serial.write(0x41);Serial.write(0x1D);Serial.write(0x41);
+	Serial.write(0x1E);Serial.write(0x41);Serial.write(0x1F);Serial.write(0x41);
+	Serial.write(0x80);Serial.write(0x41);Serial.write(0x81);Serial.write(0x41);
+	Serial.write(0x82);Serial.write(0x41);Serial.write(0x83);Serial.write(0x41);
+	Serial.write(0x84);Serial.write(0x41);Serial.write(0x85);Serial.write(0x41);
+	Serial.write(0x86);Serial.write(0x41);Serial.write(0x87);Serial.write(0x41);
+	Serial.write(0x88);Serial.write(0x41);Serial.write(0x89);Serial.write(0x41);
+	Serial.write(0x8A);Serial.write(0x41);Serial.write(0x8B);Serial.write(0x41);
+	Serial.write(0x8C);Serial.write(0x41);Serial.write(0x8D);Serial.write(0x41);
+	Serial.write(0x8E);Serial.write(0x41);Serial.write(0x8F);Serial.write(0x41);
+	Serial.write(0x90);Serial.write(0x41);Serial.write(0x91);Serial.write(0x41);
+	Serial.write(0x92);Serial.write(0x41);Serial.write(0x93);Serial.write(0x41);
+	Serial.write(0x94);Serial.write(0x41);Serial.write(0x95);Serial.write(0x41);
+	Serial.write(0x96);Serial.write(0x41);Serial.write(0x97);Serial.write(0x41);
+	Serial.write(0x98);Serial.write(0x41);Serial.write(0x99);Serial.write(0x41);
+	Serial.write(0x9A);Serial.write(0x41);Serial.write(0x9B);Serial.write(0x41);
+	Serial.write(0x41);Serial.write(0x9D);Serial.write(0x41); // 0x9C is the terminating byte that unblocks the terminal. Skip it.
+	Serial.write(0x9E);Serial.write(0x41);Serial.write(0x9F);Serial.write(0x41);
+	Serial.write(0x87);Serial.write(0x41);Serial.write(0x88);Serial.write(0x41);
+	Serial.write(0x89);Serial.write(0x41);Serial.write(0x8A);Serial.write(0x41);
+	Serial.write(0x8B);Serial.write(0x41);Serial.write(0x8C);Serial.write(0x41);
+	Serial.write(0x8D);Serial.write(0x41);Serial.write(0x8E);Serial.write(0x41);
+	Serial.write(0x8F);Serial.write(0x41);Serial.write(0x90);Serial.write(0x41);
+	Serial.write(0x91);Serial.write(0x41);Serial.write(0x92);Serial.write(0x41);
+	Serial.write(0x93);Serial.write(0x41);Serial.write(0x94);Serial.write(0x41);
+	Serial.write(0x95);Serial.write(0x41);Serial.write(0x96);Serial.write(0x41);
+	Serial.write(0x97);Serial.write(0x41);Serial.write(0x98);Serial.write(0x41);
+	Serial.write(0x99);Serial.write(0x41);Serial.write(0x9A);Serial.write(0x41);
+	Serial.write(0x9B);Serial.write(0x41);Serial.write(0x41); // 0x9C is the terminating byte that unblocks the terminal. Skip it.
+	Serial.write(0x9D);Serial.write(0x41);Serial.write(0x9E);Serial.write(0x41);
+	Serial.write(0x9F);Serial.write(0x41);
+	Serial.flush(); // Wait for the outgoing buffer to be cleared.
+}
+
+void sendAsAndControl(void)
+/* Send 10 'A' characters, problematic 0x90 control byte, and 10 more 'A's. */
+{
+	for(int i=0; i<10; i++)
+	{
+		Serial.write(0x41); // ASCII for 'A'.
+	}
+	Serial.write(0x90); // 58256 = 'ã'.
+	for(int i=0; i<10; i++)
+	{
+		Serial.write(0x41); // ASCII for 'A'.
+	}
+	Serial.flush();
+}
+
+void sendTerminatingByte(void)
+/* Send 0x9C, which terminates the control byte sequences and unblock the terminal. */
+{
+	Serial.write(0x9C);
+	Serial.flush();
 }

 void sendNonASCII(void)
@@ -442,23 +490,35 @@
 			  		Serial.flush();
 				}
 				break;
-			case 'x': // One of the two bytes that seem to make the log stall
+			case 'x': // One of the two bytes that make the log stall. It's one
+				// of the control bytes that is also sent in C0 and C1 test cases.
 				Serial.write(0x90); // 58256 = 'ã'.
 				Serial.flush();
 				break;
-			case 'y': // One of the two bytes that seem to make the log stall
+			case 'X': // Similar to 'x' but sends 10 'A' before and after 0x90
+				// in order to clearly show where the log stalls.
+				sendAsAndControl();
+				break;
+			case 'y': // One of the two problematic control bytes, which has
+			 	// turned out not to make the log stall.
 				Serial.write(0x84); // 58756 = 'å'.
 				Serial.flush();
 				break;
-			case 'c': // Send all the possible control characters to make sure the replacement works.
+			case 'c': // Send all the possible control characters interweaved with
+				// 'A' to make sure the replacement works. Do not send the
+				// terminating byte 0x9C, however, to stall the log.
 				sendControl();
 				Serial.flush();
 				break;
-			case 'C': // Send all the possible control characters, two at a time to make sure the replacement works.
+			case 'C': // Send all the possible control characters, two at a time
+				// to make sure the replacement works.Do not send the
+				// terminating byte 0x9C, however, to stall the log.
 				sendControlLongs();
 				break;
-		//TODO Sending each C0 and C1 control byte doesn't seem to reproduce the error
-		//TODO of the 'L' and 'x' test cases?
+			case 't': // Send command terminating byte 0x9C to unblock the log
+				// after test cases c, C, x, X, and L.
+				sendTerminatingByte();
+				break;
 		}
 	}
 }


changed types to use like decltype(az0)

changed types to use like decltype(az0)

--- arduino_st/arduino_st.ino
+++ arduino_st/arduino_st.ino
@@ -160,12 +160,12 @@
 static float az0 = 0;
 static float el0 = 0;

-void readSensor(my_helpers::Circular<float, READINGS_AMOUNT_AVR>& az, my_helpers::Circular<float, READINGS_AMOUNT_AVR>& el)
+void readSensor(my_helpers::Circular<decltype(az0), READINGS_AMOUNT_AVR>& az, my_helpers::Circular<decltype(el0), READINGS_AMOUNT_AVR>& el)
 {
     using namespace my_helpers;
     sensorDataReady = false;
     uint8_t mpuIntStatus = mpu.getIntStatus();
-    int16_t fifoCount   = mpu.getFIFOCount();
+    int16_t fifoCount    = mpu.getFIFOCount();

     // check for overflow (this should never happen unless our code is too inefficient)

@@ -198,7 +198,7 @@
                 //https://www.reddit.com/r/Astronomy/comments/3udenf/quaternion_matrix_or_euler_angles_conversion_to/
                 el.push_back_lpf(atan(gravity.x / sqrt(sqrf(gravity.y) + sqrf(gravity.z))) -el0);
                 //az.push_back(-2 * atan2(q.z, q.w));
-                float az1 = removeRotRad<float>(-2.f * atan2(q.z, q.w)) - az0;
+                auto az1 = removeRotRad<decltype(az0)>(-2.f * atan2(q.z, q.w)) - az0;
                 while (az1 < 0.f) az1 += M_PI * 2.f;

                 az.push_back_lpf(az1);
@@ -218,11 +218,12 @@
     static elapsedMillis timeElapsed;
     static elapsedMillis light;

-    static my_helpers::Circular<float , READINGS_AMOUNT_AVR> az(0);
-    static my_helpers::Circular<float , READINGS_AMOUNT_AVR> el(0);
-    static float az_prior = 0;
-    static float el_prior = 0;
-    const static auto lightSens = radians(0.12);
+    static my_helpers::Circular<decltype(az0) , READINGS_AMOUNT_AVR> az(0);
+    static my_helpers::Circular<decltype(el0) , READINGS_AMOUNT_AVR> el(0);
+    static decltype(az0) az_prior = 0;
+    static decltype(el0) el_prior = 0;
+
+    const static float lightSens = radians(0.12);
     static bool leadON = true;
     // if programming failed, don't try to do anything
     if (!dmpReady) return;