Formatted defines

Formatted defines

--- esp8266-weather-station.ino
+++ esp8266-weather-station.ino
@@ -6,7 +6,9 @@
 #undef WITH_SELECT
 #include <mysql.h>

-//defined SQL_USER, SQL_PASS, WIFI_SSID, WIFI_PASS, SQL_SERVER_ADDR
+// defines
+//WIFI_SSID, WIFI_PASS
+//SQL_USER, SQL_PASS, SQL_SERVER_ADDR
 #include "config.h"

 enum SensorIdEnum


Motor and ESC stuff

Motor and ESC stuff

--- Firmware/R2-Quadcopter/R2-Quadcopter.ino
+++ Firmware/R2-Quadcopter/R2-Quadcopter.ino
@@ -419,10 +419,10 @@
     if (motorBL > MOTOR_MAX_LEVEL) motorBL = MOTOR_MAX_LEVEL;//plus grande que 2000
     if (motorBR > MOTOR_MAX_LEVEL) motorBR = MOTOR_MAX_LEVEL;

-    if (motorFR < MOTOR_ZERO_LEVEL + 80) motorFR = MOTOR_ZERO_LEVEL +80;
-    if (motorFL < MOTOR_ZERO_LEVEL + 80) motorFL = MOTOR_ZERO_LEVEL +80;//histoire que les moteurs tournent
-    if (motorBL < MOTOR_ZERO_LEVEL + 80) motorBL = MOTOR_ZERO_LEVEL +80;//quand meme quand on arme
-    if (motorBR < MOTOR_ZERO_LEVEL + 80) motorBR = MOTOR_ZERO_LEVEL +80;
+    if (motorFR < MOTOR_ZERO_LEVEL + 100) motorFR = MOTOR_ZERO_LEVEL +100;
+    if (motorFL < MOTOR_ZERO_LEVEL + 100) motorFL = MOTOR_ZERO_LEVEL +100;//histoire que les moteurs tournent
+    if (motorBL < MOTOR_ZERO_LEVEL + 100) motorBL = MOTOR_ZERO_LEVEL +100;//quand meme quand on arme
+    if (motorBR < MOTOR_ZERO_LEVEL + 100) motorBR = MOTOR_ZERO_LEVEL +100;

     esc_1.writeMicroseconds(motorFR);
     esc_2.writeMicroseconds(motorFL);
@@ -443,6 +443,6 @@
     Proportional_yaw, Integral_yaw, Derivative_yaw = 0;
   }

-  print_imu_speed();
+  print_motors();
   delay(36);
 }


update

update

--- examples/deepsleep/deepSleep_all_wakeups/deepSleep_all_wakeups.ino
+++ examples/deepsleep/deepSleep_all_wakeups/deepSleep_all_wakeups.ino
@@ -16,8 +16,9 @@
    * define the configuration
    * parameters for waking the
    * teensy up.
-   * Only pins:
-   * 2,4,6,7,9,10,11,13,16,21,22,26,30,33
+   * Digtal pins: 2,4,6,7,9,10,11,13,16,21,22,26,30,33
+   * Touch Sense pins: 0,1,15,16,17,18,19,22,23,25,32,33
+   * Compare pins: 11,12
    *****************************/
   config.pinMode(21, INPUT_PULLUP, RISING);//pin, mode, type
   config.pinMode(22, INPUT_PULLUP, RISING);//pin, mode, type


moved from Console to Serial output in Yun Process example

--- hardware/arduino/avr/libraries/Bridge/examples/Process/Process.ino
+++ hardware/arduino/avr/libraries/Bridge/examples/Process/Process.ino
@@ -7,22 +7,21 @@
  created 5 Jun 2013
  by Cristian Maglie

+ This example code is in the public domain.
+
  */

 #include <Process.h>

 void setup() {
-  // Setup Bridge (needed every time we communicate with the Arduino Yún)
+  // Initialize Bridge
   Bridge.begin();

-  // Setup Console
-  Console.begin();
-  // Buffering improves Console performance, but we must remember to
-  // finish sending using the Console.flush() command.
-  Console.buffer(64);
+  // Initialize Serial
+  Serial.begin(9600);

-  // Wait until a Network Monitor is connected.
-  while (!Console);
+  // Wait until a Serial Monitor is connected.
+  while (!Serial);

   // run various example processes
   runCurl();
@@ -34,37 +33,38 @@
 }

 void runCurl() {
-  // Launch "curl" command and get Arduino asciilogo from the network
-
-  Process p;                 // Create a process and call it "p"
-  p.begin("curl");           // Process should launch the "curl" command
+  // Launch "curl" command and get Arduino ascii art logo from the network
+  // curl is command line program for transferring data using different internet protocols
+  Process p;		// Create a process and call it "p"
+  p.begin("curl");	// Process that launch the "curl" command
   p.addParameter("http://arduino.cc/asciilogo.txt"); // Add the URL parameter to "curl"
-  p.run();                   // Run the process and wait for its termination
+  p.run();		// Run the process and wait for its termination

-  // Print arduino logo over the console.
+  // Print arduino logo over the Serial
   // A process output can be read with the stream methods
   while (p.available()>0) {
     char c = p.read();
-    Console.print(c);
+    Serial.print(c);
   }
-  // Ensure the latest bit of data is sent.
-  Console.flush();
+  // Ensure the last bit of data is sent.
+  Serial.flush();
 }

 void runCpuInfo() {
   // Launch "cat /proc/cpuinfo" command (shows info on Atheros CPU)
-  Process p;
-  p.begin("cat");
-  p.addParameter("/proc/cpuinfo");
-  p.run();
+  // cat is a command line utility that shows the content of a file
+  Process p;		// Create a process and call it "p"
+  p.begin("cat");	// Process that launch the "cat" command
+  p.addParameter("/proc/cpuinfo"); // Add the cpuifo file path as parameter to cut
+  p.run();		// Run the process and wait for its termination

-  // Print command output on the Console.
+  // Print command output on the Serial.
   // A process output can be read with the stream methods
   while (p.available()>0) {
     char c = p.read();
-    Console.print(c);
+    Serial.print(c);
   }
-  // Ensure the latest bit of data is sent.
-  Console.flush();
+  // Ensure the last bit of data is sent.
+  Serial.flush();
 }


Delete K_Nearest_Boxes_Weight_Color_Length.ino

--- K_Nearest_Boxes_Weight_Color_Length.ino
+++ K_Nearest_Boxes_Weight_Color_Length.ino
@@ -1,303 +0,0 @@
-//Distance Sensor   UPDATE
-//Feature is width
-//Pre-known object of different widths
-//Pattern is see what the object is closest to.
-
-// This file has the most up-to-date code of all the files
-
-#include <Arduino.h>
-#include <NewPing.h>
-#include <HX711.h>
-#include <Wire.h>
-#include "Adafruit_TCS34725.h"
-
-#include <math.h>
-
-#include "Object.h"
-
-// IR Breakbeam (Width)
-#define IR_SENSOR_PIN_1 4
-#define IR_SENSOR_PIN_2 5
-#define IR_SENSOR_PIN_3 6
-
-// Weight Sensor
-#define DOUT 3
-#define CLK 2
-
-int test = 0;
-
-const int DISTANCE_SENSOR_MAX_DISTANCE = 50;
-
-// HX711 Weight Sensor
-// Use HX711_Calibration sketch to define
-const float calibration_factor = 0;
-
-// K Nearest Neighbors
-// May want to declare locally and pass as parameter
-const int K = 3;
-
-byte gammatable[256];
-Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
-
-const size_t NUM_OF_KNOWN_OBJECTS = 9;
-const size_t NUM_OF_OBJECT_TYPES = 3;
-String Known_Object_Types[3] = {"Small", "Medium", "Large"};
-
-// Needed for standardizing values
-const int WIDTH_MAX = 3;
-const int WIDTH_MIN = 1;
-const int WEIGHT_MAX = 6;
-const int WEIGHT_MIN = 0;
-const int RGB_MAX = 256;
-const int RGB_MIN = 0;
-
-HX711 scale(DOUT, CLK);
-
-// Takes the features from the current object and converts them to strings and integers
-// **
-void ObjectFeatureExtraction(Object &currObject) {
-  //Object currObject;
-  int currDistance;
-  // clear_val is needed b/c the getRawData() requries 4 values
-  uint16_t red, green, blue, clear_val;
-  uint32_t sum;
-  float r, g, b;
-  bool IR_Sensor1;
-  bool IR_Sensor2;
-  bool IR_Sensor3;
-
-  // Get width feature (in cm)
-  IR_Sensor1 = digitalRead(IR_SENSOR_PIN_1);
-  IR_Sensor2 = digitalRead(IR_SENSOR_PIN_2);
-  IR_Sensor3 = digitalRead(IR_SENSOR_PIN_3);
-
-  // currObject.width {1, 2, 3} {Short, Medium, Long Box}
-  // LOW means beam is broken
-  // Once IR_Sensor3 is broken, then IR_Sensor1 and IR_Sensor2 are tested to see if they are broken
-  // If S3 is the only sensor broken then the box is short, if S2 is also broken then it is meaium,
-    // is S1 is also broken then it is long
-  // {Start} S1 S2 S3 {End}
-  if(IR_Sensor3 == LOW) {
-    if(IR_Sensor1 == LOW && IR_Sensor2 == LOW) {
-      currObject.width = 3;
-    }
-    //If one beam is broken
-    else if(IR_Sensor1 == HIGH && IR_Sensor2 == LOW) {
-      currObject.width = 2;
-    }
-    //If neither beam is broken
-    else if(IR_Sensor1 == HIGH && IR_Sensor2 == HIGH) {
-      //box_size = "None";
-      currObject.width = 1;
-    }
-  }
-
-  // Get weight feature (in lbs) to the nearest 100ths place
-  currObject.weight = roundf(scale.get_units() * 100.0) / 100.0;
-
-  // RGB VALUES
-  // turn on LED
-  tcs.setInterrupt(false);
-  // takes 60ms to read
-  delay(60);
-  tcs.getRawData(&red, &green, &blue, &clear_val);
-  //turn off LED
-  tcs.setInterrupt(true);
-  sum = clear_val;
-  r = red/sum;
-  g = green/sum;
-  b = blue/sum;
-  r *= 256;
-  g *= 256;
-  b *= 256;
-  currObject.red = (int)r;
-  currObject.green = (int)g;
-  currObject.blue = (int)b;
-
-  //return currObject;
-}
-
-//  Computes the euclidean distance between the known and the current object's rgb values
-float ComputeDistanceofColors(Object currObject, Object knownObject) {
-  float red = currObject.red - knownObject.red;
-  float green = currObject.green - knownObject.green;
-  float blue = currObject.blue - knownObject.blue;
-  float dist = pow(red, 2) + pow(green, 2) + pow(blue, 2);
-  dist = roundf(dist* 100.0) / 100.0;
-  return dist;
-}
-
-//  Computes the euclidean distance between the known and the current object's features
-float ComputeDistanceofObjects(Object currObject, Object knownObject) {
-  float width = ((currObject.width - knownObject.width) - WIDTH_MIN) / (WIDTH_MAX - WIDTH_MIN);
-  float weight =  ((currObject.weight - knownObject.weight) - WEIGHT_MIN) / (WEIGHT_MAX - WEIGHT_MIN);;
-  float colorDistance = ComputeDistanceofColors(currObject, knownObject);
-  float dist = pow(width, 2) + pow(weight, 2) + pow(colorDistance, 2);
-  dist = sqrt(dist);
-  // Nearest 100ths place
-  dist = roundf(dist * 100.0) / 100.0;
-
-  return dist;
-}
-
-// Finds the patterns from the current object and compares them to patterns from the given objects
-// **
-String ObjectPatternRecognition(Object currObject, Object knownObjects[], size_t NUM_OF_KNOWN_OBJECTS) {
-
-  // Maintains the differences of the currObject and the knownObjects
-  Object kNearestObjects[K];
-
-  // For testing purposes
-  for(int i = 0; i < NUM_OF_KNOWN_OBJECTS; ++i) {
-    Serial.println(ComputeDistanceofObjects(currObject, knownObjects[i]));
-  }
-
-  // The first K Object differences are added to the kNearestObjects array
-  for(int i = 0; i < K; ++i) {
-    kNearestObjects[i].width = abs(knownObjects[i].width - currObject.width);
-    kNearestObjects[i].weight = abs(knownObjects[i].weight - currObject.weight);
-    kNearestObjects[i].red = abs(knownObjects[i].red - currObject.red);
-    kNearestObjects[i].green = abs(knownObjects[i].green - currObject.green);
-    kNearestObjects[i].blue = abs(knownObjects[i].blue - currObject.blue);
-    kNearestObjects[i].type = knownObjects[i].type;
-  }
-
-  // Now, determine if each remaining object is among the K closest, and if so insert into array (thus dropping one obj)
-  for(int i = K; i < NUM_OF_KNOWN_OBJECTS; ++i) { // For each remaining known object
-
-    // Find the current max difference (CHANGE TO DISTANCE, EVERYWHERE) in the K nearest objects
-    float max_diff_of_K_nearest = 0;
-    int max_index = 0;
-    float temp_dist = 0;
-
-    for(int j = 0; j < K; ++j) {
-
-        // kNearest Objects is the difference between the currObject and the knownObjects
-        // ComputeDistanceofObjects should compute the total distance for kNearestObjects[j]
-        // May just add this to the above
-      temp_dist = ComputeDistanceofObjects(currObject, kNearestObjects[j]);
-
-      if(temp_dist > max_diff_of_K_nearest) { // Update max
-        max_diff_of_K_nearest = temp_dist;
-        max_index = j;
-      }
-    }
-
-    // If the current known object's difference < the max difference in the current K nearest neighbors
-    temp_dist = ComputeDistanceofObjects(currObject, knownObjects[i]);
-
-    if(temp_dist < max_diff_of_K_nearest) {
-      // Replace the existing neighbor having max_diff_of_K_nearest, by the current known object, in the K nearest neighbors array
-
-      kNearestObjects[max_index].type = knownObjects[i].type;
-      kNearestObjects[max_index].width = abs(knownObjects[i].width - currObject.width);
-      kNearestObjects[max_index].weight = abs(knownObjects[i].weight - currObject.weight);
-      kNearestObjects[max_index].red = abs(knownObjects[i].red - currObject.red);
-      kNearestObjects[max_index].green = abs(knownObjects[i].green - currObject.green);
-      kNearestObjects[max_index].blue = abs(knownObjects[i].blue - currObject.blue);
-      max_diff_of_K_nearest = temp_dist;
-    }
-  }
-
-  // For testing purposes
-  /*
-  for(int i = 0; i < K; ++i) {
-    Serial.println(kNearestObjects[i].type);
-    Serial.println(ComputeDistanceofObjects(currObject, kNearestObjects[i]));
-  }
-  */
-
-  int count = 0;
-  int max_count = 0;
-  String most_frequent_type;
-  // Find out which object type occurs most frequently
-  for(int i = 0; i < NUM_OF_OBJECT_TYPES; ++i) {
-    count = 0;
-    for(int j = 0; j < K; ++j) {
-      if(kNearestObjects[j].type == Known_Object_Types[i]) {
-        count++;
-      }
-    }
-    if(count > max_count) {
-      max_count = count;
-      most_frequent_type = Known_Object_Types[i];
-    }
-  }
-
-  return most_frequent_type;
-}
-
-// Prints the type of object that is being passed through the project
-// **
-void Actuation(String object) {
-  if(object != "") {
-    Serial.print("\t");
-    Serial.println(object);
-  }
-}
-
-void setup() {
-  // Weight sensor, found with calibration sketch
-  scale.set_scale(calibration_factor);
-  //Resets scale to 0
-  scale.tare();
-  pinMode(IR_SENSOR_PIN_1, INPUT);
-  digitalWrite(IR_SENSOR_PIN_1, HIGH);
-  pinMode(IR_SENSOR_PIN_2, INPUT);
-  digitalWrite(IR_SENSOR_PIN_2, HIGH);
-  pinMode(IR_SENSOR_PIN_3, INPUT);
-  digitalWrite(IR_SENSOR_PIN_3, HIGH);
-
-  Serial.begin(9600);
-}
-
-void loop() {
-  // Turns both LEDs off before each reading
-
-  // Should put feature extraction and pattern recognition in one multi-second for loop to
-    //give the box time to go through the sensors.
-
-  // {Type, width (cm.), weight (lbs.)}
-  // Small is red, Medium is green, Large is blue
-  const size_t NUM_OF_KNOWN_OBJECTS = 9;
-  Object knownObjects[NUM_OF_KNOWN_OBJECTS] = { {"Small", 1, 1.2, 230, 54, 27},
-                                                {"Small", 1, 0.8, 205, 43, 18},
-                                                {"Small", 1, 1.6, 253, 40, 7},
-                                                {"Medium", 2, 2.5, 5, 253, 7},
-                                                {"Medium", 2, 3.2, 16, 196, 16},
-                                                {"Medium", 2, 4.1, 45, 246, 45},
-                                                {"Large", 3, 4.6, 30, 18, 191},
-                                                {"Large", 3, 4.2, 66, 53, 235},
-                                                {"Large", 3, 5.3, 17, 9, 134}};
-
-  /*
-  const size_t NUM_OF_TEST_OBJECTS = 9;
-
-  Object testObjects[NUM_OF_KNOWN_OBJECTS] = {  {"", 11, 1.2, 230, 54, 27},
-                                                {"", 15, 0.8, 205, 43, 18},
-                                                {"", 12, 1.6, 253, 40, 7},
-                                                {"", 27, 2.5, 5, 253, 7},
-                                                {"", 29, 3.2, 16, 196, 16},
-                                                {"", 30, 4.1, 45, 246, 45},
-                                                {"", 40, 4.6, 30, 18, 191},
-                                                {"", 42, 4.2, 66, 53, 235},
-                                                {"", 42, 5.3, 17, 9, 134}};
-  */
-
-
-  Object currObject;
-  String closestObjectType;
-
-  // Once 3rd IR breakbeam is broken go through the process
-  bool IR_Sensor3 = digitalRead(IR_SENSOR_PIN_2);
-  if(IR_Sensor3 == LOW) {
-    Object currObject;
-    ObjectFeatureExtraction(currObject);
-
-    closestObjectType = ObjectPatternRecognition(currObject, knownObjects, NUM_OF_KNOWN_OBJECTS);
-
-    Actuation(closestObjectType);
-
-    delay(1000);
-  }
-}


Minor modification to CarWifiServer.ino

Minor modification to CarWifiServer.ino

--- CarWifiServer/CarWifiServer.ino
+++ CarWifiServer/CarWifiServer.ino
@@ -14,8 +14,8 @@
 	straight = STRAIGHT;
 	left = LEFT;
 	right = RIGHT;
-  // angle = straight;
-  // speed = M;
+	// angle = straight;
+	// speed = M;

 	expire = 500;
 	ignored_cnt = 0;


added pressure sensor data collect; changed name of persistence functions to include "P"

--- ardesp/waterelf/waterelf.ino
+++ ardesp/waterelf/waterelf.ino
@@ -325,10 +325,10 @@
 // config utils /////////////////////////////////////////////////////////////
 boolean getCloudShare();
 void setCloudShare(boolean b);
-String getSvrAddr();
-void setSvrAddr(String s);
-String getAnalogSensor();
-void setAnalogSensor(String s);
+String getSvrAddrP();
+void setSvrAddrP(String s);
+String getAnalogSensorP();
+void setAnalogSensorP(String s);

 /////////////////////////////////////////////////////////////////////////////
 // setup ////////////////////////////////////////////////////////////////////
@@ -340,8 +340,8 @@

   // read persistent config
   SPIFFS.begin();
-  svrAddr = getSvrAddr();
-  analogSensor = getAnalogSensor();
+  svrAddr = getSvrAddrP();
+  analogSensor = getAnalogSensorP();

   // start the sensors, the DNS and webserver, etc.
   startPeripherals();
@@ -585,6 +585,8 @@
   toSend += "
\n";
   toSend += "\n
Data sharing server address: "; toSend += svrAddr;
   toSend += "
\n";
+  toSend += "\n
Got analog sensor: "; toSend += GOT_ANALOG_SENSOR;
+  toSend += "
\n";
   toSend += "\n
Analog sensor type: "; toSend += analogSensor;
   toSend += "
\n";

@@ -690,7 +692,7 @@
   }

   // persist the config
-  setSvrAddr(svrAddr);
+  setSvrAddrP(svrAddr);
   setCloudShare(cloudShare);

   // TODO some way of verifying if server config worked
@@ -723,7 +725,7 @@
       toSend += "
...for ";
       toSend += analogSensor;
       toSend += "
";
-      setAnalogSensor(analogSensor);
+      setAnalogSensorP(analogSensor);
     }
   }

@@ -1023,12 +1025,23 @@
   return;
 }
 void getAnalog(float* a) {
+  dbg(analogDBG, "getAnalog: ");
+
   if(! GOT_ANALOG_SENSOR) {
     (*a) = 0.0;
   } else if(analogSensor == "analog_mains") {
     (*a) = 1.0;
   } else if(analogSensor == "analog_pressure") {
-    (*a) = -1.0;
+    int analogValue = analogRead(A0);
+
+    // conversion/"calibration" because sensor 4.5v=1.2MPa
+    (*a) = (analogValue - 25) * .19;
+
+    dbg(analogDBG, "Value: ");
+    dbg(analogDBG, analogValue);
+    dbg(analogDBG, "    Pressure: ");
+    dbg(analogDBG, (*a));
+    dbg(analogDBG, " PSI\n");
   }

   return;
@@ -1054,7 +1067,7 @@
     SPIFFS.remove("/cloudShare.txt");
   }
 }
-String getSvrAddr() {
+String getSvrAddrP() {
   String s = "";
   File f = SPIFFS.open("/svrAddr.txt", "r");
   if(f) {
@@ -1064,24 +1077,25 @@
   }
   return s;
 }
-void setSvrAddr(String s) {
+void setSvrAddrP(String s) {
   File f = SPIFFS.open("/svrAddr.txt", "w");
   f.println(s);
   f.close();
 }
-String getAnalogSensor() {
+String getAnalogSensorP() {
   analogSensor = ANALOG_SENSOR_NONE; // the default is...
   GOT_ANALOG_SENSOR = false;         // ...no sensor
   String s = "";
   File f = SPIFFS.open("/analogSensor.txt", "r");
   if(f) {
+    GOT_ANALOG_SENSOR = true;
     s = f.readString();
     s.trim();
     f.close();
   }
   return s;
 }
-void setAnalogSensor(String s) {
+void setAnalogSensorP(String s) {
   File f = SPIFFS.open("/analogSensor.txt", "w");
   f.println(s);
   f.close();


activityLED added to sensRH

activityLED added to sensRH

--- sensRH/src/sketch.ino
+++ sensRH/src/sketch.ino
@@ -7,6 +7,7 @@
 #include <DHT.h>

 #define DHTPIN 4     // what pin we're connected to
+#define activityLED 3

 // Uncomment whatever type you're using!
 //#define DHTTYPE DHT11   // DHT 11


Fixed a minor sound bug.

Fixed a minor sound bug.

Stepping on magenta lights was not making any sound.

--- DDR_Neo_Pixel_Strip_Display/DDR_Neo_Pixel_Strip_Display.ino
+++ DDR_Neo_Pixel_Strip_Display/DDR_Neo_Pixel_Strip_Display.ino
@@ -83,6 +83,7 @@

 // game state variables
 int whichSong = 0;
+int score = 0;
 bool gameOver;
 // -----------------------------------------------------------------------------
 // End Game Objects, State Variables, and Timers
@@ -152,7 +153,7 @@
   playDDR();
 }

-// allow the player to choose a song to play
+se// allow the player to choose a song to play
 void mainMenu()
 {
   displayOptions();
@@ -248,6 +249,7 @@
 void setupDDR()
 {
   gameOver = false;
+  score = 0;
   initCapacitiveSensor();

   pinMode(PIEZO, OUTPUT);
@@ -408,6 +410,7 @@
          break;
        case 5:   // 1 0 1 (magenta)
          if (danceMoveArray[i]->isSteppedOn(MAGENTA))
+          playNextNote();
          break;
        default:  // 0 0 0
          break;


print reading

print reading

--- eMotion/flap/flap.ino
+++ eMotion/flap/flap.ino
@@ -69,6 +69,9 @@
 int light()
 {
   int num = sonsor_reading(1);
+  Serial.print('Light: ');
+  Serial.println(num);
+  Serial.flush();
   return 100000 / num;
 }

@@ -78,6 +81,9 @@
 int IR()
 {
   int num = irRead(irSensorPin, irLED);
+  Serial.print('IR: ');
+  Serial.println(num);
+  Serial.flush();
   return num;
 }


Removed Kalman filter

Removed Kalman filter

--- gps_arduino/gps_arduino.ino
+++ gps_arduino/gps_arduino.ino
@@ -14,7 +14,7 @@
 #include <LSM303.h>
 #include <SabertoothSimplified.h>
 #include <EasyTransfer.h>
-#include <Kalman.h>
+//#include <Kalman.h>

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

@@ -120,7 +120,7 @@
 byte mCurrentWayPoint = 0;

 //Kalman filter for smoothing compass value
-Kalman compassFilter(0.125,32,1023,0); //suggested initial values for high noise filtering
+//Kalman compassFilter(0.125,32,1023,0); //suggested initial values for high noise filtering

 //Method definitions
 void gpsdump(TinyGPS &gps);


added Enable/Disable konservative hastigheder og andet

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -1,4 +1,5 @@
 #include <AccelStepper.h>
+#include <TimerOne.h>

 //(type, step pin, direction pin)
 AccelStepper stepperX(AccelStepper::DRIVER, 5, 4);
@@ -8,70 +9,70 @@

 int timer1_counter;

+boolean enabled = false;
 boolean homeing = false;

 void setup()
 {
   Serial.begin(57600);
   Serial.setTimeout(25);
-  stepperX.setMaxSpeed(1000);
-  stepperX.setAcceleration(300);
+  stepperX.setMaxSpeed(2000);
+  stepperX.setAcceleration(5000);

-  stepperY.setMaxSpeed(750);
-  stepperY.setAcceleration(100);
+  stepperY.setMaxSpeed(2000);
+  stepperY.setAcceleration(5000);

-  // initialize timer1
-  noInterrupts();           // disable all interrupts
-  TCCR1A = 0;
-  TCCR1B = 0;
+  Timer1.initialize(50); // microseconds
+  Timer1.attachInterrupt( timerIsr ); // attach the service routine here
+  pinMode(2, INPUT_PULLUP);
+  attachInterrupt(0, setY, FALLING);
+  pinMode(6, OUTPUT);
+  pinMode(9, OUTPUT);

-  // Set timer1_counter to the correct value for our interrupt interval
-  timer1_counter = 64886;   // preload timer 65536-16MHz/8/100Hz
-  //timer1_counter = 64286;   // preload timer 65536-16MHz/256/50Hz
-  //timer1_counter = 34286;   // preload timer 65536-16MHz/256/2Hz

-  TCNT1 = timer1_counter;   // preload timer
-  //TCCR1B |= (1 << CS11) | (1 << CS10);    // 64 prescaler
-  TCCR1B |= (1 << CS11);    // 8 prescaler
-  TIMSK1 |= (1 << TOIE1);   // enable timer overflow interrupt
-  interrupts();             // enable all interrupts
-  pinMode(2, INPUT_PULLUP);
-  digitalWrite(6, HIGH);
-  digitalWrite(9, HIGH);
 }
-ISR(TIMER1_OVF_vect)        // interrupt service routine
+void timerIsr()
 {
-  TCNT1 = timer1_counter;   // preload timer
+  stepperY.run();
   stepperX.run();
-  stepperY.run();
+}
+void setY() {
+  stepperX.stop();
+  stepperX.setCurrentPosition(0);
+  homeing = false;
 }
 void loop()
 {

-  if (!homeing) {
-    handleInput();
-  }
+  handleInput();
+
   update();

   if (homeing) {
+    enable();
     if (digitalRead(2)) {
-
-      stepperX.move(-10);
-
-    } else {
-      stepperX.stop();
-      stepperX.setCurrentPosition(0);
-      homeing = false;
-
+
+      stepperX.move(-10000);
+
     }
   }

 }

+void enable() {
+  enabled = true;
+  digitalWrite(6, HIGH);
+  digitalWrite(9, HIGH);
+}
+void disable() {
+  enabled = false;
+  digitalWrite(6, LOW);
+  digitalWrite(9, LOW);

+}
 void update() {

   //this should be every second or so
@@ -91,7 +92,9 @@
     Serial.print(stepperY.distanceToGo());
     Serial.print(" ");
     Serial.print((homeing ? 'y' : 'n'));
-    Serial.print("\r\n");
+    Serial.print(" ");
+    Serial.print((enabled ? 'y' : 'n'));
+    Serial.print("\r");

     nextUpdate = millis() + 250;
   }
@@ -109,7 +112,7 @@
       stepperY.move(jogY);
     }

-    if (command == 'g') {
+    if (command == 'g') {
       long absoluteX = Serial.parseInt();
       long absoluteY = Serial.parseInt();
       stepperX.moveTo(absoluteX);
@@ -123,7 +126,7 @@
       if (motor == 'Y') {

         stepperY.setMaxSpeed(speed);
-      }
+      }
       if (motor == 'X') {

         stepperX.setMaxSpeed(speed);
@@ -148,7 +151,11 @@
     if (command == 'h') {
       homeing = true;
     }
-
+    if (command == 'E') {
+      enable();
+    }
+    if (command == 'e') {
+      disable();
+    }
   }
 }
-


change subscribe to QOS0

change subscribe to QOS0

subscribe QOS1 crashes if recv msg too frequently

--- src/neurite.ino
+++ src/neurite.ino
@@ -1027,9 +1027,9 @@
 			}

 			nd->mqtt_connected = true;
-			mqtt_cli.subscribe(nd->cfg.topic_from);
-			log_info("subscribe: %s\n\r", nd->cfg.topic_from);
-			mqtt_cli.subscribe(nd->topic_private, 1);
+			//mqtt_cli.subscribe(nd->cfg.topic_from);
+			//log_info("subscribe: %s\n\r", nd->cfg.topic_from);
+			mqtt_cli.subscribe(nd->topic_private);
 			log_info("subscribe: %s\n\r", nd->topic_private);
 			char payload_buf[32];
 			dbg_assert(payload_buf);


comments

comments

--- resilient-network.ino
+++ resilient-network.ino
@@ -1,9 +1,9 @@
 // resilient network
-#include <SoftwareSerialWithHalfDuplex.h>
+#include <SoftwareSerialWithHalfDuplex.h> // which one?
 #include "Arduino.h"
 #include "timers.h"

-#define isSource false
+#define isSource false // ToDo: control through jumper

 #define leds1pin 11
 #define leds2pin 3
@@ -13,7 +13,7 @@

 int RX[3] = {A0, A2, A4};
 int TX[3] = {A1, A3, A5};
-int coil[3] = {6, 5, 10};
+int coil[3] = {6, 5, 10}; // magnets
 int distanceToSource[3];
 int shortestDistanceToSource;
 int lampState;


Increase pulseIn timeout period.

Increase pulseIn timeout period.

Increase pulseIn timeouts to fix issues with unexpected timeout during remote control signal reading.  Issue appears to only happen with latest 1.6.5 IDE and perhaps specific platforms like Mac OSX.

--- Techno_Tiki_With_Remote_Control/Techno_Tiki_With_Remote_Control.ino
+++ Techno_Tiki_With_Remote_Control/Techno_Tiki_With_Remote_Control.ino
@@ -169,9 +169,9 @@
   // Read the first pulse with a large timeout since it's 9ms long, then
   // read subsequent pulses with a shorter 2ms timeout.
   uint32_t durations[33];
-  durations[0] = pulseIn(IR_PIN, HIGH, 10000);
+  durations[0] = pulseIn(IR_PIN, HIGH, 20000);
   for (uint8_t i = 1; i < 33; ++i) {
-    durations[i] = pulseIn(IR_PIN, HIGH, 2000);
+    durations[i] = pulseIn(IR_PIN, HIGH, 5000);
   }
   // Reset any state changed by the interrupt.
   receiverFell = false;


--- projects/JeeNode_micro/JNu_TNode_VCC_DS18B20_lowPower/JNu_TNode_VCC_DS18B20_lowPower.ino
+++ projects/JeeNode_micro/JNu_TNode_VCC_DS18B20_lowPower/JNu_TNode_VCC_DS18B20_lowPower.ino
@@ -13,6 +13,9 @@
 // adapted 130816 matt hodge
 // adapted 141217 to JeeNode v3 peter widmayer
 // extended 150110 to 2 x DS18B20
+//
+// 150524 Measurement interval extended from every 5 s to every 60 s
+//   - 3 x NiMH @ 5s > 1..2 weeks, then down at 3.7 V
 //--------------------------------------------------------------------------------------

 #include <JeeLib.h> // https://github.com/jcw/jeelib
@@ -24,7 +27,7 @@
 #define ONE_WIRE_BUS 8  // JNu DIO2
 #define tempPower 10    // JNu DIO1: power pin

-#define MEASUREMENT_INTERVAL 5000 // valid range 16-65000 ms -> JeeLabs power save duration between measurements
+#define MEASUREMENT_INTERVAL 60000 // valid range 16-65000 ms -> JeeLabs power save duration between measurements

 // Setup a oneWire instance to communicate with any OneWire devices
 // (not just Maxim/Dallas temperature ICs)


commented up

commented up

--- telemetryBox.ino
+++ telemetryBox.ino
@@ -124,8 +124,10 @@
 }

 void measureUS() {
-    // the pulseIn from the sensor needs to be read often, otherwise it gets backed up with old measurements
-    // perhaps using the analog signal would be better
+	// The pulseIn from the sensor needs to be read often, otherwise I think it can get backed up with old measurements.
+	// Perhaps using the analog signal would be better.
+	// Need to take an average of many measurements because sometimes
+	// there are outliers.
     waterHeightSum = 0;
     for (int i = 0; i < 100; i++) {
         duration = pulseIn(A0, HIGH);


fix moving average

fix moving average

--- tinkering/hallsensor/hall_test.ino
+++ tinkering/hallsensor/hall_test.ino
@@ -1,9 +1,11 @@
+#define RPMSIZE 5
 #define HALLPIN P1_5

 int revs;
 unsigned long oldtime;
 unsigned int average;
-int rpm[5];
+int rpm[RPMSIZE];
+int rpmidx;
 int hallRead;
 int switched;

@@ -21,17 +23,25 @@
     revs = 0;
     oldtime = 0;
     average = 0;
+
+    for (rpmidx = RPMSIZE - 1; rpmidx >= 0; rpmidx--)
+        rpm[rpmidx] = 0;
 }

 void loop()
 {
     hallRead = digitalRead(HALLPIN);

-    //Using moving average to calculate RPM, I don't think it is totally correct
     if(millis() - oldtime > 1000)
     {
-        average -= average / 5;
-        average += (revs*30) / 5;
+        rpm[rpmidx] = revs;
+
+        rpmidx = (rpmidx + 1) % RPMSIZE;
+
+        average = 0;
+        for (int idx = 0; idx < RPMSIZE; idx++)
+            average += rpm[idx];
+        average /= RPMSIZE;

         oldtime = millis();
         revs = 0;


Added ESP32-WebServer at Github.

Added ESP32-WebServer at Github.

--- aquacontrol32.ino
+++ aquacontrol32.ino
@@ -8,11 +8,7 @@
 //#include "time.h"
 #include <Preferences.h>
 #include "SSD1306.h"              //https://github.com/squix78/esp8266-oled-ssd1306
-#include <ESP32WebServer.h>       //http://www.fisch.lu/junk/ESP32-WebServer.zip
-                                  // or
-                                  //https://github.com/fesch/arduino-esp32/tree/master/libraries/WebServer
-                                  // or
-                                  //http://wasietsmet.nl/ESP32-WebServer.zip
+#include <ESP32WebServer.h>       //https://github.com/CelliesProjects/ESP32-WebServer

 #define COUNTRY_CODE_ISO_3166 "nl"  //https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2


Increased GPIO drive strength.

Increased GPIO drive strength.

--- aquacontrol32.ino
+++ aquacontrol32.ino
@@ -224,6 +224,12 @@
   pinMode( I2C_SCL_PIN, INPUT_PULLUP );
   pinMode( I2C_SDA_PIN, INPUT_PULLUP );

+  gpio_set_drive_capability( (gpio_num_t)LED0_PIN, GPIO_DRIVE_CAP_3 );
+  gpio_set_drive_capability( (gpio_num_t)LED1_PIN, GPIO_DRIVE_CAP_3 );
+  gpio_set_drive_capability( (gpio_num_t)LED2_PIN, GPIO_DRIVE_CAP_3 );
+  gpio_set_drive_capability( (gpio_num_t)LED3_PIN, GPIO_DRIVE_CAP_3 );
+  gpio_set_drive_capability( (gpio_num_t)LED4_PIN, GPIO_DRIVE_CAP_3 );
+
   preferences.begin( "aquacontrol32", false );

   btStop();


Added sensor timed requests

Added sensor timed requests

--- arduinofences.ino
+++ arduinofences.ino
@@ -4,6 +4,7 @@

 int RECV_PIN = 5;
 int BUTTON_PIN = 6;
+int ANALOG_LIGHT_PIN = 1;

 IRrecv irrecv(RECV_PIN);
 IRsend irsend;
@@ -61,6 +62,7 @@
     pinMode(ledPin1, OUTPUT);
     pinMode(RECV_PIN, INPUT);
     pinMode(BUTTON_PIN, INPUT);
+    pinMode(ANALOG_LIGHT_PIN, INPUT);

     //WiFi.init();
     WiServer.init(sendPage);
@@ -149,6 +151,7 @@
 unsigned long codeValue; // The code value if not raw
 int codeLen; // The length of the code
 int toggle = 0; // The RC5/6 toggle state
+unsigned long sentLockMillis = 0;

 int lastButtonState;

@@ -225,9 +228,24 @@
   }
 }

+void sendCodeOnce() {
+  unsigned long time = millis();
+
+  if ( (time - sentLockMillis) > 10000) { //10 seconds
+    Serial.println("Sending once");
+    sendCode();
+    sentLockMillis = time;
+  }
+}
+
 void loop()
 {
   int buttonState = digitalRead(BUTTON_PIN);
+  int lightValue = analogRead(ANALOG_LIGHT_PIN);
+
+  if (lightValue < 200) {
+    sendCodeOnce();
+  }

   if (buttonState == HIGH) {
     if (irrecv.decode(&results)) {


Use PROGMEM where it makes sense to do so.

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -1,4 +1,5 @@
 #include <stdint.h>
+#include <avr/pgmspace.h>

 #include "Config.h"

@@ -122,9 +123,7 @@

 void writeRssiData() {
-    static const char* prefix = "r ";
-
-    Serial.print(prefix);
+    Serial.print(F("r "));

     for (uint8_t i = 0; i < RECEIVER_COUNT; i++) {
         if (EepromSettings.rawMode)
@@ -141,34 +140,28 @@

 #ifdef TEMP_MONITORING_ENABLED
 void writeTempMonitorData() {
-    static const char* prefix = "t ";
-
-    Serial.print(prefix);
-    Serial.print(tempMonitor.value);
+    Serial.print(F("t "));
+    Serial.print(tempMonitor.value, DEC);
     Serial.println();
 }
 #endif

 #ifdef VOLTAGE_MONITORING_ENABLED
 void writeVoltMonitorData() {
-    static const char* prefix = "v ";
-
-    Serial.print(prefix);
-    Serial.print(voltMonitor.value);
+    Serial.print(F("v "));
+    Serial.print(voltMonitor.value, DEC);
     Serial.println();
 }
 #endif

 void parseCommands() {
     if (Serial.available() > 0) {
-        char command = Serial.read();
+        const char command = Serial.read();

         switch (command) {
             // Status
             case '?': {
-                static const char* prefix = "? ";
-
-                Serial.print(prefix);
+                Serial.print(F("? "));
                 Serial.print(RECEIVER_COUNT, DEC);
                 Serial.print(serialSeperator);

@@ -231,7 +224,7 @@
         }

         Serial.find('\n');
-        Serial.println("ok");
+        Serial.println(F("ok"));
     }
 }


firmware: set correct size

firmware: set correct size

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -117,8 +117,8 @@
 }

 /******** mapping xy position to steps ******/
-#define WIDTH 380
-#define HEIGHT 310
+#define WIDTH 310
+#define HEIGHT 380
 #define STEPS_PER_MM 87.58 // the same as 3d printer
 void prepareMove()
 {


Show Git commit hash in User-Agent header

--- client_arduino/arduino_client.ino
+++ client_arduino/arduino_client.ino
@@ -5,6 +5,8 @@
 #include <WiFiClientSecure.h>

 #include PRIKMETER_CONFIG_INCLUDE
+#include "buildinfo.h"
+
 #include "telegram_reader.h"

 #define SERIAL_RX_PIN D5
@@ -17,10 +19,8 @@
 #define SERVER_PORT 443
 #endif
 #ifndef USER_AGENT
-#define USER_AGENT "prikmeter" // TODO Add Git hash from buildinfo.h.
-#endif
-
-#define VERSION "1.0.0"
+#define USER_AGENT "prikmeter"
+#endif

 #ifdef READ_FROM_SERIAL
 #  define P1_INPUT Serial // Debugging aid.
@@ -132,7 +132,9 @@
   httpsClient.print(
       "POST /telegrams HTTP/1.1\r\n"
       "Host: " SERVER_HOST "\r\n"
-      "User-Agent: " USER_AGENT " " VERSION "\r\n"
+      "User-Agent: " USER_AGENT " ");
+  httpsClient.print(_BuildInfo.src_version);
+  httpsClient.print("\r\n"
       "Content-Type: text/plain\r\n"
       "Content-Length: ");
   httpsClient.print(size);


removing AzureIoTHubClient class

removing AzureIoTHubClient class

--- command_center/command_center.ino
+++ command_center/command_center.ino
@@ -40,23 +40,6 @@
 static const char ssid[] = "[Your WiFi network SSID or name]";
 static const char pass[] = "[Your WiFi network WPA password or WEP key]";
 static const char* connectionString = "[Device Connection String]";
-
-// Choose the sslClient for Adafruit WINC1500.
-Adafruit_WINC1500SSLClient sslClient;
-
-
-/*
- * The new version of AzureIoTHub library changed the AzureIoTHubClient signature.
- * As a temporary solution, we will test the definition of AzureIoTHubVersion, which is only defined
- *    in the new AzureIoTHub library version. Once we totally deprecate the last version, we can take
- *    the #ifdef out.
- */
-#ifdef AzureIoTHubVersion
-static AzureIoTHubClient iotHubClient;
-#else
-AzureIoTHubClient iotHubClient(sslClient);
-#endif
-

 // The connection string is the one which begins with HostName=... and contains the DeviceId
 // and SharedAccessKey for this particular Thing on the Internet.


Cut down on sound effects

Cut down on sound effects

--- frontdesk/frontdesk.ino
+++ frontdesk/frontdesk.ino
@@ -128,7 +128,6 @@
 		}

 		Serial.write(END_CHAR);
-		state = 0;
 	}

 	if (characterRead[0] == COMMAND_RESET_TIME) {
@@ -140,7 +139,6 @@

 		Serial.write(done);
 		Serial.write(END_CHAR);
-		state = 0;
 	}

 	if (characterRead[0] == COMMAND_REGISTER) {


Added red and green gradients as status

Added red and green gradients as status

--- frontdesk/frontdesk.ino
+++ frontdesk/frontdesk.ino
@@ -40,9 +40,9 @@

 		// LEDs stay off
 		digitalWrite(ledPin, LOW);
-		redBeat(8, 64);
+		// redBeat(8, 64);
 		// rainbow();
-		// rainbowCycle();
+		 rainbowCycle();

 		// If a tag is detected, go to the next state
 		if (isValidResponse) {
@@ -60,7 +60,8 @@
 			scannedID = (int)getTime(readData, numUserBytes, userOffset);

 			// LEDs on
-			colorWipe(LED.Color(0, 0, 127));
+      green();
+			// colorWipe(LED.Color(0, 0, 127));
 			digitalWrite(ledPin, HIGH);
 			playCoinSound();

@@ -74,7 +75,9 @@
 		}
 		// If data read fails, go back to scan state
 		else {
-			playDeath();
+      red();
+      //colorWipe(LED.Color(127, 0, 0));
+			playDeath();
 			state = 0;
 		}
 	}
@@ -213,6 +216,22 @@
 	LED.show();
 }

+void green() {
+  LED.setPixelColor(0, LED.Color(23, 9, 68));
+  LED.setPixelColor(1, LED.Color(58, 33, 127));
+  LED.setPixelColor(2, LED.Color(46, 17, 127));
+  LED.setPixelColor(3, LED.Color(41, 26, 84));
+  LED.show();
+}
+
+void red() {
+  LED.setPixelColor(0, LED.Color(68, 0, 5));
+  LED.setPixelColor(1, LED.Color(127, 16, 25));
+  LED.setPixelColor(2, LED.Color(127, 0, 0));
+  LED.setPixelColor(3, LED.Color(84, 20, 15));
+  LED.show();
+}
+
 void colorWipe(uint32_t c) {
 	for (int i = 0; i < LED.numPixels(); i++) {
 		LED.setPixelColor(i, c);
@@ -230,7 +249,7 @@
 }

 void rainbowCycle() {
-	j >= 384 ? j = 0 : j += 25;
+	j >= 384 ? j = 0 : j += 7;

     for (int i = 0; i < LED.numPixels(); i++) {
 		// tricky math! we use each pixel as a fraction of the full 384-color wheel


Setup tweaks.

Setup tweaks.

Avoid the 1 sec delay if the FONA begin()'s properly (it always does) and add an initial outgoing SMS because we seem to need it.

--- gsm_tracker/gsm_tracker.ino
+++ gsm_tracker/gsm_tracker.ino
@@ -72,8 +72,9 @@

   // Start the FONA
   Serial.print(F("Initializing FONA..."));
-  while (! fona.begin(4800)) {
-    Serial.print(F(" waiting..."));
+  while (1) {
+    boolean fonaStarted = fona.begin(4800);
+    if (fonaStarted) break;
     delay (1000);
   }
   Serial.println(F(" done."));
@@ -85,6 +86,8 @@
     if (network_status == 1 || network_status == 5) break;
     delay(250);
   }
+  // Sometimes the FONA can't recieve SMSs until it sends one first.
+  fonaSendStatusSMS(MY_PHONE_NUMBER);
   Serial.println(F(" done."));

   // Attach the RI interrupt
@@ -239,16 +242,7 @@
         if (strcmp(sms_buffer, "Location") == 0) {
           Serial.print(F("  Responding with location..."));

-          char sms_response[52];
-
-          if (current_location.isValid) {
-            sprintf (sms_response, "https://maps.google.com?q=%s,%s", current_location.latitude_c, current_location.longitude_c);
-          } else {
-            sprintf (sms_response, "I'm lost!");
-          }
-
-          // reply...
-          if (fona.sendSMS(MY_PHONE_NUMBER, sms_response)) {
+          if (fonaSendLocationSMS(MY_PHONE_NUMBER)) {
             Serial.println(F(" sent."));
           } else {
             Serial.println(F(" failed!"));
@@ -259,15 +253,7 @@
         } else if (strcmp(sms_buffer, "Status") == 0) {
           Serial.print(F("  Responding with status..."));

-          char sms_response[16];
-          uint16_t vbat;
-          fona.getBattVoltage(&vbat);
-
-          uint8_t rssi = fona.getRSSI();
-          sprintf (sms_response, "%d bars,\n%d mV", barsFromRSSI(rssi), vbat);
-
-          // reply...
-          if (fona.sendSMS(MY_PHONE_NUMBER, sms_response)) {
+          if (fonaSendStatusSMS(MY_PHONE_NUMBER)) {
             Serial.println(F(" sent."));
           } else {
             Serial.println(F(" failed!"));
@@ -284,6 +270,31 @@
     gpsSerial.listen();
     ringing = false;
   }
+}
+
+
+boolean fonaSendLocationSMS (char *recipient) {
+  char sms_response[52];
+
+  if (current_location.isValid) {
+    sprintf (sms_response, "https://maps.google.com?q=%s,%s", current_location.latitude_c, current_location.longitude_c);
+  } else {
+    sprintf (sms_response, "I'm lost!");
+  }
+
+  return fona.sendSMS(recipient, sms_response);
+}
+
+
+boolean fonaSendStatusSMS (char *recipient) {
+  uint8_t rssi = fona.getRSSI();
+  uint16_t vbat;
+  fona.getBattVoltage(&vbat);
+
+  char sms_response[16];
+  sprintf (sms_response, "%d bars, %d mV", barsFromRSSI(rssi), vbat);
+
+  return fona.sendSMS(recipient, sms_response);
 }


Fix Bugs

Fix Bugs

Turn the lights off at 1 AM.
When the alarm is active, the LCD backlight will increase with the alarm lights.

--- Sketch.ino
+++ Sketch.ino
@@ -113,6 +113,10 @@
 			if (minute == 0)
 			{
 				CheckDayOrNight();
+				if (hour == 1)
+				{
+					LightOff();
+				}
 			}
 		}

@@ -434,6 +438,10 @@
 	if (backlightManuallyTurnedOff)
 	{
 		analogWrite(backlightLCD, 0);
+	}
+	else if (alarmActive)
+	{
+		analogWrite(backlightLCD, brightness);
 	}
 	else
 	{


Added support for 4 weights.

Added support for 4 weights.

--- Weight.ino
+++ Weight.ino
@@ -32,12 +32,17 @@
 #define DEFAULT_WEIGHT_PRINT_TIME 5000
 #define DEFAULT_EMPTY_VALUE 8237827
 #define BAUD_RATE 9600
+#define KILO 1000
+#define TAP_SIZE 330
+#define KEG_WEIGHT 4000

 // Not in use. May be used in the future.
 int EEPROM_ADDR = 0;

 // initialize the library with the numbers of the interface pins
-LiquidCrystal lcd(13, 12, 8, 9, 10, 11);
+LiquidCrystal lcd(13, 12, 8, 9, 10, 11); //PROD
+//LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //DEBUG
+
 HX711 scales[WEIGHT_SENSORS] = {HX711 (A1, A2)};

 unsigned long last = 0;
@@ -46,12 +51,15 @@
 void setup() {
   Serial.begin(BAUD_RATE);
   lcd.begin(16, 2);
-  lcd.print("Vekt:");
-
-  scales[0].set_scale(2280.f);
-  scales[0].tare();
-  delay(DELAY);
-  scales[0].set_offset(DEFAULT_EMPTY_VALUE);
+  lcd.print("Starting....");
+
+  for (int i = 0; i < WEIGHT_SENSORS; i++) {
+    scales[i].set_scale(2280.f);
+    scales[i].tare();
+    delay(DELAY);
+    scales[i].set_offset(DEFAULT_EMPTY_VALUE);
+  }
+  lcd.clear();
 }

@@ -59,25 +67,58 @@
   unsigned long now = millis();

   if ((last + DEFAULT_WEIGHT_TIME) < now) {
-    scales[0].power_up();
-    lcd.setCursor(0, 1);
-    float value = scales[0].get_units(10) * -10;
-    if (value > -10 && value < 10)  {
-      value = 0;
+    for (int i = 0; i < WEIGHT_SENSORS; i++) {
+      String weightName = String("V");
+      weightName = weightName + (i + 1) + ":";
+      scales[i].power_up();
+      lcd.setCursor(0, 1);
+      float value = scales[i].get_units(10) * -10;
+      if (value > -10 && value < 10)  {
+        value = 0;
+      }
+
+      if ((lastPrint + DEFAULT_WEIGHT_PRINT_TIME) < now) {
+         Serial.print(weightName);
+         Serial.println(value, 1);
+         lastPrint = now;
+      }
+      int row = i % 2;
+      int col = 0;
+      if (i > 1) {
+        col = 9;
+      }
+      lcd.setCursor(col, row);
+      char weight[8];
+      String kilo = "kg";
+      if (value > KILO * 10 || (KILO * -10) < value) {
+         if (WEIGHT_SENSORS > 2) {
+          dtostrf((value / KILO), 1, 1, weight);
+        } else {
+          dtostrf((value / KILO), 1, 3, weight);
+        }
+      } else {
+        if (WEIGHT_SENSORS > 2) {
+          dtostrf((value / KILO), 1, 0, weight);
+        } else {
+          dtostrf((value / KILO), 1, 2, weight);
+        }
+      }
+      if (WEIGHT_SENSORS > 2) {
+        lcd.print(weight + kilo);
+      } else {
+        lcd.print(weightName + weight + kilo);
+      }
+      if (WEIGHT_SENSORS == 1 && value > 0) {
+        lcd.setCursor(0, 1);
+        String beers = String("Beers:");
+        char numberOfBeers[4];
+        dtostrf(((value - KEG_WEIGHT) / TAP_SIZE), 1, 0, numberOfBeers);
+        lcd.print(beers + numberOfBeers);
+      }
+      delay(50);
+      scales[i].power_down();	// put the ADC in sleep mode
+      last = millis();
     }
-
-    if ((lastPrint + DEFAULT_WEIGHT_PRINT_TIME) < now) {
-       Serial.print("V1:");
-       Serial.println(value, 1);
-       lastPrint = now;
-    }
-    char weight[8];
-    String grams = " g      ";
-    dtostrf(value, 1, 1, weight);
-    lcd.print(weight +  grams);
-    delay(50);
-    scales[0].power_down();	// put the ADC in sleep mode
-    last = millis();
   }
 }


Put button lights on pins, sleep/wake them up too

--- pingpong/pingpong.ino
+++ pingpong/pingpong.ino
@@ -1,11 +1,13 @@
 #define P1PIN           8
+#define P1LIGHTPIN     12
 #define P2PIN           9
+#define P2LIGHTPIN     13
 #define SPEAKERPIN      6
 #define LONGPRESS_TIME 25
 #define LATCH 4
 #define CLK   3
 #define DATA  2
-#define INACTIVEMILLIS 600000 // 10 minutes
+#define INACTIVEMILLIS 1200000 // 20 minutes

 // Seven Segment Display Handling
 byte DigitBytes[10]= {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x67};
@@ -133,6 +135,7 @@
 boolean p1Win = false;
 boolean p2Win = false;
 boolean blinkToggle = true;
+boolean sleeping = false;

 Button p1Button(P1PIN);
 Button p2Button(P2PIN);
@@ -144,6 +147,12 @@
   pinMode(CLK, OUTPUT);
   pinMode(DATA, OUTPUT);

+  pinMode(P1LIGHTPIN, OUTPUT);
+  pinMode(P2LIGHTPIN, OUTPUT);
+
+  digitalWrite(P1LIGHTPIN, HIGH);
+  digitalWrite(P2LIGHTPIN, HIGH);
+
   showScore();

   p1Button.init();
@@ -157,10 +166,10 @@
 {
   int p1Event, p2Event;

-  Serial.println(millis() - lastActivityTime);
-
   if ((millis() - lastActivityTime) > INACTIVEMILLIS) {
-    shutDownLights();
+    goToSleep();
+  } else {
+    wakeup();
   }

   if (gameOver) {
@@ -180,6 +189,9 @@
   p1Event = p1Button.handle();
   if (!gameOver && p1Event == BUTTON_SHORT) {
     lastActivityTime = millis();
+    if (sleeping)
+      return;
+
     p1Score++;
     numServes++;
     showScore();
@@ -188,6 +200,9 @@

   if (gameOver && p1Event == BUTTON_LONG) {
     lastActivityTime = millis();
+    if (sleeping)
+      return;
+
     resetGame();
     currentServe = 0;
     numServes = 0;
@@ -197,6 +212,9 @@
   p2Event = p2Button.handle();
   if (!gameOver && p2Event == BUTTON_SHORT) {
     lastActivityTime = millis();
+    if (sleeping)
+      return;
+
     p2Score++;
     numServes++;
     showScore();
@@ -205,6 +223,9 @@

   if (gameOver && p2Event == BUTTON_LONG) {
     lastActivityTime = millis();
+    if (sleeping)
+      return;
+
     resetGame();
     currentServe = 1;
     numServes = 0;
@@ -246,13 +267,33 @@
   }
 }

-void shutDownLights()
-{
+void goToSleep()
+{
+  sleeping = true;
+
+  // Blank p1 score
   digitalWrite(LATCH, LOW);
   shiftOut(DATA, CLK, MSBFIRST, 0x00);
   shiftOut(DATA, CLK, MSBFIRST, 0x00);
   digitalWrite(LATCH, HIGH);
-}
+
+  // Blank p2 score
+
+  // Turn off button lights
+  digitalWrite(P1LIGHTPIN, LOW);
+  digitalWrite(P2LIGHTPIN, LOW);
+}
+
+ void wakeup()
+ {
+   sleeping = false;
+
+   showScore();
+
+   digitalWrite(P1LIGHTPIN, HIGH);
+   digitalWrite(P2LIGHTPIN, HIGH);
+ }
+

 void checkForWinner()
 {


EMG basic movement Xbee 2.0

EMG basic movement Xbee 2.0

--- XBee_rob_function_2.0/xBee_2.0/xBee_2.0.ino
+++ XBee_rob_function_2.0/xBee_2.0/xBee_2.0.ino
@@ -1,5 +1,17 @@
 #include <Dynamixel_Serial.h>
 #include <readxBee.h>
+#include <SoftwareSerial.h>
+
+#define SERVO_ControlPin 0x02       // Control pin of buffer chip, NOTE: this does not matter becasue we are not using a half to full contorl buffer.
+#define SERVO_SET_Baudrate 57600    // Baud rate speed which the Dynamixel will be set too (57600)
+#define LED13 0x0D
+#define CW_LIMIT_ANGLE 0x001        // lowest clockwise angle is 1, as when set to 0 it set servo to wheel mode
+#define CCW_LIMIT_ANGLE 0xFFF       // Highest anit-clockwise angle is 0XFFF, as when set to 0 it set servo to wheel mode
+#define OPEN 'o'
+#define CLOSE 'c'
+
+SoftwareSerial mySerial(10, 11);    // RX, TX
+

 int x, y, z, emg1, emg2;
 int infoPk[24];
@@ -29,11 +41,45 @@
 void setup() {
   Serial.begin(115200);
   Serial1.begin(115200);
+
+  Serial.flush();                                       // Clear the serial buffer of garbage data before running the code.
+  mySerial.begin(SERVO_SET_Baudrate);                   // We now need to set Ardiuno to the new Baudrate speed 115200
+  //Serial.begin(SERVO_SET_Baudrate);                     // Start serial communication on baudrate 57600
+  Dynamixel.begin(mySerial);                            // Calling mySerial function which sets 10 pin as the 2nd RX serial pin, and sets pin 11 as the 2nd TX serial pin
+  Dynamixel.setDirectionPin(SERVO_ControlPin);
+
+  //Turn on hold for the servos, so they stay in place
+  Dynamixel.setHoldingTorque(0x01, true);               //Set on hold turque for each servo
+  Dynamixel.setHoldingTorque(0x02, true);
+  Dynamixel.setHoldingTorque(0x03, true);
+  Dynamixel.setHoldingTorque(0x04, true);
+  Dynamixel.setHoldingTorque(0x05, true);
+
+  //Set profile acceleration
+  Dynamixel.setProfileAcceleration(0x01, 10);           //Set profile acc for each servo
+  Dynamixel.setProfileAcceleration(0x02, 10);
+  Dynamixel.setProfileAcceleration(0x03, 10);
+  Dynamixel.setProfileAcceleration(0x04, 300);
+  Dynamixel.setProfileAcceleration(0x05, 300);
+
+  //Set profile velocity
+  Dynamixel.setProfileVelocity(0x01, 100);              //Set profile vel for each servo
+  Dynamixel.setProfileVelocity(0x02, 100);
+  Dynamixel.setProfileVelocity(0x03, 100);
+  Dynamixel.setProfileVelocity(0x04, 200);
+  Dynamixel.setProfileVelocity(0x05, 200);
 }

 void loop() {
   actualName();
-}
+  if (Serial1.read(emg1) < 70) {
+    Dynamixel.performMovement(2148, 2048, 2048, CLOSE);   //"Initial" position
+    delay(1500);
+  }else{
+    Dynamixel.performMovement(2148, 1850, 3250, OPEN);     //Ready position
+    delay(2000);
+  }
+ }


implemented getmovement();

implemented getmovement();

--- master/master.ino
+++ master/master.ino
@@ -1178,40 +1178,11 @@
 		checkBallInZone();
 		/* end ball in zone */

+		getPlayMode();
+
 		/*movement control*/
-
-		targetVelocity = NORMAL_SPEED;
-
-		orbit_k = 1;
-
-		if (tsopStrength > 148){
-			orbit_k = 1.0;
-		}
-		else if (tsopStrength > 140){
-			orbit_k = 0.9;
-		}
-		else if (tsopStrength > 135){
-			orbit_k = 0.8;
-		}
-		else if (tsopStrength > 130){
-			orbit_k = 0.7;
-		}
-		else if (tsopStrength > 120){
-			orbit_k = 0.6;
-		}
-		else if (tsopStrength > 100){
-			orbit_k = 0.55;
-		}
-		else if (tsopStrength > 70){
-			orbit_k = 0.5;
-		}
-		else{
-			targetVelocity = 0;
-		}
-
-		targetDir_r_field = (270 - abs(tsopAngle_r_targetBearing * orbit_k)) / 90 * tsopAngle_r_targetBearing * orbit_k;
-
-		TOBEARING180(targetDir_r_field);
+		getMovement(playMode);
+
 		targetDir = targetDir_r_field - bearing_int;
 		TOBEARING180(targetDir);


Smaller debounce delay is fine enough

Smaller debounce delay is fine enough

--- current-test-program/servo_via_timer.ino
+++ current-test-program/servo_via_timer.ino
@@ -14,21 +14,18 @@
 void setup() {
   hp1_button.attach(2, INPUT_PULLUP);
   hp2_button.attach(3, INPUT_PULLUP);
-  hp1_button.interval(200);
-  hp2_button.interval(200);
+  hp1_button.interval(20);
+  hp2_button.interval(20);

   upper_arm.init();
   lower_arm.init();
-  // delay(INITIAL_DELAY_MS);
-  //upper_arm.move_to_min();  // reverse...
-  //lower_arm.move_to_min();
-
 }

 void loop() {
   hp1_button.update();
   hp2_button.update();
+
   if (hp1_button.rose() ) {
     upper_arm.move_to_min();
     lower_arm.move_to_min();


One more comment/debug sync.

One more comment/debug sync.

--- gps-transmitter/gps_transmitter_fio/gps_transmitter_fio.ino
+++ gps-transmitter/gps_transmitter_fio/gps_transmitter_fio.ino
@@ -77,6 +77,8 @@
       return;
     }

+    //Serial.print(GPS.lastNMEA());
+
     // status bit 0 is fix status
     if (GPS.fix) {
       RXLED0;


Update Keypad.ino

Update Keypad.ino

--- ComboKeypad/Keypad.ino
+++ ComboKeypad/Keypad.ino
@@ -113,53 +113,4 @@

 //////////////////////////////////////////////////////

-//Function pressButton, If user presses a Button
-void pressButton(int num, int digRead){
-  if (digRead == 1 && doonce != true) { // If I hit a Button
-   time = millis();   //Starts the 10 second timer
-    input[count] = num + 1; // sends the number 1 into the array at the "count number"
-     count++; // Where to put 4 into the array
-      doonce = true;
-    }
-    int exists;
-
-      for(int a = 0; a < numOfButtons; a++){
-        if(buttonsRead[a] == 0){
-          exists++;
-        }
-      }
-
-      //////////////////////////////////////////////////////////////////////
-      /// So it doesnt go ON and OFF infinitly, Basically a stopper  ///
-      /// If no button is pressed reset the doonce                       ///
-      //////////////////////////////////////////////////////////////////////
-      if (exists == numOfButtons && doonce == true){
-          doonce = false;
-           delay(50);
-        }
-}/*----(Function pressButton END)----*/
-
-/*----(Function Reset)----*/
-void reset() {
-  for (int inputIndex = 0; inputIndex < numOfCombos; inputIndex++) {
-    input[inputIndex] = 0;   //Zeros the input array
-  }
-
-    time = millis();
-     digitalWrite(rightLight, 0);   //Turns the "Green" light off
-      digitalWrite(wrongLight, 0);   //Turns the "Red" light off
-       count = 0;  //Sets the counter to 0
-
-}/*----(Function Reset END)----*/
-
-/*----(Function Debug, Prints the count, and what has been pressed)----*/
-void debug(){
-  Serial.print("Count = ");
-   Serial.print(count);
-    Serial.print(", |");
-
-     for(int a = 0; a < numOfCombos; a++){
-      Serial.print(input[a]);   //Prints which number has been pressed
-    }
-  Serial.println();
-}/*----(Function Debug END)----*/
+/*(—


Slightly better testing

Slightly better testing

--- TJCTM24024-SPI/graphics_test/graphics_test.ino
+++ TJCTM24024-SPI/graphics_test/graphics_test.ino
@@ -34,10 +34,7 @@
   Serial.begin(115200);
   Serial.println("ILI9341 Test!");

-  // set the TFT reset to HIGH
-//  pinMode(TFT_RESET, OUTPUT);
-//  digitalWrite(TFT_RESET, LOW);
-
+  // get the display ready
   tft.begin();

   // read diagnostics (optional but can help debug problems)
@@ -69,7 +66,7 @@
 unsigned long testFillScreen()
 {
   unsigned long start = micros();
-
+
   tft.fillScreen(ILI9341_BLACK);
   yield();
   tft.fillScreen(ILI9341_RED);
@@ -77,6 +74,12 @@
   tft.fillScreen(ILI9341_GREEN);
   yield();
   tft.fillScreen(ILI9341_BLUE);
+  yield();
+  tft.fillScreen(ILI9341_YELLOW);
+  yield();
+  tft.fillScreen(ILI9341_WHITE);
+  yield();
+  tft.fillScreen(0xFD20);
   yield();
   tft.fillScreen(ILI9341_BLACK);
   yield();


Fixed the bug.

Fixed the bug.

--- monitor_client/monitor_client.ino
+++ monitor_client/monitor_client.ino
@@ -83,13 +83,13 @@
         starttime = millis();

-    //snprintf(http_cmd,sizeof(http_cmd),"GET monitor.ourjnu.com/submit.php?device_index=13726247339&longitude=113.540718&latitude=22.256467&temperature=%03d&humidity=%03d&particulate_matter=25 HTTP/1.0\r\n\r\n",DHT11.temperature,DHT11.humidity);
-    //sprintf(http_cmd,"GET /submit.php?device_index=13726247339&longitude=113.540718&latitude=22.256467&temperature=%03d&humidity=%03d&particulate_matter=25 HTTP/1.0\r\n\r\n",DHT11.temperature,DHT11.humidity);
+    //snprintf(http_cmd,sizeof(http_cmd),"GET monitor.ourjnu.com/submit.php?device_index=13726247339&longitude=113.540718&latitude=22.256467&temperature=%03d&humidity=%03d&particulate_matter=25 HTTP/1.0  \r\n\r\n",DHT11.temperature,DHT11.humidity);
+    //sprintf(http_cmd,"GET /submit.php?device_index=13726247339&longitude=113.540718&latitude=22.256467&temperature=%03d&humidity=%03d&particulate_matter=25 HTTP/1.0  \r\n\r\n",DHT11.temperature,DHT11.humidity);
     //Serial.println(http_cmd);
     if(!is_debug){
         //Use rewrited url to prevent memory overflow
-        char target_url[66];
-        snprintf(target_url, sizeof(target_url), "GET /13726247339-113.540718-22.256467-%03d-%03d-%07.2f HTTP/1.0\r\n\r\n",DHT11.temperature, DHT11.humidity, ratio);
+        char target_url[68];
+        snprintf(target_url, sizeof(target_url), "GET /13726247339-113.540718-22.256467-%03d-%03d-%07.2f HTTP/1.0  \r\n\r\n",DHT11.temperature, DHT11.humidity, ratio);
         Serial.println(target_url);

         if(false == gprs.connect(TCP,"monitor.ourjnu.com", 80)) {
@@ -141,4 +141,4 @@
     }
     Serial.println(gprs.read());
     */
-}
+}


cleanup

cleanup

--- sensornode/sensornode_rf24.ino
+++ sensornode/sensornode_rf24.ino
@@ -66,27 +66,21 @@
 {
    measure();

-   int d = random(5000, 15000);
+   int d = random(10000, 20000);
    Serial << "waiting " << d << "ms\n\n";
    delay(d); // randomize delay to ensure we don't get stuck in an enless streak of collisions
 }

 void measure() {
   Serial << "measuring temperature: ";
-
   int temp = round(dht.readTemperature()*100.0);
   Serial << temp << "C" << endl;
+
   Serial << "measuring humidity: ";
-  digitalWrite(3, HIGH);
   int hum = round(dht.readHumidity()*100.0);
   Serial << hum << "%" << endl;

-  digitalWrite(3, HIGH);
   sendPacket(temp, hum);
-
-  digitalWrite(3, LOW);
-  delay(1000);
-
 }

 void sendPacket(int temp, int hum) {
@@ -97,7 +91,10 @@
   packet[3] = (int16_t) temp;
   packet[4] = (int16_t) hum;

-  radio.write(&packet, PACKET_SIZE);
+  digitalWrite(3, HIGH);
+  radio.write(&packet, PACKET_SIZE);
+  digitalWrite(3, LOW);
+
   packet_count++;
 }


bits in data array now reversed during filling so it's easier to calc data later

--- reciever/reciever.ino
+++ reciever/reciever.ino
@@ -33,7 +33,7 @@
 // A0-A3,B2-B3  - UUID which is randomly set once sensor is turned on
 //                and it not changed until next power off
 //
-// B0-B1  - Number of the sensor: 01 - 1, 10 - 2, 11 - 3
+// B0-B1  - Number of channel of the sensor: 01 - 1, 10 - 2, 11 - 3
 //
 // C0 - battery info: 0 - battery is ok, 1 - battery is low
 //
@@ -49,13 +49,18 @@
 //          1110|1011 = 59% because 101001 (inverted all bits and add 1) = 41, and 100 - 41 = 59
 //
 // I0-I3 - 4 check sum which is calculated as a sum of less significant bits
-//            of check sum of the tetrads T1-T8 written backwards.
+//            of check sum of the nibbles T1-T8 written backwards.
 //            for example let's look at the example message:
 //            1011|1100|0100|0000|1111|0000|0010|1111|0010
-//            sum of the tetrad T1-T8 where each bit written backwards = 110100,
+//            sum of the nibbles T1-T8 where each bit written backwards = 110100,
 //            lets take last 4 bits and wrote them backward:
-//            0010 which is equal to T9 tetrad
-
+//            0010 which is equal to T9 nibble
+
+// data array is used to store the whole message
+// We will write all nibbles in data array in reversed order
+// so it will be easier to calculate temperature, check sum etc. later
+// for example this message: 1011|1100|0100|0000|1111|0000|0010|1111|0010
+// will be stored as 1101|0011|0010|0000|1111|0000|0100|1111|0100
 volatile byte data[DATA_ARRAY_SIZE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};

 void setup() {
@@ -100,7 +105,7 @@
                 //This was the last value bit

                 //All is done we can return the whole message to the client
-                if (checkSumMatch()) {
+                if (isCheckSumMatch()) {
                     printDataArray();
                 }

@@ -135,15 +140,14 @@
 void printDataArray() {
     Serial.println("==== Sensor data captured ===");

-    byte sensorNumber = data[1] >> 2;
-    byte powerOnUUID = (data[0] << 2) | (data[1] & 3);
-    byte powerState = data[2] >> 3;
+    byte sensorChannel = getSensorChannel();
+    byte powerOnUUID = getPowerUUID();
+    byte powerState = getPowerStatus();
     float temperature = (float)getTemperature() / 10;
     byte humidity = getHumidity();
-    boolean checkSumMatches = checkSumMatch();
-
-    Serial.print("No: ");
-    Serial.println(sensorNumber);
+
+    Serial.print("Channel: ");
+    Serial.println(sensorChannel);

     Serial.print("Power UUID: ");
     Serial.println(powerOnUUID);
@@ -158,31 +162,55 @@
     Serial.println(humidity);
 }

-boolean checkSumMatch() {
-
-    //Sum first 8 tetrads
+int isCheckSumMatch() {
+
+    //Sum first 8 nibbles
     int sum = 0;
     for (byte i = 0; i < DATA_ARRAY_SIZE - 1; i++) {
-        sum += getLastFourBitsReversed(data[i]);
-    }
+        sum += data[i];
+    }
+
+    //clear higher bits
+    sum &= 15;

     //returns true if calculated check sum matches received
-    return getLastFourBitsReversed(sum) == data[DATA_ARRAY_SIZE - 1];
+    return sum == data[DATA_ARRAY_SIZE - 1];
+}
+
+byte getSensorChannel() {
+    //Channel is bits B0, B1 in T2 nibble
+    //Since we store T2 in reversed order
+    //we have to get 3,4 bits ot data[1] and reverse them
+    return ((data[1] & 1) << 1) | ((data[1] & 2) >> 1);
+}
+
+byte getPowerUUID() {
+    //we do not reverse power uuid since value is still uniq
+    return (data[0] << 2) | ((data[1] & 12) >> 2);
+}
+
+byte getPowerStatus() {
+    //Power or battery status is C0 bit in T3 nibble
+    //since in data array we wrote T3 in reversed order
+    //it will be the first bit in data[2]
+    return data[2] & 1;
 }

 int getTemperature() {
     int temperature = 0;

-    temperature = (((int)getLastFourBitsReversed(data[5]) << 8)
-                   | ((int)getLastFourBitsReversed(data[4]) << 4)
-                   | (int)getLastFourBitsReversed(data[3]));
+    //Temperature is stored in T4,T5,T6 nibbles
+    //lowest nibble - first
+    //since we already reversed bits order in these nibbles
+    //all we have to do is to reverse nibbles order
+    temperature = (((int)data[5] << 8) | ((int)data[4] << 4) | (int)data[3]);

     if ((data[5] & 1) == 1) {
         //negative number, use two's compliment conversion
         temperature = ~temperature + 1;

-        //clear higher bits
-        temperature = temperature & 4095;
+        //clear higher bits and convert to negative
+        temperature = -1 * (temperature & 4095);
     }

     return temperature;
@@ -190,38 +218,31 @@

 int getHumidity() {

+    //Humidity is stored in nibbles T7,T8
+    //since bits in these nibbles are already in reversed order
+    //we just have to get number by reversing nibbles orderßßß
+    int humidity = ((int)data[7] << 4) | (int)data[6];
+
     //negative number, use two's compliment conversion
-    int humidity = ((int)(getLastFourBitsReversed(data[7]) << 4)
-            | (int)getLastFourBitsReversed(data[6]));
-
     humidity = ~humidity + 1;

+    //humidity is stored as 100 - humidity
     return 100 - humidity;
 }

 void fillDataArray(byte bitNumber, boolean isOne) {
     byte dataArrayIndex = bitNumber / BITS_PER_PACKET;
-    boolean isFirstBitInTetrad = bitNumber % 4 == 0;
-
-    if (isFirstBitInTetrad) {
-        //clear tetrad since it could be filled with random data
+    byte bitInNibble = bitNumber % 4;
+
+    if (bitInNibble == 0) {
+        // if it's the first bit in nibble -
+        // clear nibble since it could be filled with random data at this time
         data[dataArrayIndex] = 0;
     }

-    data[dataArrayIndex] = (data[dataArrayIndex] << 1) | isOne;
-}
-
-//reverse last 4 bits and return
-//so 0101 -> 1010, 1100 -> 0011
-byte getLastFourBitsReversed(int b) {
-    byte inverted = 0;
-
-    inverted = inverted | ((b & 1) << 3); //(byte & 0001) << 3 so could be 1000
-    inverted = inverted | (b & 2) << 1; //(byte & 0010) << 1 so could be 0100
-    inverted = inverted | (b & 4) >> 1; // (byte & 0100) >> 1 so could be 0010
-    inverted = inverted | (b & 8) >> 3; // (byte & 1000) >> 3 so could be 0001
-
-    return inverted;
+    //Write all nibbles in reversed order
+    //so it will be easier to do calculations later
+    data[dataArrayIndex] |= (isOne << bitInNibble);
 }

 // Matcher for divider bit
@@ -253,3 +274,4 @@
 void setState(byte st, boolean condition) {
     state = condition ? st : 0;
 }
+


Update FixBrickedUID.ino

Update FixBrickedUID.ino

Added new pin layout info; standardizing format and info

--- examples/FixBrickedUID/FixBrickedUID.ino
+++ examples/FixBrickedUID/FixBrickedUID.ino
@@ -23,15 +23,17 @@
  http://mac86project.altervista.org/

  ----------------------------------------------------------------------------- Nicola Coppola
- * Pin layout should be as follows:
- * Signal     Pin              Pin               Pin
- *            Arduino Uno      Arduino Mega      MFRC522 board
- * ------------------------------------------------------------
- * Reset      9                5                 RST
- * SPI SS     10               53                SDA
- * SPI MOSI   11               51                MOSI
- * SPI MISO   12               50                MISO
- * SPI SCK    13               52                SCK
+ * Typical pin layout used:
+ * -----------------------------------------------------------------------------------------
+ *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
+ *             Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
+ * Signal      Pin          Pin           Pin       Pin        Pin              Pin
+ * -----------------------------------------------------------------------------------------
+ * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
+ * SPI SS      SDA(SS)      10            53        D10        10               10
+ * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
+ * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
+ * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
  *
  * The reader can be found on eBay for around 5 dollars. Search for "mf-rc522" on ebay.com.
  */


Full TTL features

Full TTL features

--- ArdPythonSlave_TTLs/ArdPythonSlave_TTLs.ino
+++ ArdPythonSlave_TTLs/ArdPythonSlave_TTLs.ino
@@ -31,6 +31,7 @@
  Program constants
 **********************************/
 const long BAUD_RATE = 115200; // baud rate for serial communication. must match contro script
+const long MAX_TIME_UL = 4294967295UL;
 const long DETECT_TIME_THR  = 80; // in ms
 const long DETECT_REFRAC_THR = 4000; // twenty seconds before registering a second detection
 const bool Pump_ON = LOW; // LOW activates the pump
@@ -109,8 +110,7 @@
 bool Well_Active_State[nWells]; // state variable indicating active well
 bool Pump_State[nWells]; // Pump: on/off
 // TTL State Variables
-bool TTL_IR_Detect[nWells]; // TTL PULSE indicating that there was a detection.
-bool TTL_RD; // TTL PULSE indicating if a reward was delivered.
+bool TTL_IR_Detect_State[nWells]; // TTL PULSE indicating that there was a detection.

 /******************************************
         Time references
@@ -120,6 +120,7 @@
 unsigned long Well_IR_TimeRef[nWells];  // time reference: for IR detection
 unsigned long Well_IR_Timer[nWells];    // timer for how long IR has been on.
 unsigned long Well_IR_RefracTimeRef[nWells]; // timer for second detection
+unsigned long TTL_IR_Detect_Timer[nWells]; // timer

 unsigned long PumpTimeRef[nWells];      // time ref for pump on
 unsigned long PumpTimer[nWells];        // timer for how long pump has been on
@@ -141,18 +142,17 @@
     Well_Detect_State[well] = false;
     Well_LED_State[well] = false;
     Pump_State[well] = false;
-
-    Well_Active_TimeRef[well] = 15000UL;
-    Well_IR_TimeRef[well] = 15000UL;
-    PumpTimeRef[well] = 15000UL;
+    TTL_IR_Detect_State[well] = false;
+
+    Well_Active_TimeRef[well] = MAX_TIME_UL;
+    Well_IR_TimeRef[well] = MAX_TIME_UL;
+    PumpTimeRef[well] = MAX_TIME_UL;
     Well_IR_RefracTimeRef[well] = 0;
+    TTL_IR_Detect_Timer = 0;

     Well_Active_Timer[well] = 0;
     PumpTimer[well] = 0;
     Well_IR_Timer[well] = 0;
-
-    // TTLs
-    TTL_IR_Detect[well] = False;
   }

   // LEDs
@@ -192,7 +192,6 @@
   // Reward Delivered
   pinMode(TTL_RD_Pin, OUTPUT);
   digitalWrite(TTL_RD_Pin,LOW);
-  TTL_RD = false

   // Attach interrupts independently
   attachInterrupt(digitalPinToInterrupt(Well_IR_Pins[0]), IR_Detect1, CHANGE);
@@ -223,7 +222,9 @@
     }
     // Check serial input.
     ProcessInput();
-    // Process the wells.
+    /**************************************
+      Process the wells.
+    ***************************************/
     for (int well = 0; well < nWells; well++) {
       WellDetectThrCheck(well);
       // if well is active, check to deliver reward
@@ -241,9 +242,19 @@
           sendEventCode(RR, well + 1);
         }
       }
-    }
-
-    // Process the cue if not constant.
+      // TTL IRs Timer reset
+      if (TTL_IR_Detect_State[well] == true){
+        if ( (millis()-TTL_IR_Detect_Timer[well])>=TTL_PulseDur ){
+          TTL_IR_Detect_State = false;
+          TTL_IR_Detect_Timer = MAX_TIME_UL;
+          digitalWrite(TTL_IR_Pins[well],LOW);
+        }
+      }
+    } // well loop
+
+    /**************************************
+      Process the CUE
+    ***************************************/
     if (ActiveCUE_ID >= 1 & ActiveCUE_ID <= 4) {
       CUE_Timer = millis() - CUE_TimeRef;
       if (CUE_Timer > ActiveCUE_HalfCycle) {
@@ -267,8 +278,17 @@
     SerialState = false;
     reset_states();
     TurnCueOff();
-  }
-}
+  } //cue Processing
+} // end of Main loop()
+
+
+/**********************************************************
+***********************************************************
+***********************************************************
+                    Dependent Routines
+***********************************************************
+***********************************************************
+***********************************************************/

 /*************************************
   ISR routines for IR well detection
@@ -305,6 +325,10 @@
     Well_IR_State[well] = false;
     Well_Detect_State[well] = false;
     ResetDetectTimer(well);
+
+    TTL_IR_Detect_State[well] = false;
+    TTL_IR_Detect_Timer = MAX_TIME_UL;
+    digitalWrite(TTL_IR_Pins[well],LOW);
   }
 }

@@ -318,10 +342,14 @@
         // valid Detection
         if (Well_IR_Timer[well] >= DETECT_TIME_THR) {
           Well_Detect_State[well] = true;
-          // digitalWrite(RPGIO_IR_Detect[well], !digitalRead(RPGIO_IR_Detect[well]));
           ResetDetectTimer(well);
           Well_IR_RefracTimeRef[well] = millis();
           sendEventCode(DD, well + 1);
+
+          // send TTL for detection
+          TTL_IR_Detect_State[well] = true;
+          TTL_IR_Detect_Timer[well] = millis();
+          digitalWrite(TTL_IR_Pins[well],HIGH);
         }
       }
     }
@@ -330,7 +358,7 @@

 // Reset IR Timer
 void ResetDetectTimer(int well) {
-  Well_IR_TimeRef[well] = 15000UL;
+  Well_IR_TimeRef[well] = MAX_TIME_UL;
   Well_IR_Timer[well] = 0;
 }

@@ -521,9 +549,6 @@
   int well = SerialReadNum();
   if (well >= 0 && well <= 5) {
     TurnOnPump(well);
-//    Serial.print("<Pump Activated #");
-//    Serial.println(well + 1);
-//    Serial.print(">\n");
     return well;
   }
   else {
@@ -535,13 +560,12 @@

 void Deliver_Reward(int well) {
   TurnOnPump(well);
-//  Serial.println("<Delivering Reward");
-//  Serial.println(">");
 }

 void TurnOnPump(int well) {
   // set pump to on & set pump timer
   digitalWrite(Pumps_Pins[well], Pump_ON);
+  digitalWrite(TTL_RD_Pin,HIGH);
   Pump_State[well] = true;
   PumpTimeRef[well] = millis();
   PumpTimer[well] = 0;
@@ -550,8 +574,9 @@
 // turn off pump and reset pump timers
 void TurnOFFPump(int well) {
   digitalWrite(Pumps_Pins[well], Pump_OFF);
+  digitalWrite(TTL_RD_Pin,LOW);
   Pump_State[well] = false;
-  PumpTimeRef[well] = 15000UL;
+  PumpTimeRef[well] = MAX_TIME_UL;
   PumpTimer[well] = 0;
 }

@@ -664,6 +689,8 @@

   Well_IR_State[well] = false;
   Well_Detect_State[well] = false;
+  digitalWrite(TTL_IR_Pins[well],LOW);
+
   Well_IR_RefracTimeRef[well] = 0;
   ResetDetectTimer(well);

@@ -673,7 +700,7 @@

 void DeActivateWell(int well) {
   Well_Active_State[well] = false;
-  Well_Active_TimeRef[well] = 15000UL;
+  Well_Active_TimeRef[well] = MAX_TIME_UL;
   Well_Active_Timer[well] = 0;
   Well_LED_OFF(well);
   sendEventCode(DW, well + 1);
@@ -719,14 +746,6 @@
       Well_LED_OFF(well);
     }
   }
-}
-
-/**************************************
- * TTL Pulse Functions
- *
- **************************************/
-void sendTTLPulse(int pin){
-
 }

 /****************************************


Fixes delay of serial input when using parseInt (#7)

* [fix] Fixed delay between commands

* [minor] added comment

--- arduino/serial_protocol/serial_protocol.ino
+++ arduino/serial_protocol/serial_protocol.ino
@@ -5,64 +5,34 @@
 const int pin_right   = 6;

 // Initializing bit masks
-const int forward_mask = 8; // 1000
-const int reverse_mask = 4; // 0100
-const int left_mask    = 2; // 0010
-const int right_mask   = 1; // 0001
+const int forward_mask = 1 << 3; // 1000
+const int reverse_mask = 1 << 2; // 0100
+const int left_mask    = 1 << 1; // 0010
+const int right_mask   = 1 << 0; // 0001

-int protocol_num; // number of current state
-int forward_value = 0;
-int reverse_value = 0;
-int left_value = 0;
-int right_value = 0; // values that will be read from Serial after applying mask
-boolean commandComplete = false;
+int protocol_num = -1;

 void setup() {
-  pinMode(pin_forward, OUTPUT);
-  pinMode(pin_reverse, OUTPUT);
-  pinMode(pin_left,    OUTPUT);
-  pinMode(pin_right,   OUTPUT);
-
-  digitalWrite(pin_forward, HIGH);
-  digitalWrite(pin_reverse, HIGH);
-  digitalWrite(pin_left,    HIGH);
-  digitalWrite(pin_right,   HIGH);
-
-  Serial.begin(9600);
+    pinMode(pin_forward, OUTPUT);
+    pinMode(pin_reverse, OUTPUT);
+    pinMode(pin_left,    OUTPUT);
+    pinMode(pin_right,   OUTPUT);
+
+    digitalWrite(pin_forward, HIGH);
+    digitalWrite(pin_reverse, HIGH);
+    digitalWrite(pin_left,    HIGH);
+    digitalWrite(pin_right,   HIGH);
+
+    Serial.begin(9600);
 }

 void loop(){
-  if(commandComplete){
-    Serial.println();
-    Serial.println("Current move:");
-    Serial.println(protocol_num);
-
-    forward_value = protocol_num & forward_mask;
-    reverse_value = protocol_num & reverse_mask;
-    left_value    = protocol_num & left_mask;
-    right_value   = protocol_num & right_mask;
-
-    Serial.print(forward_value);
-    Serial.print(reverse_value);
-    Serial.print(left_value);
-    Serial.print(right_value);
+    if((protocol_num = Serial.read()) == -1) return;

-    digitalWrite(pin_forward, forward_value?LOW:HIGH);
-    digitalWrite(pin_reverse, reverse_value?LOW:HIGH);
-    digitalWrite(pin_left,    left_value?LOW:HIGH);
-    digitalWrite(pin_right,   right_value?LOW:HIGH);
-
-    commandComplete = false;
-  }
+    // sets HIGH for no motion, and LOW to activate motion as we use ground pins to shorten the circuit
+    digitalWrite(pin_forward, (protocol_num & forward_mask) ? LOW : HIGH);
+    digitalWrite(pin_reverse, (protocol_num & reverse_mask) ? LOW : HIGH);
+    digitalWrite(pin_left,    (protocol_num & left_mask) ? LOW : HIGH);
+    digitalWrite(pin_right,   (protocol_num & right_mask) ? LOW : HIGH);
 }

-void serialEvent() {
-  if(Serial.available() > 0){
-    protocol_num = Serial.parseInt();
-  }
-  while(Serial.available() > 0){
-    Serial.read(); // clean up whatever left in Serial
-  }
-  commandComplete = true;
-}
-


Update BH1750FVI_Simple.ino

Update BH1750FVI_Simple.ino

--- examples/BH1750FVI_Simple/BH1750FVI_Simple.ino
+++ examples/BH1750FVI_Simple/BH1750FVI_Simple.ino
@@ -7,7 +7,7 @@
   SDA  <-> D2  [green]
   SCL  <-> D1  [blue]
   ADDR <-> RX  [yellow]
- */
+*/

 #include <Wire.h>
 #include <BH1750FVI.h>


[FW] Several changes to account for prototype PCB

- Swap 595 OE pins for data and address bus
- Fixed off-by-one error in SRAM copy code
- Fixed occasional bug with CE1/CE2 pins on Arduino
  which could stay at +5V if they were HIGH before
  switching them to INPUT (high-Z) mode.
- Move status LED blinking code into loop()
- Removed some trailing whitespace in source file.

--- firmware/MultiRomVC4000_2/MultiRomVC4000_2.ino
+++ firmware/MultiRomVC4000_2/MultiRomVC4000_2.ino
@@ -2,7 +2,7 @@

 #define ROMSIZE 2048

-const byte romImage[] PROGMEM = {
+const byte romImage[] PROGMEM = {
 0x1f, 0x00, 0x20, 0x17, 0x06, 0x20, 0x0e, 0x47, 0xa3, 0xce, 0x7f, 0x80, 0x5a, 0x78, 0x17, 0x05,
 0xf6, 0x0e, 0x26, 0xca, 0xcd, 0x7e, 0x0a, 0x0f, 0x26, 0xca, 0xcd, 0x7e, 0x1a, 0xd9, 0x72, 0x17,
 0x20, 0xc3, 0xcf, 0x5f, 0x00, 0x5b, 0x7b, 0x92, 0xcc, 0x5e, 0xc9, 0xcc, 0x1f, 0x0f, 0x04, 0x02,
@@ -138,8 +138,8 @@
 #define DATA  5    //SER

 #define WR    2
-#define OEDATA    A0  //_G DATA BUS
-#define OEADDRESS A1  //_G ADDRESS BUS
+#define OEDATA    A1  //_G DATA BUS
+#define OEADDRESS A0  //_G ADDRESS BUS

 #define OEVCBUS 6

@@ -160,35 +160,27 @@

  disableVCBus();
  enableSRAM();
-
+
  Serial.begin(9600);
  delay(100);
-

  Serial.println("writing data");
  enableSRAM();
- for (int i=0;i<=ROMSIZE;i++) {
+ for (int i=0;i<ROMSIZE;i++) {
     write2RAM(i,pgm_read_byte(romImage+i));
  }
  disableSRAM();
-
+
  Serial.println("done");
  Serial.println("enable bus to VC4000");
  enableVCBus();
-
- while(1) {
-    digitalWrite(LED,HIGH);
-    delay(300);
-    digitalWrite(LED,LOW);
-    delay(300);
- };
-}
-
-
-
+}

 void loop() {
-
+  digitalWrite(LED,HIGH);
+  delay(300);
+  digitalWrite(LED,LOW);
+  delay(300);
 }

 void enableSRAM() {
@@ -196,14 +188,17 @@
  pinMode(CE2SRAM,OUTPUT);
  digitalWrite(CE1SRAM,LOW);
  digitalWrite(CE2SRAM,HIGH);
-
 }

 void disableSRAM() {
- pinMode(CE1SRAM,INPUT);
- pinMode(CE2SRAM,INPUT);
+  // Ensure that CE1+2 are in LOW state before turning them OFF.
+  // Switching them to INPUT mode while in HIGH state will
+  // activate the internal pullup resistors to VCC (which is a
+  // bad idea!).
  digitalWrite(CE1SRAM,LOW);
  digitalWrite(CE2SRAM,LOW);
+ pinMode(CE1SRAM,INPUT);
+ pinMode(CE2SRAM,INPUT);
 }

@@ -227,15 +222,13 @@
   digitalWrite(WR,HIGH);
   shiftout(address,data);
   digitalWrite(WR,LOW);
-  //delay(5);
   digitalWrite(WR,HIGH);
 }

 void shiftout(unsigned int address, byte data) {
-
   byte lowbyte = address & 0xff;
   byte highbyte = address >> 8;
-
+
   digitalWrite(LATCH,LOW);
   shiftOut(DATA,CLOCK,MSBFIRST,data);
   shiftOut(DATA,CLOCK,MSBFIRST,highbyte);


Committing communication protocol (untested)

--- AndroidTVGateway/edge-agent/edge-agent.ino
+++ AndroidTVGateway/edge-agent/edge-agent.ino
@@ -5,16 +5,20 @@
 #include <SPI.h>
 #include <MFRC522.h>

+#define DHTTYPE           DHT11
+#define WINDOWPIN         4
+#define ACPIN             5
 #define DHTPIN            6
-#define DHTTYPE           DHT11
+#define DOOR_LOCK         7
 #define LED_LIGHT         8
-#define DOOR_LOCK         7

 DHT dht(DHTPIN, DHTTYPE);
 SoftwareSerial XBee(2, 3); // RX, TX
 uint8_t successRead;    // Variable integer to keep if we have Successful Read from Reader
 byte readCard[4];   // Stores scanned ID read from RFID Module
 int lastId = 0;
+char msg[100];
+boolean isCardIn = false;

 // Create MFRC522 instance.
 constexpr uint8_t RST_PIN = 9;     // Configurable, see typical pin layout above
@@ -26,6 +30,8 @@
   XBee.begin(9600);
   Serial.begin(9600);
   dht.begin();
+  pinMode(WINDOWPIN, INPUT);
+  pinMode(ACPIN, INPUT);
   pinMode(LED_LIGHT, OUTPUT);
   pinMode(DOOR_LOCK, OUTPUT);
   digitalWrite(DOOR_LOCK, HIGH);
@@ -36,46 +42,46 @@

 void loop() {
   if (XBee.available()) {
-    String msg = XBee.readString();
-    Serial.println(msg);
-    if (msg == "LON\r") {
+    String incomingMsg = XBee.readString();
+    Serial.println(incomingMsg);
+    if (incomingMsg == "LON\r") {
       digitalWrite(LED_LIGHT, HIGH);
-      XBee.print("{\"a\":\"LON\",\"p\":\"OK\"}\r");
-    } else if (msg == "LOFF\r") {
+      XBee.print("{\"a\":\"LON\"}\r");
+    } else if (incomingMsg == "LOFF\r") {
       digitalWrite(LED_LIGHT, LOW);
-      XBee.print("{\"a\":\"LOFF\",\"p\":\"OK\"}\r");
-    }else if (msg == "DOPEN\r") {
+      XBee.print("{\"a\":\"LOFF\"}\r");
+    }else if (incomingMsg == "DOPEN\r") {
       digitalWrite(DOOR_LOCK, LOW);
-      XBee.print("{\"a\":\"DOPEN\",\"p\":\"OK\"}\r");
-    } else if (msg == "DCLOSE\r") {
+      XBee.print("{\"a\":\"DOPEN\"}\r");
+    } else if (incomingMsg == "DCLOSE\r") {
       digitalWrite(DOOR_LOCK, HIGH);
-      XBee.print("{\"a\":\"DCLOSE\",\"p\":\"OK\"}\r");
-    } else if (msg == "D\r") {
+      XBee.print("{\"a\":\"DCLOSE\"}\r");
+    } else if (incomingMsg == "D\r") {
       syncNode();
     }
   }
   if (getID()) {
     if (!lastId) {
       lastId = 1;
-      char msg[100];
-      sprintf (msg, "{\"a\":\"CI\",\"p\":\"%02x%02x%02x%02x\"}\r", readCard[0], readCard[1], readCard[2], readCard[3]);
-      XBee.print(msg);
-      Serial.println(msg);
+      digitalWrite(DOOR_LOCK, LOW);
+      isCardIn = true;
     }
   } else if (lastId) {
     lastId = 0;
-    XBee.print("{\"a\":\"CO\"}\r");
-    Serial.println("CARDOUT");
+    digitalWrite(DOOR_LOCK, HIGH);
+    isCardIn = true;
   }
 }

 void syncNode() {
   float h = dht.readHumidity();
   float t = dht.readTemperature();
-  char msg[100];
-  sprintf (msg, "{\"a\":\"TEMP\",\"p\":{\"t\":%d,\"h\":%d}}\r", (int) t, (int) h);
-  XBee.print(msg);
-  Serial.println(msg);
+  int window = digitalRead(WINDOWPIN);
+  int ac = digitalRead(ACPIN);
+  char syncmsg[100];
+  sprintf (syncmsg, "{\"a\":\"DATA\",\"p\":{\"t\":%d,\"h\":%d,\"a\":%d,\"w\":%d,\"d\":%d}}\r", (int) t, (int) h, ac, window, (isCardIn ? 1 : 0));
+  XBee.print(syncmsg);
+  Serial.println(syncmsg);
 }

 uint8_t getID() {


Update multiple.ino

Update multiple.ino

--- firmware/examples/multiple.ino
+++ firmware/examples/multiple.ino
@@ -1,9 +1,9 @@
-//#define USE_ADJDS311
+#define USE_ADJDS311
 #define BLINK_LED
 #define USE_BMP085
-//#define USE_TCS34725
+#define USE_TCS34725
 #define USE_TINKER
-//#define USE_TMP006
+#define USE_TMP006

@@ -70,22 +70,22 @@

 void loop() {
     #ifdef USE_ADJDS311
-        runADJDS311();
+        run_ADJDS311();
     #endif

     #ifdef BLINK_LED
-        runBLINK_LED();
+        run_BLINK_LED();
     #endif

     #ifdef USE_BMP085
-        runBMP085();
+        run_BMP085();
     #endif

     #ifdef USE_TCS34725
-        runTCS34725();
+        run_TCS34725();
     #endif

     #ifdef USE_TMP006
-        runTMP006();
+        run_TMP006();
     #endif
 }


remove temperature timer

remove temperature timer

Not needed right now

--- firmware/wibean-firmwarev2.ino
+++ firmware/wibean-firmwarev2.ino
@@ -43,7 +43,6 @@
 // hardware timers
 IntervalTimer heatingTimer;
 IntervalTimer pumpTimer;
-IntervalTimer temperatureTimer;
 // Thermistor LUT
 Thermistor thermistor;
 // the way spark works, we can only return data to the user via the Spark.variable command


add more details to description

add more details to description

--- arduinoTest/USB_to_Android/USB_to_Android.ino
+++ arduinoTest/USB_to_Android/USB_to_Android.ino
@@ -1,9 +1,19 @@
-//Zachary Nelson
-//znelson1@ford.com
-//This program uses a 74hc595 shift register and a
-//7-sement display to display the numbers 0 - 9. It
-//is used to test future implementations of the
-//display control.
+/*
+-------------------------------------------------
+| Zachary Nelson
+| znelson1@ford.com
+|
+| This program uses a 74hc595 shift register and a
+| 7-sement display to display the numbers 0 - 9. It
+| is used to test future implementations of the
+| display control.
+|
+| USB serial support has been added to test USB
+| connections with an Android host device.
+---------------------------------------------------
+*/
+
+

 //Pin connected to ST_CP of 74HC595
 int latchPin = 8;


better description

better description

--- Ensembles/EnsembleOne/firmeware/EnsembleOne_firmware/EnsembleOne_firmware.ino
+++ Ensembles/EnsembleOne/firmeware/EnsembleOne_firmware/EnsembleOne_firmware.ino
@@ -1,7 +1,14 @@
 /* PHOBOS - EnsembleOne firmware v.0.2 (27.05.2017)
+ *
  * using:
- * Arduino 1.8.0
+ * Arduino v1.8.0
+ * MIDI_Library v.4.3.1 by fortyseveneffects
  *
+ * plays:
+ * A - 4 motors on bowls
+ * B - 3 solenoids on a keyboard with medals
+ * C - 3 solenoids on shakers
+ * D - 2 solenoids on wood blocks
  */

 #include <MIDI.h>


Code cleanup, center cam numbers again (even if >=10)

--- RevCamViewer.ino
+++ RevCamViewer.ino
@@ -4,7 +4,6 @@

 #include <ESP8266WiFi.h>
 #include <WiFiClient.h>
-#include <ESP8266WebServer.h>
 #include <ESP8266mDNS.h>
 #include <ESP8266HTTPClient.h>
 #include <Bounce2.h>
@@ -17,29 +16,30 @@
 const int port = 9999;
 const unsigned long restart_timeout = 5*60*1000;

-WiFiClient client;
-
 #define TFT_CS     0
 #define TFT_RST    0
-#define TFT_DC     16
+#define TFT_DC    16
+
+#define PIN_LEFT   5
+#define PIN_RIGHT  4
+
+#define NUM_CAMS  10
+
 Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

-#define PIN_LEFT     5
-#define PIN_RIGHT   4
-
-#define NUM_CAMS  10
+WiFiClient client;

 Bounce b_left   = Bounce();
 Bounce b_right = Bounce();

-uint8_t cam = 4;
+uint8_t cam = 1;

 void setCam(int relativeCam) {
   cam += relativeCam;
   if(cam < 1) cam = NUM_CAMS;
   if(cam > NUM_CAMS) cam = 1;
   tft.fillScreen(ST7735_BLACK);
-  tft.setCursor(36,8);
+  tft.setCursor(104-(48*String(cam).length()), 20);
   tft.setTextColor(ST7735_GREEN);
   tft.setTextSize(12);
   tft.print(cam);


Convert some ints to bytes

Convert some ints to bytes

--- OpenStage/openStage_moveToTarget.ino
+++ OpenStage/openStage_moveToTarget.ino
@@ -119,30 +119,30 @@
   bool keepMoving=1;
   bool axisFinished[numAxes];

-  for (int ii=0; ii<numAxes; ii++){
+  for (byte ii=0; ii<numAxes; ii++){
     axisFinished[ii]=1;
   }

   if (verbose){
     Serial.println("Entering while loop in runSteppersToPos()");
   }
-
+
   while (keepMoving){
-
+
     keepMoving=0;
-    for (int ii=0; ii<numAxes; ii++){
+    for (byte ii=0; ii<numAxes; ii++){
       if (!axisPresent[ii]){
         continue;
       }
-
       if ((*mySteppers[ii]).distanceToGo() != 0){
          keepMoving=1;
          axisFinished[ii]=0;
       }
     }

+
     //Motion is a touch faster if we place run code here
-    for (int ii=0; ii<numAxes; ii++){
+    for (byte ii=0; ii<numAxes; ii++){
       if (axisFinished[ii] || !axisPresent[ii]){
         continue;
       }


gpio0 to gnd to switch through infoscreens

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -148,6 +148,17 @@

   delay(1000);
   --seccount;
+
+  /** You know:
+   *  - press RST (to GND), press GPIO0 (to GND), leave 0 and than RST:
+   *    -> programm your ESP :-)
+   *
+   *  GPIO0 (= D3) and (on press) you can switch to the infoscreens
+   */
+  if (digitalRead(D3) == LOW) {
+    infoScreen++;
+  }
+
   if (seccount%4 == 0) infoScreen++; // change every 4 sec
   if (infoScreen > (SCREENS-1)) infoScreen=0;
 }


re-touch examples

re-touch examples

--- examples/full/full.ino
+++ examples/full/full.ino
@@ -27,7 +27,7 @@
      */
     slave.cbVector[CB_READ_COILS] = readDigitalIn;
     slave.cbVector[CB_WRITE_COIL] = writeDigitlOut;
-    slave.cbVector[CB_READ_REGISTERS] = readAnalogIn;
+    slave.cbVector[CB_READ_REGISTERS] = readMemory;
     slave.cbVector[CB_WRITE_MULTIPLE_REGISTERS] = writeMemory;

     // start slave at baud 9600 on Serial
@@ -42,23 +42,6 @@
      * call the user handler function.
      */
     slave.poll();
-}
-
-/**
- * Handel Read Coils (FC=01)
- * write back the values from digital in pins (input status).
- *
- * handler functions must return void and take:
- *      uint8_t  fc - function code
- *      uint16_t address - first register/coil address
- *      uint16_t length/status - length of data / coil status
- */
-void readCoils(uint16_t address, uint16_t length) {
-    // read coils state
-    for (int i = 0; i < length; i++) {
-        // write one boolean (1 bit) to the response buffer
-        slave.writeCoilToBuffer(i, digitalRead(address + i));
-    }
 }

 /**
@@ -86,16 +69,30 @@
 }

 /**
+ * Handel Read Coils (FC=01)
+ * write back the values from digital in pins (input status).
+ */
+void readCoils(uint16_t address, uint16_t length) {
+    // read coils state
+    for (int i = 0; i < length; i++) {
+        // write one boolean (1 bit) to the response buffer
+        slave.writeCoilToBuffer(i, digitalRead(address + i));
+    }
+}
+
+/**
  * Handel Read Holding Registers (FC=03)
- * write back the values from analog in pins (input registers).
- *
- * handler functions must return void and take:
- *      uint8_t  fc - function code
- *      uint16_t address - first register/coil address
- *      uint16_t length/status - length of data / coil status
+ * write back the values from eeprom (holding registers).
  */
-void readMemory(uint16_t address, uint16_t length) {
+void readMemory(uint8_t fc, uint16_t address, uint16_t length) {
     uint16_t value;
+
+    // check the function code
+    if (fc == FC_READ_INPUT_REGISTERS) {
+        // read eeprom memory
+        readAnalogIn(address, length);
+        return;
+    }

     // read program memory
     for (int i = 0; i < length; i++) {
@@ -109,20 +106,8 @@
 /**
  * Handel Read Input Registers (FC=04)
  * write back the values from analog in pins (input registers).
- *
- * handler functions must return void and take:
- *      uint8_t  fc - function code
- *      uint16_t address - first register/coil address
- *      uint16_t length/status - length of data / coil status
  */
-void readAnalogIn(uint8_t fc, uint16_t address, uint16_t length) {
-    // check the function code
-    if (fc == FC_READ_HOLDING_REGISTERS) {
-        // read eeprom memory
-        readMemory(address, length);
-        return;
-    }
-
+void readAnalogIn(uint16_t address, uint16_t length) {
     // read analog input
     for (int i = 0; i < length; i++) {
         // write uint16_t value to the response buffer
@@ -135,17 +120,13 @@
  * set digital output pins (coils) on and off
  */
 void writeDigitlOut(uint8_t fc, uint16_t address, uint16_t status) {
+    // set digital pin state
     digitalWrite(address, status);
 }

 /**
  * Handel Write Holding Registers (FC=16)
  * write data into program.
- *
- * handler functions must return void and take:
- *      uint8_t  fc - function code
- *      uint16_t address - first register/coil address
- *      uint16_t length/status - length of data / coil status
  */
 void writeMemory(uint8_t fc, uint16_t address, uint16_t length) {
     uint16_t value;


Move volatiles into private members and move ISR code into internal callback methods.

--- examples/plsr/plsr.ino
+++ examples/plsr/plsr.ino
@@ -71,8 +71,6 @@
 static const DUINO_Function::Jack out_jacks[4] =
   {DUINO_Function::CO1, DUINO_Function::CO2, DUINO_Function::CO3, DUINO_Function::CO4};

-volatile int8_t current_step;
-
 void clock_ext_isr();
 void reset_isr();

@@ -130,6 +128,7 @@
     randomSeed(cv_read(CI1));

     // initialize interface
+    current_step = -1;
     displayed_step = -1;

     // load params
@@ -180,6 +179,17 @@
   virtual void function_loop()
   {
     widget_loop();
+  }
+
+  void clock_ext_callback()
+  {
+    Clock.on_jack(gt_read_debounce(DUINO_Function::GT3));
+  }
+
+  void reset_callback()
+  {
+    current_step = -1;
+    Clock.reset();
   }

   void clock_clock_callback()
@@ -364,21 +374,14 @@
   DUINO_DisplayWidget * widget_swing_;
   DUINO_MultiDisplayWidget<STEP_MAX> * widgets_patterns_[4];

+  volatile int8_t current_step;
   int8_t displayed_step;
 };

 DU_PLSR_Function * function;

-void clock_ext_isr()
-{
-  Clock.on_jack(function->gt_read_debounce(DUINO_Function::GT3));
-}
-
-void reset_isr()
-{
-  current_step = -1;
-  Clock.reset();
-}
+void clock_ext_isr() { function->clock_ext_callback(); }
+void reset_isr() { function->reset_callback(); }

 void clock_callback() { function->clock_clock_callback(); }
 void external_callback() { function->clock_external_callback(); }
@@ -395,8 +398,6 @@
 {
   function = new DU_PLSR_Function();

-  current_step = -1;
-
   function->begin();
 }


Switched initial relay power states to OFF

In case I'm away from home for an extended period of time and the power is cycled, I'd rather not have a high-wattage bulb consuming a lot of energy wastefully.

--- Sketches/Alexa/AlexaWemoSwitchMulti/AlexaWemoSwitchMulti.ino
+++ Sketches/Alexa/AlexaWemoSwitchMulti/AlexaWemoSwitchMulti.ino
@@ -36,11 +36,10 @@
   pinMode(D2, OUTPUT);
   pinMode(D3, OUTPUT);
   pinMode(D4, OUTPUT);
-  digitalWrite(D1, HIGH); // Start with light on
-  digitalWrite(D2, HIGH); // Start with light on
-  digitalWrite(D3, HIGH); // Start with light on
-  digitalWrite(D4, HIGH); // Start with light on
-//  digitalWrite(D1, LOW); // Start with light off
+  digitalWrite(D1, LOW); // Start with light off
+  digitalWrite(D2, LOW); // Start with light off
+  digitalWrite(D3, LOW); // Start with light off
+  digitalWrite(D4, LOW); // Start with light off

   // Set the UUIDs and socket information:
   prepareIds();


Juggle works

Juggle works

--- Goggles.ino
+++ Goggles.ino
@@ -1,54 +1,121 @@
 #include <Adafruit_NeoPixel.h>

 #define PIN 16
-#define BUTTON 9
+#define BUTTON 7
 #define DELAY 35
+#define PIXELS 16
+#define RIGHT_NOSE 14
+#define LEFT_NOSE 4

-Adafruit_NeoPixel pixels = Adafruit_NeoPixel(32, PIN);
+Adafruit_NeoPixel pixels = Adafruit_NeoPixel(PIXELS * 2, PIN);

-uint8_t  mode   = 0, // Current animation effect
+uint8_t  mode   = 3, // Current animation effect
          offset = 0; // Position of spinny eyes
-uint32_t prevTime;
+volatile byte changeMode = false;

 void setup() {
+  pinMode(BUTTON, INPUT_PULLUP);
+  attachInterrupt(digitalPinToInterrupt(BUTTON), pin_ISR, FALLING);
   pixels.begin();
   pixels.setBrightness(85); // 1/3 brightness
-  prevTime = millis();
 }

 void loop() {
-  uint8_t  i;
-  uint32_t t;
+  if (changeMode) {
+    mode++;
+    changeMode = false;
+    if (mode > 5) {
+      mode = 0;
+    }
+  }

   switch(mode) {
-
   case 0:
-    wheel(0xFF0000);
+    rollers(0xFF0000);
     break;
   case 1:
-    wheel(0x00FF00);
+    blankAll();
+    juggle(0xFFFF00);
     break;
   case 2:
-    wheel(0x0000FF);
+    rollers(0x00FF00);
     break;
-  }
+  case 3:
+    blankAll();
+    juggle(0x00FFFF);
+    break;
+  case 4:
+    rollers(0x0000FF);
+    break;
+  case 5:
+    blankAll();
+    juggle(0xFF00FF);
+    break;

-  t = millis();
-  if((t - prevTime) > DELAY * 16) {
-    mode++;
-    if(mode > 2) {
-      mode = 0;
-    }
-    for(i=0; i<32; i++) pixels.setPixelColor(i, 0);
-    prevTime = t;
+
   }
 }

-void wheel(uint32_t colour) {
-  for(int i=0; i<32; i++) {
+void pin_ISR() {
+  changeMode = true;
+}
+
+void juggle(uint32_t colour) {
+  for(int i = 0; i < 1; i++) {
+    rollLeft(colour);
+    rollRight(colour);
+  }
+  for(int i = 0; i < 2; i++) {
+    rollLeft(colour);
+  }
+  for(int i = 0; i < 1; i++) {
+    rollRight(colour);
+    rollLeft(colour);
+  }
+  for(int i = 0; i < 2; i++) {
+    rollRight(colour);
+  }
+}
+
+void rollRight(uint32_t colour) {
+  for(int i = RIGHT_NOSE; i < PIXELS + RIGHT_NOSE; i++) {
+    lightOne(i % PIXELS, 0, colour);
+    delay(DELAY);
+  }
+
+  blankAll();
+}
+
+void rollLeft(uint32_t colour) {
+  for(int i = LEFT_NOSE + PIXELS; i > LEFT_NOSE; i--) {
+    lightOne(i % PIXELS, PIXELS, colour);
+    delay(DELAY);
+  }
+
+  blankAll();
+}
+
+void lightOne(int index, int offset, uint32_t colour) {
+  for(int i = offset; i < PIXELS + offset; i++) {
+    uint32_t c = 0;
+    if(i == index + offset) c = colour;
+    pixels.setPixelColor(i, c);
+  }
+  pixels.show();
+}
+
+void blankAll() {
+  for(int i = 0; i < PIXELS * 2; i++) {
+    pixels.setPixelColor(i, 0);
+  }
+  pixels.show();
+}
+
+void rollers(uint32_t colour) {
+  for(int i = 0; i < PIXELS * 2; i++) {
     uint32_t c = 0;
     if(((offset + i) & 7) < 2) c = colour;
-    pixels.setPixelColor(   i, c);
+    pixels.setPixelColor(i, c);
   }
   pixels.show();
   offset++;