Fixed messy variable labels

Fixed messy variable labels

--- 2018-FirefighterL1/Left_Right_Follow.ino
+++ 2018-FirefighterL1/Left_Right_Follow.ino
@@ -1,57 +1,57 @@
 void levelOneNav(){
-followdirection = 0; //left follow or right follow
+followDirection = 0; //left follow or right follow
 lowerleftroomdistance = 10; //distance to activate Rick's Code

-while(followdirection < 7)
+while(followDirection < 7)
 {
-  if (frontultrasonic.getDistance() > 2 && rightultrasonic.getDistance() < 2)
+  if (frontRightUltrasonic.getDistance() > 2 && rightUltrasonic.getDistance() < 2)
   {
     moveSlightLeft();
     delay(500);         //move left diagnal
-    moveSlightRight().wait(rightultrasonic.getDistance() < 2);
+    moveSlightRight().wait(rightUltrasonic.getDistance() < 2);
     delay(500);    //move diagnol towards the wall until your close to the wall
   }

-  else if(rightultrasonic.getDistance() > 2 && frontultrasonic.getDistance() > 2)
+  else if(rightUltrasonic.getDistance() > 2 && frontRightUltrasonic.getDistance() > 2)
   {
     turn(-90);    //if there is no right wall turn right
     delay(500);
-    followdirection = followdirection +1;
+    followDirection = followDirection +1;
   }

-  else if(rightultrasonic.getDistance() < 2 && frontultrasonic.getDistance() < 2)
+  else if(rightUltrasonic.getDistance() < 2 && frontRightUltrasonic.getDistance() < 2)
   {
     turn(90);
     delay(500)
-    followdirection = followdirection + 1;
+    followDirection = followDirection + 1;
   }

-  else followdirection = followdirection;
+  else followDirection = followDirection;
 }

-while(followdirection >= 7)
+while(followDirection >= 7)
 {
-  if (frontultrasonic.getDistance() > closeToWall && lefttultrasonic.getDistance() < closeToWall)
+  if (frontLeftUltrasonic.getDistance() > closeToWall && leftUltrasonic.getDistance() < closeToWall)
   {
     moveSlightRight();
     delay(500);    //move left diagnal
-    moveSlightLeft().wait(leftultrasonic.getDistance() < closeToWall);
+    moveSlightLeft().wait(leftUltrasonic.getDistance() < closeToWall);
     delay(500);
   }

-  else if (leftultrasonic.getDistance() > 2)
+  else if (leftUltrasonic.getDistance() > 2)
   {
     moveright();    //if there is no left wall turn left
     delay(500);
-    followdirection = followdirection + 1;
+    followDirection = followDirection + 1;
   }
-  else if (frontultrasonic.getDistance() < lowerleftroomdistance)
+  else if (frontRightUltrasonic.getDistance() < lowerleftroomdistance)
   {
-    followdirection = followdirection + 1;
+    followDirection = followDirection + 1;
   }
 }

-while(followdirection = 8)
+while(followDirection = 8)
 {
   //void lowerRightRoom(){
   turn(0); //turn(0) is a way to reset gyro measurements
@@ -84,27 +84,27 @@

 }

-while(followdirection >= 9)
+while(followDirection >= 9)
 {
-  if (frontultrasonic.getDistance() > closeToWall && lefttultrasonic.getDistance() < closeToWall)
+  if (frontLeftUltrasonic.getDistance() > closeToWall && leftUltrasonic.getDistance() < closeToWall)
   {
     moveSlightRight();
     delay(500);    //move left diagnal
-    moveSlightLeft().wait(leftultrasonic.getDistance() < closeToWall);
+    moveSlightLeft().wait(leftUltrasonic.getDistance() < closeToWall);
     delay(500);
   }

-  else if (leftultrasonic.getDistance() > 2 && frontultrasonic.getDistance() > 2)
+  else if (leftUltrasonic.getDistance() > 2 && frontLeftUltrasonic.getDistance() > 2)
   {
     turn(90);
     delay(500);
-    followdirection = followdirection + 1;
+    followDirection = followDirection + 1;
   }
-  else if (leftultrasonic.getDistance() < 2 && frontultrasonic.getDistance() < 2)
+  else if (leftUltrasonic.getDistance() < 2 && frontLeftUltrasonic.getDistance() < 2)
   {
     turn(-90);
     delay(500);
-    followdirection = followdirection + 1;
+    followDirection = followDirection + 1;
   }
 }
 }


Don't include the null character when returning lengths written to string buffers.

--- CharBuffer.ino
+++ CharBuffer.ino
@@ -14,8 +14,8 @@
   } else {
     pad = 0;
   }
-  memcpy(buf+pad, b, l+1);
-  return l+pad;
+  memcpy(&buf[pad], b, l+1);
+  return (l+pad);
 }

 int cbPrintInt(char* buf, int n) {
@@ -42,7 +42,7 @@
   byte offset = cbPrintInt(buffer, valueA);
   buffer[offset++] = '.';
   offset += cbPrintInt(&buffer[offset], valueB);
-  buffer[offset++] = 0;
+  buffer[offset] = 0;
   return offset;
 }

@@ -67,7 +67,7 @@
     buffer[offset++] = ':';
     offset += cbPrintInt(&buffer[offset], second(*t), 2);
   }
-  buffer[offset++] = 0;
+  buffer[offset] = 0;
   return offset;
 }

@@ -76,10 +76,10 @@
 int sprintFilename(char* buffer, time_t* t) {
   byte offset = sprintTime(buffer, t, true);
   buffer[offset++] = '.';
-  buffer[offset++] = 'c';
-  buffer[offset++] = 's';
-  buffer[offset++] = 'v';
-  buffer[offset++] = 0;
+  buffer[offset++] = 'C';
+  buffer[offset++] = 'S';
+  buffer[offset++] = 'V';
+  buffer[offset] = 0;
   return offset;
 }

@@ -93,6 +93,6 @@
     }
     buf[offset++] = (char)(dir.name[i]);
   }
-  buf[offset++] = 0;
+  buf[offset] = 0;
   return offset;
 }


Fixed polling bug

Fixed polling bug

--- module/module.ino
+++ module/module.ino
@@ -178,10 +178,10 @@
 				if (sendCount > minCount) {
           			return sendCount;
 				}
+				else {
+					return 0;
+				}
 			}
-        	else {
-				return 0;
-        	}
 		}
 		else {
 			pollCounter = 0;


Kleine Korrektur der Beschreibung

Kleine Korrektur der Beschreibung

--- examples/LightMeter_LCD/LightMeter_LCD.ino
+++ examples/LightMeter_LCD/LightMeter_LCD.ino
@@ -8,8 +8,8 @@
  * Version 1.2
  * Datum: 05.08.2013
  *
- * Das Programm benutzt den RTC DS1307 und
- * zeigt die Zeit auf einem 16x2-Symbol-LCD.
+ * Das Programm benutzt den BH1750 (Umgebiungslichtsensor)
+ * und zeigt die Werte in Lux auf einem 16x2-Symbol-LCD.
  *
  * Verdrahtung (UNO, Nano...)
  *


Support reading serial in so we can toggle cameras (and led); cleaning up debug statements

--- camera_box/camera_box.ino
+++ camera_box/camera_box.ino
@@ -19,6 +19,7 @@

 void setup(void) {
   Serial.begin(9600);
+  Serial.flush();

   // Turn off LED inside camera box
   pinMode(led_pin, OUTPUT);
@@ -32,26 +33,52 @@
   turn_camera_on(CAM_01_PIN);
   turn_camera_on(CAM_02_PIN);

-  Serial.println("PANOPTES Arduino Code for Electronics");
-
   if (! mma.begin()) {
-    Serial.println("Couldn't start Accelerometer");
     while (1);
-  } else {
-    Serial.println("MMA8451 Accelerometer found");
   }

   dht.begin();
-  Serial.println("DHT22found");

   // Check Accelerometer range
-  mma.setRange(MMA8451_RANGE_2_G);
-  Serial.print("Accelerometer Range = "); Serial.print(2 << mma.getRange());
-  Serial.println("G");
-
+  // mma.setRange(MMA8451_RANGE_2_G);
+  // Serial.print("Accelerometer Range = "); Serial.print(2 << mma.getRange());
+  // Serial.println("G");
 }

 void loop() {
+
+  // Read any serial input
+  //    - Input will be two comma separated integers, the
+  //      first specifying the pin and the second the status
+  //      to change to (1/0). Cameras and debug led are
+  //      supported.
+  //      Example serial input:
+  //           4,1   # Turn fan on
+  //          13,0   # Turn led off
+  while(Serial.available() > 0){
+      int pin_num = Serial.parseInt();
+      int pin_status = Serial.parseInt();
+
+      switch(pin_num){
+        case CAM_01_PIN:
+          if(pin_status == 1){
+            turn_camera_on(CAM_01_PIN);
+          } else {
+            turn_camera_off(CAM_01_PIN);
+          }
+          break;
+        case CAM_02_PIN:
+          if(pin_status == 1){
+            turn_camera_on(CAM_02_PIN);
+          } else {
+            turn_camera_off(CAM_02_PIN);
+          }
+          break;
+        case led_pin:
+          digitalWrite(pin_num, pin_status);
+          break;
+      }
+  }

   Serial.print("{");


json mqtt temperature

json mqtt temperature

send temperature and humidity to MQTT serveur with a payload in JSON
format

--- wifi_http_request/wifi_http_request.ino
+++ wifi_http_request/wifi_http_request.ino
@@ -107,7 +107,7 @@
     // Reading temperature for humidity takes about 250 milliseconds!
     // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
     humidity = dht.readHumidity();          // Read humidity (percent)
-    temp_f = dht.readTemperature(true);     // Read temperature as Fahrenheit
+    temp_f = dht.readTemperature(false);     // Read temperature as Fahrenheit
     // Check if any reads failed and exit early (to try again).
     if (isnan(humidity) || isnan(temp_f)) {
       Serial.println("Failed to read from DHT sensor!");
@@ -133,7 +133,14 @@
     Serial.println(humidity);
     mqttClient.connect("ESP1");
     char temp_c[20];
-    sprintf(temp_c, "%f", temp_f);
-    mqttClient.publish("node/temp",temp_c);
+    char hum_c[20];
+    dtostrf(temp_f,7, 2, temp_c);
+    dtostrf(humidity,7, 2, hum_c);
+    String jsonStr = "{ \"tmp\": ";
+    jsonStr.concat(temp_c);
+    jsonStr.concat(",\"hum\":");
+    jsonStr.concat(hum_c);
+    jsonStr.concat("}");
+    mqttClient.publish("node/temp",jsonStr);
 }


got it working

got it working

Now the display messages reflect the ID of the external ESP chip.

--- Arduino/HelloMesh_OLED/HelloMesh_OLED.ino
+++ Arduino/HelloMesh_OLED/HelloMesh_OLED.ino
@@ -1,7 +1,6 @@
 // Based on the HelloMesh Example
 // Add OLED for debugging messages
 // I have two identical NodeMCUs, both programmed the same, yet one runs slower than the other?
-

 #include <ESP8266WiFi.h>
 #include <ESP8266WiFiMesh.h>
@@ -30,50 +29,50 @@
  */
 String manageRequest(String request)
 {
-	/* Print out received message */
-	Serial.print("received: ");
-	Serial.println(request);
+  /* Print out received message */
+  Serial.print("received: ");
+  Serial.println(request);

-	/* return a string to send back */
-	char response[60];
-	sprintf(response, "Hello world response #%d from Mesh_Node%d.", response_i++, ESP.getChipId());
-	return response;
+  // Display the current chip ID in yellow
+  // Display the incoming message
+  display.clearDisplay();
+  display.setCursor(0,0);
+  display.println(ESP.getChipId());
+  display.setCursor(0,16);
+  display.print("Received: ");
+  display.println(request);
+  display.display();
+
+  /* return a string to send back */
+  char response[60];
+  sprintf(response, "Hello #%d from %d.", response_i++, ESP.getChipId());
+  return response;
 }

 void setup(){
   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
+  // empty the buffer
   display.clearDisplay();
   display.display();
   display.setTextSize(1);
   display.setTextColor(WHITE);
-  /*
-	Serial.begin(115200);
-	delay(10);
-
-	Serial.println();
-	Serial.println();
-	Serial.println("Setting up mesh node...");
-
-	/* Initialise the mesh node */
+  display.setCursor(0,0);
+  display.println(ESP.getChipId());
+  display.setCursor(0,16);
+  display.print("Searching...");
+  display.display();
+
 	mesh_node.begin();
 }

 void loop()
 {
-	/* Accept any incoming connections */
-	mesh_node.acceptRequest();
+  /* Accept any incoming connections */
+  mesh_node.acceptRequest();

-	/* Scan for other nodes and send them a message */
-	char request[60];
-	sprintf(request, "Hello world request #%d from Mesh_Node%d.", request_i++, ESP.getChipId());
-
-  display.clearDisplay();
-  display.setCursor(0,0);
-  display.println("Hello World!");
-  display.setCursor(0,16);
-  display.println(request);
-  display.display();
-
-	mesh_node.attemptScan(request);
-	delay(1000);
-}
+  /* Scan for other nodes and send them a message */
+  char request[60];
+  sprintf(request, "Hello #%d from %d.", request_i++, ESP.getChipId());
+  mesh_node.attemptScan(request);
+  delay(1000);
+}


RFduino: sanity check of sleep time, removed possible integer overflow

--- LBridge_RFduino_V09/LBridge_RFduino_V09.ino
+++ LBridge_RFduino_V09/LBridge_RFduino_V09.ino
@@ -40,6 +40,8 @@
  *  V0.9.04
  *  - minimum voltage set to 2300 mV to ensure proper BLE operation (@bertrooode)
  *  - debug oputput with no sensor available cleanded
+ *  V0.9.05
+ *  - possible overflow error in sleep time fixed (@bertrooode)
  */

 /* ********************* program configuration options **********************/
@@ -74,8 +76,8 @@
 #define LB_ADVERT "rfduino"     // dont change "rfduino"
                                 // length of device name and advertisement <=15!!!
 #define LB_VERSION "V0.9"       // program version
-#define LB_MINOR_VERSION ".04"  // indicates minor version
-#define LB_DATETIME "180211_1953" // date_time
+#define LB_MINOR_VERSION ".05"  // indicates minor version
+#define LB_DATETIME "180213_1332" // date_time
 #define SPIKE_HEIGHT 40         // minimum delta to be a spike

 #define MAX_VOLTAGE 3600        // adjust voltage measurement to have a wider rrange
@@ -178,8 +180,8 @@
 byte protocolType = 1;              // 1 - LimiTTer
 byte runPeriod = 1;                 // czas w minutach - 0 = tylko na żądanie

-unsigned int time_loop_started = 0;
-unsigned int time_elapsed = 0;
+unsigned long time_loop_started = 0;
+unsigned long time_elapsed = 0;

 bool BatteryOK = false;

@@ -457,6 +459,12 @@
   }

   time_elapsed = mymillis() - time_loop_started;
+  // sanity check
+  if ( time_elapsed > (60000*10) ) {
+    // in case of terror set to 5 mins fix
+    print_statef(" *** error in sleep time calculationm (%d ms) set to 5 min fix", time_elapsed);
+    time_elapsed = 5*60000L;
+  }
   print_statef("loop %d - end - NFCReady = %d, sleep for %d s", loop_cnt, NFCReady, (60 * runPeriod)-(time_elapsed/1000));

   Serial.end();         // reduce power consumption


Nam, the one and only

Nam, the one and only

--- 2018-FirefighterL1/Left_Right_Follow.ino
+++ 2018-FirefighterL1/Left_Right_Follow.ino
@@ -34,6 +34,7 @@
   if(frontRightUltrasonic.getDistance() < dogDistance){
     dog2 = true;
   }
+  delay(50);
 }

 void levelOneNav() {
@@ -45,8 +46,13 @@
   upperRightRoom();
   secondDogCheck();

-  if(dog2){
-    //turn around and get to the lower right room the long way
+  if(dog2) {
+    turn(-90); //turn towards start
+    moveForward(60); //move back to start
+    turn(90); //turn downward
+    moveForward(36);  //move down past upperRightRoom
+    turn(90); //turn left
+
   } else {
     //proceed forward and get to the lower right room the short way
   }
@@ -77,11 +83,10 @@
   while(followDirection == 8)
   {
     //void lowerRightRoom(){
-    //ADD TURN(0) TO MOVE FUNCTION

     turn(-45);

-    //moveForward(diagonalMove);  //this function is located on Alex's laptop, which is currently dead
+    moveForward(diagonalMove);

     turn(-90);
     delay(1000);  //see if there's fire in the upper corner
@@ -91,11 +96,12 @@

     while(frontRightUltrasonic.getDistance() > closeToWall){ //roll forward until the robot gets close to the lower wall
       rollForward();
+      delay(50);
     }
     stopRobot();

     turn(-90);  //turn right towards the exit of the room
-    //moveForward(lateralMove); //see above
+    moveForward(lateralMove);
     turn(0);

   }


Update Arduino_8_Zone_Irrigation_Controller.ino

Add the ability to receive the message "advance" and then advance the controller to the next scheduled zone.

--- Arduino_8_Zone_Irrigation_Controller.ino
+++ Arduino_8_Zone_Irrigation_Controller.ino
@@ -358,6 +358,9 @@
   if (strcmp(inValue[0],"allOff")==0) {
     allOff();
   }
+  if (strcmp(inValue[0],"advance")==0) {
+    toggleOff();
+  }
   if (strcmp(inValue[0],"pump")==0) {
     if (strcmp(inValue[1],"0")==0) {
       isConfigPump = false;


Update K_Nearest_Neighbors_Template.ino

Update K_Nearest_Neighbors_Template.ino

--- K_Nearest_Neighbors_Template/K_Nearest_Neighbors_Template.ino
+++ K_Nearest_Neighbors_Template/K_Nearest_Neighbors_Template.ino
@@ -30,8 +30,8 @@

 // Define max height/weight/etc.
 // FIXME: For each feature
+const int [feature]_MIN = [number];
 const int [feature]_MAX = [number];
-const int [feature]_MIN = [number];

 // Takes the features from the current object and converts them to strings and integers
 // **
@@ -121,6 +121,7 @@
       kNearestObjects[max_index].type = knownObjects[i].type;
       // FIXME: For each feature
       kNearestObjects[max_index].[feature] = knownObjects[i].[feature];
+    }
   }

   // For testing purposes
@@ -175,8 +176,6 @@
   digitalWrite(IR_SENSOR_PIN_1, HIGH);

   // Setup any features that need it
-
-  String closestObject;
 }

 void loop() {


Update to restrict i value in PID controller

--- TeensyQuad.ino
+++ TeensyQuad.ino
@@ -662,6 +662,8 @@
   float rollError = sensorRoll - rollSetPoint;
   if (abs(rollError) < 0.5) rollError = 0.0;
   rollErrSum += rollKi * rollError;
+  if (rollErrSum > ROLL_PID_MAX) rollErrSum = ROLL_PID_MAX;
+  if (rollErrSum < -ROLL_PID_MAX) rollErrSum = -ROLL_PID_MAX;
   rollOutput = (rollKp * rollError + rollErrSum + rollKd * (rollError - lastRollError));
   if (rollOutput > 180.0) rollOutput = 180.0;
   if (rollOutput < -180.0) rollOutput = -180.0;
@@ -674,6 +676,8 @@
   float pitchError = sensorPitch - pitchSetPoint;
   if (abs(pitchError) < 0.5) pitchError = 0.0;
   pitchErrSum += pitchKi * pitchError;
+  if (pitchErrSum > PITCH_PID_MAX) pitchErrSum = PITCH_PID_MAX;
+  if (pitchErrSum < -PITCH_PID_MAX) pitchErrSum = -PITCH_PID_MAX;
   pitchOutput = (pitchKp * pitchError + pitchErrSum + pitchKd * (pitchError - lastPitchError));
   if (pitchOutput > 180.0) pitchOutput = 180.0;
   if (pitchOutput < -180.0) pitchOutput = -180.0;
@@ -686,6 +690,8 @@
   float error_tmp = sensorYaw - yawSetPoint;
   if (abs(yawError) < 0.5) yawError = 0.0;
   yawErrSum += yawKi * error_tmp;
+  if (yawErrSum > YAW_PID_MAX) yawErrSum = YAW_PID_MAX;
+  if (yawErrSum < -YAW_PID_MAX) yawErrSum = -YAW_PID_MAX;
   yawOutput = (yawKp * error_tmp + yawErrSum + yawKd * (error_tmp - lastYawError));
   if (yawOutput > 360.0) yawOutput = 360.0;
   if (yawOutput < -360.0) yawOutput = -360.0;


Added SPI function that reads content of one of the RTC6715 registers

--- src/cyclop_plus/cyclop_plus.ino
+++ src/cyclop_plus/cyclop_plus.ino
@@ -72,6 +72,11 @@
 char    *shortNameOfChannel(uint8_t channel, char *name);
 void     setRTC6715Frequency(uint16_t frequency);
 void     setOptions( void );
+void     spi_0(void);
+void     spi_1(void);
+void     spiEnableHigh( void );
+void     spiEnableLow( void );
+int      spiRead( void );
 void     testAlarm( void );
 void     updateScannerScreen(uint8_t position, uint8_t value );
 void     writeEeprom(void);
@@ -554,6 +559,42 @@
 }

 //******************************************************************************
+//* function: readRTC6715Register  - NOT TESTED!
+//*         : Returns the contents of a given register in  long.
+//*         : The 20 LSB of the long is the register content. The rest is zero
+//*         : padding.
+//*
+//* SPI data: 4  bits  Register Address  LSB first
+//*         : 1  bit   Read or Write     0=Read 1=Write
+//*         : 20 bits  Register content
+//******************************************************************************
+long readRTC6715Register( uint8_t reg )
+{
+  long retVal = 0;
+  uint8_t i;
+
+  // Enable SPI
+  spiEnableHigh();
+  spiEnableLow();
+
+  // Address (4 LSB bits)
+  for (i = 4; i; i--, reg >>= 1 ) {
+    (reg & 0x1) ? spi_1() : spi_0();
+  }
+  // Read/Write bit
+  spi_0(); // Read
+
+  // Data (20 LSB bits)
+  for (i = 20; i; i--, retVal <<= 1 ) {
+    spiRead() ? retVal &= 0x01 : retVal &= 0x00;
+  }
+  // Disable SPI
+  spiEnableHigh();
+
+  return retVal;
+}
+
+//******************************************************************************
 //* function: calcFrequencyData
 //*         : calculates the frequency value for the syntheziser register B of
 //*         : the RTC6751 circuit that is used within the RX5808/RX5880 modules.
@@ -592,7 +633,7 @@

   // Bit bang the syntheziser register

-  // Clock
+  // Enable SPI pin
   spiEnableHigh();
   delayMicroseconds(1);
   spiEnableLow();
@@ -616,7 +657,7 @@
   spi_0();
   spi_0();

-  // Clock
+  // Disable SPI pin
   spiEnableHigh();
   delayMicroseconds(1);

@@ -628,7 +669,7 @@
 //******************************************************************************
 //* function: spi_1
 //******************************************************************************
-void spi_1()
+void spi_1( void )
 {
   digitalWrite(SPI_CLOCK_PIN, LOW);
   delayMicroseconds(1);
@@ -643,7 +684,7 @@
 //******************************************************************************
 //* function: spi_0
 //******************************************************************************
-void spi_0()
+void spi_0( void )
 {
   digitalWrite(SPI_CLOCK_PIN, LOW);
   delayMicroseconds(1);
@@ -656,9 +697,25 @@
 }

 //******************************************************************************
+//* function: spiRead  - NOT TESTED!
+//******************************************************************************
+int spiRead( void )
+{
+  int retVal;
+  digitalWrite(SPI_CLOCK_PIN, LOW);
+  delayMicroseconds(1);
+  digitalWrite(SPI_CLOCK_PIN, HIGH);
+  delayMicroseconds(1);
+  digitalWrite(SPI_CLOCK_PIN, LOW);
+  retVal = digitalRead(SPI_DATA_PIN);
+  delayMicroseconds(1);
+  return retVal;
+}
+
+//******************************************************************************
 //* function: spiEnableLow
 //******************************************************************************
-void spiEnableLow()
+void spiEnableLow( void )
 {
   delayMicroseconds(1);
   digitalWrite(SLAVE_SELECT_PIN, LOW);
@@ -668,7 +725,7 @@
 //******************************************************************************
 //* function: spiEnableHigh
 //******************************************************************************
-void spiEnableHigh()
+void spiEnableHigh( void )
 {
   delayMicroseconds(1);
   digitalWrite(SLAVE_SELECT_PIN, HIGH);


Gain Tuned at no load.  Need to drive test it.

--- scr_arduino/scr_arduino.ino
+++ scr_arduino/scr_arduino.ino
@@ -76,21 +76,25 @@
 double R_EncoderAngle = 0; // In revolutions (360.0 degrees = 1.0)

 // Speed Controller Initialization
-// Input, Output, Setpoint, P, I, D, DIRECT)
+
+double L_PIDout = 0;
+double R_PIDout = 0;
+
+// Input, Output, Setpoint, P, I, D, DIRECT/REVERSE)
 PID L_DCMotorPID(&L_WheelVelocity,
-                 &lm_cmd,
+                 &L_PIDout,
                  &lw_cmd_spd,
-                 3.5,
-                 .001,
-                 .15,
+                 1.5,
+                 0.0,
+                 0.1,
                  REVERSE);

 PID R_DCMotorPID(&R_WheelVelocity,
-                 &rm_cmd,
+                 &R_PIDout,
                  &rw_cmd_spd,
-                 3.5,
-                 .001,
-                 .15,
+                 1.5,
+                 0.0,
+                 0.1,
                  REVERSE);

 // Motor Callbacks
@@ -152,10 +156,10 @@
   // PID Setup
   L_DCMotorPID.SetMode(AUTOMATIC);
   L_DCMotorPID.SetOutputLimits(-127, 127);
-  L_DCMotorPID.SetSampleTime(75);
+  L_DCMotorPID.SetSampleTime(20);
   R_DCMotorPID.SetMode(AUTOMATIC);
   R_DCMotorPID.SetOutputLimits(-127, 127);
-  R_DCMotorPID.SetSampleTime(75n);
+  R_DCMotorPID.SetSampleTime(20);

   // Motor Driver Init
   pmd.init();
@@ -169,6 +173,10 @@
   // Compute New Control Values
   L_DCMotorPID.Compute();
   R_DCMotorPID.Compute();
+
+  // Update motor command
+  lm_cmd += L_PIDout;
+  rm_cmd += R_PIDout;

   // Populate messages
   l_enc_msg.data = lm_cmd;


and make sure it compiles...

and make sure it compiles...

--- Arduino/hardware/REV10/REV10SecureBHR/REV10SecureBHR.ino
+++ Arduino/hardware/REV10/REV10SecureBHR/REV10SecureBHR.ino
@@ -769,7 +769,7 @@
     const uint8_t nearOverrunThreshold = OTV0P2BASE::GSCT_MAX - 8; // ~64ms/~32 serial TX chars of grace time...

     // Update internal boiler hub state and
-    BoilerHub.processCallsForHeat(second0, hubManager.inHubMode());
+    BoilerHub.processCallsForHeat((0 == TIME_LSD), hubManager.inHubMode());

     // Sleep in low-power mode (waiting for interrupts) until seconds roll.
     // NOTE: sleep at the top of the loop to minimise timing jitter/delay from Arduino background activity after loop() returns.


switch flags to use struct for clarity test directive triggers flag

--- onboard_controller/onboard_controller.ino
+++ onboard_controller/onboard_controller.ino
@@ -13,13 +13,11 @@
 #define MARKER_LON 0xFC
 #define MARKER_ALT 0xFD
 #define MARKER_FLAG 0xFE
-#define FLAG_GPS_FIX 0b00000001
-#define FLAG_PAYLOAD 0b00000010

 //directives received from ground station
 //make sure these match on the sending end
 #define DIR_TEST 0xAB
-#define DIR_PAYLOAD 0xACDIR_TEST
+#define DIR_PAYLOAD 0xAC

 #define PIN_TEST 13

@@ -29,14 +27,22 @@
 byte* buf_start = (byte*)malloc( MAX_BUF ); //allocate starting payload pointer
 byte* buf_curr; //current position of buffer

-//fake data
-typedef struct Payload {
-  long latitude; //42.4439;
-  long longitude;//-76.5018;
-  int altitude;//9999
-  byte flags;//0xF;
+typedef struct {
+  unsigned int gps_fix : 1;
+  unsigned int payload_abort : 1;
+  unsigned int test : 1;
+  unsigned int padding : 5;
+} Flags;
+
+typedef struct {
+  long latitude;
+  long longitude;
+  int altitude;
+  Flags flags;
 } Payload;

+
+Flags flags;
 Payload payload;
 Payload* ptr_payload = &payload;

@@ -105,9 +111,14 @@
     byte receivedPayload = Serial1.read();
     switch (receivedPayload) {
       case DIR_TEST:
-        if ( digitalRead(PIN_TEST) == HIGH )
+        if ( digitalRead(PIN_TEST) == LOW ) {
+          digitalWrite(PIN_TEST,HIGH);
+          payload.flags.test = 1;
+        }
+        else {
           digitalWrite(PIN_TEST,LOW);
-        else digitalWrite(PIN_TEST,HIGH);
+          payload.flags.test = 0;
+        }
         break;
       default:
         digitalWrite(PIN_TEST,LOW);


minor changes

minor changes

current sensor removed
initialization function improvements

--- arduino/medox/medox.ino
+++ arduino/medox/medox.ino
@@ -17,12 +17,11 @@
 #define    roPin4       11
 //other outputs
 #define    drawer       12
-#define    warehouse    13
+#define    warehouse    A1
 #define    pump         A0 //used as digital O/P as digital pins are all used
 //sensors
 #define    infrared     2  //interrupt pin
 #define    doorSwitch   3  //interrupt pin
-#define    current      A1
 #define    temperature  A2
 #define    lightLevel   A3
 //limits for initialization
@@ -34,8 +33,6 @@
 #define    upStepperDelay   3    //to wait before up/down steps
 #define    roStepperDelay   15   //to wait before rotation steps

-#define    currentThreeshold 5    //current where pump gets a bill
-#define    currentOffset     2    //offset for current sensor
 #define    maxUpSteps        650   //maximum number of steps pump should move 50 ----> 1 revolation
 #define    step72            10   //steps required to rotate 72 degrees

@@ -43,9 +40,9 @@
 #include <Servo.h>
 Servo drawerServo;// create servo object to control a servo
 Servo warehouseServo;// create servo object to control a servo
-#define drawerServoOpen     100
+#define drawerServoOpen     90
 #define drawerServoClose    0
-#define WarehouseServoOpen  100
+#define WarehouseServoOpen  90
 #define WarehouseServoClose 10

 //variables definition
@@ -83,7 +80,6 @@
   //inputs
   pinMode(  infrared,    INPUT);
   pinMode(  doorSwitch,  INPUT);
-  pinMode(  current,     INPUT);
   pinMode(  temperature, INPUT);
   pinMode(  lightLevel,  INPUT);
   //initialize Serial Communication to communicate with RPI, with Baud rate=9600
@@ -99,11 +95,11 @@
   pinMode(  trayLimit,  INPUT);
   pinMode(  upLimit,    INPUT);

-  //double check initial state
-  //initialization();
-  //initialization();
-  //initialization();
-  //initialization();
+  //initialization(); //initialize motors "moves them to initial position"
+  //open all doors for debugging
+  openDoor();
+  openWarehouse();
+  stopMotors();
 }

 //Check serial buffer for any strings from RPI and call Corresponding Function
@@ -145,34 +141,34 @@
   }
 }

+//initialize motors "moves them to initial position"
 void initialization(){
   int i = 0;
-  while(digitalRead(upLimit) != HIGH){//move up motor to initial place
-    digitalWrite(upPin1, seq[i][0]);
-    digitalWrite(upPin2, seq[i][1]);
-    digitalWrite(upPin3, seq[i][2]);
-    digitalWrite(upPin4, seq[i][3]);
-    delay(upStepperDelay);
-    i++;
-    if(i == 8)
-      i = 0;
-  }
-  stopMotors();
-  //delay(1000);
-
-  i=0;
-  while(digitalRead(trayLimit) != LOW){//move Tray motor to initial place
-    digitalWrite(roPin1, seq[i][0]);
-    digitalWrite(roPin2, seq[i][1]);
-    digitalWrite(roPin3, seq[i][2]);
-    digitalWrite(roPin4, seq[i][3]);
-    delay(roStepperDelay);
-    i++;
-    if(i == 8)
-      i = 0;
-  }
-
-  stopMotors();
+  for(int j = 0; j<4; j++){//double check
+    while(digitalRead(upLimit) != HIGH){//move up motor to initial place
+      digitalWrite(upPin1, seq[i][0]);
+      digitalWrite(upPin2, seq[i][1]);
+      digitalWrite(upPin3, seq[i][2]);
+      digitalWrite(upPin4, seq[i][3]);
+      delay(upStepperDelay);
+      i++;
+      if(i == 8)
+        i = 0;
+    }
+    stopMotors();
+    i=0;
+    while(digitalRead(trayLimit) != LOW){//move Tray motor to initial place
+      digitalWrite(roPin1, seq[i][0]);
+      digitalWrite(roPin2, seq[i][1]);
+      digitalWrite(roPin3, seq[i][2]);
+      digitalWrite(roPin4, seq[i][3]);
+      delay(roStepperDelay);
+      i++;
+      if(i == 8)
+        i = 0;
+    }
+    stopMotors();
+  }
 }

 void openDoor(){
@@ -216,15 +212,6 @@
   billCount = billCount + 1;
 }

-//Calculate the current pump using
-float getCurrent() {
-  tempFloat = analogRead(current); //read from motor current sensor pin
-  tempFloat = (tempFloat * 5) / 1024; //converting binary number to voltage (0-1024)->(0-5)
-  tempFloat = tempFloat - currentOffset; //subtracting sensor offset
-  tempFloat = tempFloat / 0.185; //mapping sensor output 'Voltage' to 'Ampere', 185mV/A
-  return tempFloat;
-}
-
 //dispenses given bill array
 //array is given via serial port from RPI
 void hardwareDispense(){
@@ -248,6 +235,7 @@
     }
   }
   stopMotors(); //stop all motors "set all pins to low"
+  initialization(); //re-initialize motors
   //check number of dispensed bills
   if(billCount == total)
     Serial.print("t");
@@ -285,7 +273,7 @@
 void getBill(){
   int steps = 0; //for storing steps to return to initial position again
   digitalWrite(pump, HIGH); //activates the pump
-  while(/*getCurrent() < currentThreeshold &&*/ steps < maxUpSteps){ //go down until gets one bill
+  while(steps < maxUpSteps){ //go down until gets one bill
     stepDown(); //move one step down
     steps++;
   }


adjsuting delay

adjsuting delay

--- frontdesk/module.wifi.ino
+++ frontdesk/module.wifi.ino
@@ -49,7 +49,8 @@
     cmd += getStr.length();

     WIFI.println(cmd);
-    delay(waitForGET);
+    //delay(waitForGET);
+    delay(500);

     WIFI.println(getStr);
     delay(waitForFlush);


Changes:

Changes:

* Remove error blinking
* Move backlight buttons support to functions
* Temporary backlight works "in background" (don't freeze the screen)

--- meteo_lcd/meteo_lcd.ino
+++ meteo_lcd/meteo_lcd.ino
@@ -654,7 +654,6 @@
     if (isnan(temp_in)) {
         // blink LED on error
         LOGLN("temp_in is NaN");
-        error_blink(1);
         temp_in = err_val; //ERR
     }
     else {
@@ -667,7 +666,6 @@
     if (isnan(temp_out)) {
         // blink LED on error
         LOGLN("temp_out is NaN");
-        error_blink(1);
         temp_out = err_val; //ERR
     }
     else {
@@ -680,7 +678,6 @@
     if(isnan(humid_in)) {
         // blink LED on error
         LOGLN("humid_in is NaN");
-        error_blink(1);
         humid_in = err_val; //ERR
     }
     else {
@@ -693,7 +690,6 @@
     if(isnan(humid_out)) {
         // blink LED on error
         LOGLN("humid_out is NaN");
-        error_blink(1);
         humid_out = err_val; //ERR
     }
     else {
@@ -704,6 +700,40 @@
     // ##### Pressure #####
     // Nothing to do here
     LOG("Pressure: "); LOGLN(pressure);
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+//                BACKLIGHT BUTTONS
+
+void backlight_buttons()
+{
+    static byte off_time;
+    static bool should_off;
+
+    // This may cause that we miss off_time and the backlight will stay on.
+    // This may happend beause of some "lag" from sensors, or user witl use
+    // DOWN+UP+OK buttons to set time;
+    // Anyway it's not a big issue. Backlight will be off eventually.
+    // User can always turn it off manually by pushing DOWN button.
+    if (should_off && off_time == rtc.getSecond()) {
+        lcd.noBacklight();
+        should_off = false;
+    }
+
+    if (was_button_pressed(BUTTON_UP)) {
+        lcd.backlight();
+	return;
+    }
+    if (was_button_pressed(BUTTON_DOWN)) {
+        lcd.noBacklight();
+	return;
+    }
+    else if (was_button_pressed(BUTTON_OK)) {
+        lcd.backlight();
+        off_time = (rtc.getSecond() + 4) % 60;
+        should_off = true;
+    }
 }

@@ -747,7 +777,7 @@
     lcd.setCursor(7, 2);
     lcd.print("wersja D_0.2");

-    // Sleep for setup dht sensors
+    // Sleep for setup dht sensors - just in case. This also gives you time to read te welcome screen.
     delay(4000);

     // Temperature and humidity sensor
@@ -757,12 +787,10 @@
     // Pressure sensor
     if (!bmp.begin(3)) { // init pressure sensor with high precission param - 3
         LOGLN("Cannot initalize BMP (pressure) sensor");
-        error_blink(5);
         digitalWrite(DEBUG_LED, HIGH); // if error turn debug LED on
-        delay(5000);
-        digitalWrite(DEBUG_LED, LOW);
-    }
-
+    }
+
+    // Draw template - Labels and units.
     draw_template();
     LOGLN("Setup end");
 }
@@ -777,17 +805,8 @@
     if (enter_time_setup())
         time_setup(3 /* 4th row */);

-    if (was_button_pressed(BUTTON_UP)) {
-        lcd.backlight();
-    }
-    else if (was_button_pressed(BUTTON_DOWN)) {
-        lcd.noBacklight();
-    }
-    else if (was_button_pressed(BUTTON_OK)) {
-        lcd.backlight();
-	delay(4000);
-        lcd.noBacklight();
-    }
+    // Support backlight buttons
+    backlight_buttons();

     // Update meteo data
     float temp_in, humid_in, temp_out, humid_out;


Initial implementation using nRF24L01+

Initial implementation using nRF24L01+

Don’t have an Arduino on hand, so this code is completely untested.

--- receiver/receiver.ino
+++ receiver/receiver.ino
@@ -4,83 +4,180 @@
  */

 #include "Arduino.h"
-
-#define HEADER_LENGTH       4
-#define DATA_LENGTH         3
-#define CHECKSUM_LENGTH     1
-#define PACKET_LENGTH       (HEADER_LENGTH + DATA_LENGTH + CHECKSUM_LENGTH)
-
-#define HEADER_INDEX        0
-#define DATA_INDEX          (HEADER_LENGTH)
-#define CHECKSUM_INDEX      (HEADER_LENGTH + DATA_LENGTH)
+#include <RF24.h>
+#include <SPI.h>
+#include <EEPROM.h>
+

 //RGB pins
 #define RED_PIN             9
 #define GREEN_PIN           10
 #define BLUE_PIN            11

-const uint8_t validHeader[HEADER_LENGTH] = {'S','I','G','M'};
-uint8_t myChannel = 0xFF; //The address of the current light, set by DIP switch
-
+//Radio pins
+#define CE_PIN              2 //Radio chip enable pin
+#define CSN_PIN             3 //Radio chip select pin
+
+//Wireless protocol
+#define NODE_RF_ADDRESS         ((uint64_t)'SIGMUSIC')
+#define HEADER                  7446
+#define BASE_STATION_ID         0x00
+
+enum COMMANDS {
+    CMD_SET_RGB       = 0x10,
+    CMD_BROADCAST_RGB = 0x11,
+    CMD_PING          = 0x20,
+    CMD_PING_RESPONSE = 0x21,
+};
+
+//Serial protocol
+#define MAX_SERIAL_LINE_LEN 20
+
+
+#define VERSION                 0 //The firmware version number
+#define ENDPOINT_ID_LOCATION    0x00 //The address in EEPROM to store the ID
+
+
+typedef struct packet_tag {
+    uint16_t header;
+    uint8_t command;
+    uint8_t endpoint;
+    uint8_t rgb[3];
+} packet_t;
+
+
+void networkRead(void);
+void processPacket(packet_t packet);
+void serialRead(void);
+void processCommand(char message[]);
+void setRGB(uint8_t red, uint8_t green, uint8_t blue);
+void setEndpointID(uint8_t id);
+void welcomeMessage(void);
+void helpMessage(void);
+
+
+RF24 radio(CE_PIN, CSN_PIN);
+
+uint8_t endpointID = EEPROM.read(ENDPOINT_ID_LOCATION);
+
+uint8_t lastPingEndpoint;
+unsigned long lastPingTime;
+
+/**
+ * Initialize SPI, radio, and serial.
+ */
 void setup() {
-    Serial.begin(19200); //sends data at 19200 bits per second
-    Serial.println("Ready");
-}
-
+    SPI.begin();
+    SPI.setBitOrder(MSBFIRST);
+    SPI.setClockDivider(16); // Set SPI clock to 16 MHz / 16 = 1 MHz
+
+    // nRF24L01+ radio initialization
+    radio.begin();
+    radio.setDataRate(RF24_250KBPS);
+    radio.setChannel(80); // Channel center frequency = 2.4005 GHz + (Channel# * 1 MHz)
+    radio.setPALevel(RF24_PA_MAX);
+    radio.setRetries(0, 0);
+    radio.setAutoAck(false);
+    radio.setCRCLength(RF24_CRC_8);
+    radio.setPayloadSize(sizeof(packet_t));
+    radio.openReadingPipe(0, NODE_RF_ADDRESS);
+    radio.startListening();
+
+    Serial.begin(9600);
+    welcomeMessage();
+}
+
+/**
+ * Continuously read in data from the network and from serial.
+ */
 void loop() {
-    static int currentIndex = 0; //The packet index of the data we've received
-    static uint8_t tempRGB[DATA_LENGTH] = {0};
-
-    //Wait for incoming data
+    networkRead();
+    serialRead();
+}
+
+/**
+ * Reads network data into a struct and sends it to be processed.
+ */
+void networkRead(void) {
+    if (radio.available()) {
+        packet_t packet;
+        radio.read(&packet, sizeof(packet_t));
+        processPacket(packet);
+    }
+}
+
+/**
+ * Takes action on a packet received over the network.
+ * @param packet The packet received
+ */
+void processPacket(packet_t packet) {
+    if (packet.header != HEADER) {
+        //Invalid packet
+        return;
+    }
+
+    if ((packet.command == CMD_SET_RGB && packet.endpoint == endpointID) ||
+        packet.command == CMD_BROADCAST_RGB) {
+
+        setRGB(packet.rgb[0], packet.rgb[1], packet.rgb[2]);
+    } else if (packet.command == CMD_PING && packet.endpoint == endpointID) {
+        //Received a ping request. Respond with the endpoint ID and version.
+        packet_t response = {
+            HEADER,
+            CMD_PING_RESPONSE,
+            BASE_STATION_ID,
+            {endpointID, VERSION, 0}
+        };
+
+        radio.stopListening();
+        radio.openWritingPipe(NODE_RF_ADDRESS);
+        radio.write(&response, sizeof(response));
+        radio.openReadingPipe(0, NODE_RF_ADDRESS);
+    } else {
+        //Ignore packet
+    }
+}
+
+/**
+ * Reads serial data into a buffer. When a carriage return is encountered,
+ * the message is sent to be processed.
+ */
+void serialRead(void) {
+    static char buffer[MAX_SERIAL_LINE_LEN + 1];
+    static int index = 0;
+
     if (Serial.available()) {
-        uint8_t receivedByte = Serial.read();
-
-        if (currentIndex < HEADER_LENGTH) {
-            //We haven't yet received a valid header
-            if (receivedByte == validHeader[currentIndex]) {
-                //The received byte matches the header. Move to the next index.
-                currentIndex++;
-            } else {
-                //The received byte doesn't match. Restart the state machine.
-                currentIndex = 0;
-                Serial.println("ERR");
-            }
+
+        buffer[index] = Serial.read();
+
+        if (buffer[index] == '\r' ||  index == MAX_SERIAL_LINE_LEN) {
+            buffer[index] = '\0'; //Terminate the message
+            index = 0; //Reset to the beginning of the buffer
+            processCommand(buffer);
         } else {
-            //We have received a valid header
-             if (currentIndex < CHECKSUM_INDEX) {
-                //Store the temporary RGB values until we validate the checksum
-                tempRGB[currentIndex - DATA_INDEX] = receivedByte;
-                currentIndex++;
-             } else {
-                //Validate the checksum
-                if (calculateChecksum(tempRGB) == receivedByte) {
-                    /* It's valid. Set the new RGB values and restart the state
-                     * machine.
-                     */
-                    setRGB(tempRGB[0], tempRGB[1], tempRGB[2]);
-                    currentIndex = 0;
-                    Serial.println("OK");
-                } else {
-                    //The checksum is invalid. Restart the state machine.
-                    currentIndex = 0;
-                    Serial.println("ERR");
-                }
-             }
+            index++;
         }
     }
 }

 /**
- * Calculates the expected checksum of a received packet.
- * @param data The received data (RGB only)
- * @return The 8-bit checksum of the data
- */
-uint8_t calculateChecksum(uint8_t data[]) {
-    uint8_t checksum = 0;
-    for (int i = 0; i < DATA_LENGTH; i++) {
-        checksum += data[i]; //Relies on 8-bit integer overflow
-    }
-    return checksum;
+ * Takes action on a command received over serial.
+ * @param message The message received
+ */
+void processCommand(char message[]) {
+    uint8_t id;
+    if (!strcmp(message, "help")) {
+        helpMessage();
+    } else if (!strcmp(message, "version")) {
+        Serial.println(VERSION);
+    } else if (!strcmp(message, "getid")) {
+        Serial.println(endpointID, HEX);
+    } else if (sscanf(message, "setid %2x", &id) == 1) {
+        setEndpointID(id);
+        Serial.println("OK");
+    } else {
+        Serial.println("Error: unrecognized command");
+    }
 }

 /**
@@ -93,4 +190,40 @@
     analogWrite(RED_PIN, red);
     analogWrite(GREEN_PIN, green);
     analogWrite(BLUE_PIN, blue);
-}+}
+
+/**
+ * Sets the value of the endpoint ID in EEPROM.
+ * @param id The new endpoint ID
+ */
+void setEndpointID(uint8_t id) {
+    EEPROM.write(ENDPOINT_ID_LOCATION, id);
+    endpointID = id;
+}
+
+/**
+ * Prints the welcome message for serial debugging.
+ */
+void welcomeMessage(void) {
+    Serial.println(F("-------------------------------------"));
+    Serial.println(F("SIGMusic@UIUC Lights Serial Interface"));
+    Serial.print(F("Version "));
+    Serial.println(VERSION);
+    Serial.print(F("This light is endpoint 0x"));
+    Serial.println(endpointID, HEX);
+    Serial.println(F("End all commands with a carriage return."));
+    Serial.println(F("Type 'help' for a list of commands."));
+    Serial.println(F("-------------------------------------"));
+}
+
+/**
+ * Prints the help message for serial debugging.
+ */
+void helpMessage(void) {
+    Serial.println(F("Available commands:"));
+    Serial.println(F("  help - displays this help message"));
+    Serial.println(F("  version - displays the firmware version number"));
+    Serial.println(F("  setid [id] - sets the endpoint ID"));
+    Serial.println(F("      [id] - the new ID (in hexadecimal)"));
+    Serial.println(F("  getid - displays the endpoint ID"));
+}


Now getting setup from web service, night light disabled for now as it conflicts with the json library.

--- clock/clock.ino
+++ clock/clock.ino
@@ -13,6 +13,12 @@
 - http://anaismoisy.com/essay-cardican-clock/

 *************************************************************/
+//for the LEDs
+//#include <Wire.h>
+//#include <Adafruit_NeoPixel.h>
+//#define NEOPIN 6  // define pins
+//#define BRIGHTNESS 64 // set max brightness
+//Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, NEOPIN, NEO_GRB + NEO_KHZ800); // strip object

 #include <Bridge.h>
 #include <HttpClient.h>
@@ -22,34 +28,24 @@
 #define MAX_JSON_STR 500
 char jsonStr[MAX_JSON_STR];
 const int BUFFER_SIZE = 500;
-int steps_day = 206;    //tricks to get a full 360 degree (I don't know why it is not doing it in 200 steps)
-int steps_night = 406;
+int steps_day = 206; //tricks to get a full 360 degree (I don't know why it is not doing it in 200 steps)
+int steps_night = 406;
 String lat("55.9531");
 String lon("-3.1889");

-
-
-int delaylegnth_speed = 20;  //speed to go to the correct 'time' when it is launched
-
+int delaylegnth_speed = 50;  //speed to go to the correct 'time' when it is launched
 int i=0;
 unsigned long start_time;
-unsigned long daySteps;
-unsigned long nightSteps;
-unsigned long stepsToInit;
-
-//for the LEDs
-#include <Wire.h>
-#include <Adafruit_NeoPixel.h>
-#define NEOPIN 6  // define pins
-#define BRIGHTNESS 64 // set max brightness
-Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, NEOPIN, NEO_GRB + NEO_KHZ800); // strip object
-
-
-
-
+int steps_current_time;

 void setup() {
+  pinMode(13, OUTPUT);
+  digitalWrite(13, LOW);
+  Bridge.begin();
+  Serial.begin(9600);
+  //while(!Serial);
+

   //establish motor direction toggle pins
   pinMode(12, OUTPUT); //CH A -- HIGH = forwards and LOW = backwards???
@@ -65,25 +61,16 @@
   Serial.println("Setup complete");

   //setup LEDs
-  Wire.begin();        	// Begin I2C
-  pinMode(NEOPIN, OUTPUT);
-  strip.begin();
-  strip.setBrightness(BRIGHTNESS); // set brightness
-  delay(500);
-  colorWipe(strip.Color(0, 0, 0), 1); // Red
-  delay(500);
-
-  digitalWrite(13, LOW);
-  Bridge.begin();
-  Serial.begin(9600);
-  while(!Serial);
-
-}
-
-
-
-void loop(){
-
+  //Wire.begin();        	// Begin I2C
+  //pinMode(NEOPIN, OUTPUT);
+  //strip.begin();
+  //strip.setBrightness(BRIGHTNESS); // set brightness
+  //delay(500);
+  //colorWipe(strip.Color(0, 0, 0), 1); // Red
+  //delay(500);
+}
+
+void loop() {
   // Get the sunrise and sunset times
   uint32_t daySteps = 0;
   uint32_t nightSteps = 0;
@@ -106,9 +93,10 @@
   Serial.println("Setup complete");

-  delay(5000);
-
-  //make needle turn fast to the right time
+  delay(2000);
+
+  steps_current_time = stepsToInit;
+    //make needle turn fast to the right time
   while(i < stepsToInit){

     step1(delaylegnth_speed);
@@ -118,18 +106,15 @@
   }

   Serial.println("Time was initialized");
-  Serial.println("I is: " + String(i));
-
+  //Serial.println("I is: " + String(i));

   start_time = millis();
-  Serial.println("HEEEERREEE startime: ");
   Serial.println(String(start_time));
-  Serial.println(String(millis()));
-
-  //set the new step limit for day
-  stepsToInit = steps_day;
-
-  //make needle turn right speed until sunset day
+
+  //set the new step limit for day 1
+  steps_current_time = steps_day;
+
+  //make needle turn right speed until sunset day1
   while(i < steps_day){

       step1(1);
@@ -145,15 +130,16 @@
       waitTime(daySteps);
   }

+
   Serial.println("I is: " + String(i));
   Serial.println("Day 1 is over!");
-  stepsToInit = steps_night;
-
-  if (i==steps_day){
-  delay(5);
-  colorWipe(strip.Color(255, 255, 255), 1); // Red
-  delay(5);
-  }
+  steps_current_time = steps_night;
+
+  //if (i==steps_day1){
+  //delay(5);
+  //colorWipe(strip.Color(255, 255, 255), 1); // Red
+  //delay(5);
+  //}

   //make needle turn right speed until sunrise day2
   while(i < steps_night){
@@ -171,23 +157,78 @@
       waitTime(nightSteps);
   }

-  if (i==steps_night){
-  delay(5);
-  colorWipe(strip.Color(0, 0, 0), 1); // Red
-  delay(5);
-  }
-
-}
-
-
-//delay between steps for day1
+  //if (i==steps_night){
+  //delay(5);
+  //colorWipe(strip.Color(0, 0, 0), 1); // Red
+  //delay(5);
+  //}
+
+
+  i = 0;
+}
+
+// Get the sunrise and sunset times from openweather.org
+boolean getSunRiseSet(String lat, String lon, uint32_t &daySteps, uint32_t &nightSteps, uint32_t &stepsToInit)
+{
+  // Connect to server
+  HttpClient client;
+
+  // Create a HTTP request:
+  String url = "http://anaismoisy.com/apps/clock/api.php?lat=" + lat + "&lng=" + lon + "&steps=" + steps_day;
+  Serial.println("Getting " + url);
+
+  client.get(url);
+
+  // if there are incoming bytes available
+  // from the server, read them and print them:
+
+  // Get the JSON data
+  int j = 0;
+  while (client.available())
+  {
+    char c = client.read();
+    jsonStr[j++] = c;
+    Serial.print(c);
+
+  }
+  jsonStr[j++] += '\0';
+
+  int i = 0;
+  while(jsonStr[i])
+  {
+    Serial.print(jsonStr[i++]);
+  }
+  Serial.print("\0");
+
+  // Parse the JSON data
+  StaticJsonBuffer<BUFFER_SIZE> jsonBuffer;
+  JsonObject& root = jsonBuffer.parseObject(jsonStr);
+
+  if (!root.success())
+  {
+    Serial.println("parseObject() failed");
+    return false;
+  }
+
+  daySteps = root["daySteps"];
+  nightSteps = root["nightSteps"];
+  stepsToInit = root["stepsToInit"];
+
+  daySteps = daySteps;
+  nightSteps = nightSteps;
+
+  // Success
+  return true;
+}
+
+//delay between steps
 boolean waitTime(unsigned long time)
 {

-  Serial.println("time day one is being called:");
-  Serial.println(start_time);
-  Serial.println("Starttime + delay_day is:");
-  Serial.println(start_time + daySteps);
+  //Serial.println("time day one is being called:");
+  //Serial.println(start_time);
+  //Serial.println("Starttime + delay_day_1 is:");
+  //Serial.println(start_time + daySteps);
   while ((start_time + time) > millis())
   {
     delay(5);
@@ -198,12 +239,10 @@
     start_time = millis();
     return true;
 }
-
-

 void step1(int delayMilliseconds)
 {
- if (i < stepsToInit)
+ if (i < steps_current_time)
     {
     digitalWrite(9, LOW);  //ENABLE CH A
     digitalWrite(8, HIGH); //DISABLE CH B
@@ -219,7 +258,7 @@

 void step2(int delayMilliseconds)
 {
-  if (i < stepsToInit)
+  if (i < steps_current_time)
     {
     digitalWrite(9, HIGH);  //DISABLE CH A
     digitalWrite(8, LOW); //ENABLE CH B
@@ -235,7 +274,7 @@

 void step3(int delayMilliseconds)
 {
-  if (i < stepsToInit)
+  if (i < steps_current_time)
     {
     digitalWrite(9, LOW);  //ENABLE CH A
     digitalWrite(8, HIGH); //DISABLE CH B
@@ -251,7 +290,7 @@

 void step4(int delayMilliseconds)
 {
-  if (i < stepsToInit)
+  if (i < steps_current_time)
     {
     digitalWrite(9, HIGH);  //DISABLE CH A
     digitalWrite(8, LOW); //ENABLE CH B
@@ -266,61 +305,10 @@
 }

 // Fill the dots one after the other with a color
-void colorWipe(uint32_t c, uint8_t wait) {
-  for(uint16_t i=0; i<strip.numPixels(); i++) {
-	strip.setPixelColor(i, c);
-	strip.show();
-	delay(wait);
-  }
-}
-
-// Get the sunrise and sunset times from openweather.org
-boolean getSunRiseSet(String lat, String lon, uint32_t &daySteps, uint32_t &nightSteps, uint32_t &stepsToInit)
-{
-  // Connect to server
-  HttpClient client;
-
-  // Create a HTTP request:
-  String url = "http://anaismoisy.com/apps/clock/api.php?lat=" + lat + "&lng=" + lon + "&steps=" + steps_day;
-  Serial.println("Getting " + url);
-
-  client.get(url);
-
-  // if there are incoming bytes available
-  // from the server, read them and print them:
-
-  // Get the JSON data
-  int j = 0;
-  while (client.available())
-  {
-    char c = client.read();
-    jsonStr[j++] = c;
-    Serial.print(c);
-
-  }
-  jsonStr[j++] += '\0';
-
-  int i = 0;
-  while(jsonStr[i])
-  {
-    Serial.print(jsonStr[i++]);
-  }
-  Serial.print("\0");
-
-  // Parse the JSON data
-  StaticJsonBuffer<BUFFER_SIZE> jsonBuffer;
-  JsonObject& root = jsonBuffer.parseObject(jsonStr);
-
-  if (!root.success())
-  {
-    Serial.println("parseObject() failed");
-    return false;
-  }
-
-  daySteps = root["daySteps"];
-  nightSteps = root["nightSteps"];
-  stepsToInit = root["stepsToInit"];
-
-  // Success
-  return true;
-}
+//void colorWipe(uint32_t c, uint8_t wait) {
+//  for(uint16_t i=0; i<strip.numPixels(); i++) {
+//	strip.setPixelColor(i, c);
+//	strip.show();
+//	delay(wait);
+//  }
+//}


modified:   ESP8266HueEmulator/ESP8266HueEmulator.ino

--- ESP8266HueEmulator/ESP8266HueEmulator.ino
+++ ESP8266HueEmulator/ESP8266HueEmulator.ino
@@ -1,6 +1,6 @@
 /**
  * Emulate Philips Hue Bridge ; so far the Hue app finds the emulated Bridge and gets its config
- * and switch NeoPixels with it
+ * and switch NeoPixels with it
  **/

 // TODO: Change SSDP to get rid of local copies of ESP8266SSDP use the new scheme from the Arduino IDE instead
@@ -58,6 +58,7 @@
   // From https://github.com/pubnub/msp430f5529/blob/master/msp430f5529.ino
   char *msgStr = aJson.print(root);
   aJson.deleteItem(root);
+  Serial.println(millis());
   Serial.println(msgStr);
   HTTP.send(200, "text/plain", msgStr);
   free(msgStr);
@@ -65,6 +66,7 @@

 void handleAllOthers() {
   Serial.println("===");
+  Serial.println(millis());
   String requestedUri = HTTP.uri();
   Serial.print("requestedUri: ");
   Serial.println(requestedUri);
@@ -134,11 +136,12 @@
     // If multiple ones are submitted at once, the following convention is used: xy beats ct beats hue/sat
     // TODO: Implement this

-    // Default values in case the request does not send new ones; TODO: Read from pixel instead!
-    int hue = 1;
-    int sat = 1;
+    // Default values in case the request does not send new ones
+    int hue = 0;
+    int sat = 255;
     int bri = 255;

+    // Read hue, sat, bri from pixel if available
     if (aJsonObject* hueState = aJson.getObjectItem(parsedRoot, "hue"))
       hue = hueState->valueint;
     if (aJsonObject* satState = aJson.getObjectItem(parsedRoot, "sat"))
@@ -154,7 +157,7 @@
     Serial.println(onValue);

     // define the effect to apply, in this case linear blend
-    HslColor originalColor = strip.GetPixelColor(numberOfTheLight);
+    HslColor originalColor = strip.GetPixelColor(numberOfTheLight); // FIXME: In lambda function: error: 'originalColor' was not declared in this scope - potential reason for crashes?
     if (onValue == true)
     {
       AnimUpdateCallback animUpdate = [ = ](float progress)
@@ -178,7 +181,7 @@

     aJsonObject *root;
     root = aJson.createObject();
-    addLightJson(root, numberOfTheLight);
+    addLightJson(root, numberOfTheLight+1, rgb); // FIXME: This does not give the new color while an animation is still running
     sendJson(root);
   }

@@ -200,6 +203,7 @@
     for (uint8_t i = 0; i < HTTP.args(); i++) Serial.printf("ARG[%u]: %s=%s\n", i, HTTP.argName(i).c_str(), HTTP.arg(i).c_str());

   }
+  Serial.println(millis());
 }

 void setup() {
@@ -227,7 +231,7 @@
   ipString = StringIPaddress(WiFi.localIP());
   netmaskString = StringIPaddress(WiFi.subnetMask());
   gatewayString = StringIPaddress(WiFi.gatewayIP());
-
+
   Serial.print("Starting HTTP at ");
   Serial.print(WiFi.localIP());
   Serial.print(":");
@@ -343,40 +347,39 @@
   aJson.addStringToObject(swupdate, "url", "");
 }

-void addLightJson(aJsonObject* root, int numberOfTheLight)
+void addLightJson(aJsonObject* root, int numberOfTheLight, RgbColor rgb)
 {
   String lightName = "" + (String) numberOfTheLight;
   aJsonObject *light;
   aJson.addItemToObject(root, lightName.c_str(), light = aJson.createObject());
-  aJson.addStringToObject(light, "type", "Extended color light");
-  aJson.addStringToObject(light, "name",  ("Hue LightStrips " + (String) numberOfTheLight).c_str());
-  aJson.addStringToObject(light, "modelid", "LST001");
+  aJson.addStringToObject(light, "type", "Extended color light"); // type of lamp (all "Extended colour light" for now)
+  aJson.addStringToObject(light, "name",  ("Hue LightStrips " + (String) numberOfTheLight).c_str()); // // the name as set through the web UI or app
+  aJson.addStringToObject(light, "modelid", "LST001"); // the model number
   aJsonObject *state;
   aJson.addItemToObject(light, "state", state = aJson.createObject());
-  unsigned int brightness = strip.GetPixelColor(numberOfTheLight - 1).CalculateBrightness();
+  unsigned int brightness = rgb.CalculateBrightness();
   if (brightness == 0)
-  {
     aJson.addBooleanToObject(state, "on", false);
-  }
   else
-  {
     aJson.addBooleanToObject(state, "on", true);
-  }
-
-
+  HsbColor hsb = rgb2hsb(rgb);
+  aJson.addNumberToObject(state, "bri", hsb.bri); // brightness between 0-254 (NB 0 is not off!)
+  aJson.addNumberToObject(state, "hue", hsb.hue); // hs mode: the hue (expressed in ~deg*182.04)
+  aJson.addNumberToObject(state, "sat", hsb.sat); // hs mode: saturation between 0-254
+  double numbers[2] = {0.0, 0.0};
+  aJson.addItemToObject(state, "xy", aJson.createFloatArray(numbers, 2)); // xy mode: CIE 1931 color co-ordinates
+  aJson.addNumberToObject(state, "ct", 500); // ct mode: color temp (expressed in mireds range 154-500)
+  aJson.addStringToObject(state, "alert", "none"); // 'select' flash the lamp once, 'lselect' repeat flash for 30s
+  aJson.addStringToObject(state, "effect", "none"); // 'colorloop' makes Hue cycle through colors
+  aJson.addStringToObject(state, "colormode", "hs"); // the current color mode
+  aJson.addBooleanToObject(state, "reachable", true); // lamp can be seen by the hub
+}
+
+
+void addLightJson(aJsonObject* root, int numberOfTheLight)
+{
   RgbColor rgb = strip.GetPixelColor(numberOfTheLight - 1);
-  HsbColor hsb = rgb2hsb(rgb);
-
-  aJson.addNumberToObject(state, "bri", hsb.bri); // Should be 1-254 according to Philips API
-  aJson.addNumberToObject(state, "hue", hsb.hue); // Should between 0 and 65535. Both 0 and 65535 are red, 25500 is green and 46920 is blue
-  aJson.addNumberToObject(state, "sat", hsb.sat);
-  double numbers[2] = {0.0, 0.0};
-  aJson.addItemToObject(state, "xy", aJson.createFloatArray(numbers, 2));
-  aJson.addStringToObject(state, "alert", "none");
-  aJson.addStringToObject(state, "effect", "none");
-  aJson.addStringToObject(state, "colormode", "hs");
-  aJson.addBooleanToObject(state, "reachable", true);
-
+  addLightJson(root, numberOfTheLight, rgb);
 }

 // ==============================================================================================================
@@ -414,31 +417,26 @@
   normalizedToOneBlue = (color.B / 255);

   float red, green, blue;
-
-  // Make red more vivid
-  if (normalizedToOneRed > 0.04045) {
-    red = (float) pow(
-            (normalizedToOneRed + 0.055) / (1.0 + 0.055), 2.4);
-  } else {
-    red = (float) (normalizedToOneRed / 12.92);
-  }
-
-  // Make green more vivid
-  if (normalizedToOneGreen > 0.04045) {
-    green = (float) pow((normalizedToOneGreen + 0.055)
-                        / (1.0 + 0.055), 2.4);
-  } else {
-    green = (float) (normalizedToOneGreen / 12.92);
-  }
-
-  // Make blue more vivid
-  if (normalizedToOneBlue > 0.04045) {
-    blue = (float) pow((normalizedToOneBlue + 0.055)
-                       / (1.0 + 0.055), 2.4);
-  } else {
-    blue = (float) (normalizedToOneBlue / 12.92);
-  }
-
+ /*
+    // Make red more vivid
+    if (normalizedToOneRed > 0.04045)
+      red = (float) pow((normalizedToOneRed + 0.055) / (1.0 + 0.055), 2.4);
+    else
+      red = (float) (normalizedToOneRed / 12.92);
+
+    // Make green more vivid
+    if (normalizedToOneGreen > 0.04045)
+      green = (float) pow((normalizedToOneGreen + 0.055) / (1.0 + 0.055), 2.4);
+    else
+      green = (float) (normalizedToOneGreen / 12.92);
+
+    // Make blue more vivid
+    if (normalizedToOneBlue > 0.04045)
+      blue = (float) pow((normalizedToOneBlue + 0.055) / (1.0 + 0.055), 2.4);
+    else
+      blue = (float) (normalizedToOneBlue / 12.92);
+*/
+
   float X = (float) (red * 0.649926 + green * 0.103455 + blue * 0.197109);
   float Y = (float) (red * 0.234327 + green * 0.743075 + blue * 0.022598);
   float Z = (float) (red * 0.0000000 + green * 0.053077 + blue * 1.035763);
@@ -469,37 +467,23 @@

 struct HsbColor rgb2hsb(RgbColor color)
 {
-
+  Serial.println("Running rgb2hsb");
   struct HsbColor hsb_instance;
   int hue, sat, bri;
-
+
+  Serial.println("1.: H, S, L - this seems correct");
   HslColor hsl = HslColor(color);
-  //  Serial.print("H = ");
-  //  Serial.println(hsl.H);
-  //  Serial.print("S = ");
-  //  Serial.println(hsl.S);
-  //  Serial.print("L = ");
-  //  Serial.println(hsl.L);
-
+  Serial.print("H = ");
+  Serial.println(hsl.H);
+  Serial.print("S = ");
+  Serial.println(hsl.S);
+  Serial.print("L = ");
+  Serial.println(hsl.L);
+
+  Serial.println("2.: Convert to hue, sat, bri");
   hue = floor(hsl.H * 65535);
   sat = floor(hsl.S * 255);
   bri = floor(hsl.L * 2.55);
-  //  Serial.print("hue = ");
-  //  Serial.println(hue);
-  //  Serial.print("sat = ");
-  //  Serial.println(sat);
-  //  Serial.print("bri = ");
-  //  Serial.println(bri);
-
-  hsb_instance.hue = hue;
-  hsb_instance.sat = sat;
-  hsb_instance.bri = bri;
-
-  return (hsb_instance);
-}
-
-RgbColor hsb2rgb(int hue, int sat, int bri)
-{
   Serial.print("hue = ");
   Serial.println(hue);
   Serial.print("sat = ");
@@ -507,7 +491,26 @@
   Serial.print("bri = ");
   Serial.println(bri);

-  double H, S, L;
+  hsb_instance.hue = hue;
+  hsb_instance.sat = sat;
+  hsb_instance.bri = bri;
+
+  return (hsb_instance);
+}
+
+RgbColor hsb2rgb(int hue, int sat, int bri)
+{
+  Serial.println("Running hsb2rgb");
+  Serial.println("1.: hue, sat, bri");
+  Serial.print("hue = ");
+  Serial.println(hue);
+  Serial.print("sat = ");
+  Serial.println(sat);
+  Serial.print("bri = ");
+  Serial.println(bri);
+
+  Serial.println("2.: Convert to H, S, L");
+  float H, S, L;
   H = hue / 65535.0;
   Serial.print("H = ");
   Serial.println(H);
@@ -519,6 +522,7 @@
   Serial.println(L);
   HslColor hsl = HslColor(H, S, L);

+  Serial.println("3.: Convert to RgbColor - I think here is where things go wrong");
   RgbColor rgb = RgbColor(hsl);
   Serial.print("R = ");
   Serial.println(rgb.R);
@@ -526,7 +530,6 @@
   Serial.println(rgb.G);
   Serial.print("B = ");
   Serial.println(rgb.B);
-  Serial.println("FIXME: Hue is a bit off - why?");

   return rgb;
 }


increase delay

increase delay

--- interduino/src/sketch.ino
+++ interduino/src/sketch.ino
@@ -20,7 +20,7 @@
 		if(ledState == 90){
 			digitalWrite(13, LOW);
 		}
-	delay(500);
+	delay(2000);
 	}
 }


new function for converting to human time

--- sms_thermo/sms_thermo.ino
+++ sms_thermo/sms_thermo.ino
@@ -63,6 +63,7 @@
   {
     startOfPeriod[i] = now ();
     measuresPerPeriod[i] = monPeriodLen[i] / (cycleDelay / 1000);
+    tempAvgPrev[0][i] = sensors.getTempC(thermalSensor[i]);
   }

@@ -449,6 +450,7 @@
 int makeForecast(int sensor, bool debug)
 {
   float forecastSeconds ;
+  float forecastMinutes ;
   float delta_temp;
   float cur_temp = sensors.getTempC(thermalSensor[sensor]);

@@ -456,28 +458,29 @@

   if (tempTrend[0][sensor] < 0 )
   { //recovery time calculation
-    delta_temp = tempAvgCur[0][sensor] - TargetTemp[sensor];
+    delta_temp = cur_temp - TargetTemp[sensor];
     //Serial.print("[mF] Trend < 0. delta_temp:"); Serial.println(delta_temp);

   }

   if (tempTrend[0][sensor] > 0 )
-  { //Destroy time calculation
-    delta_temp = DestroyAlarmTemp[sensor] - tempAvgCur[0][sensor];
+  {
+     delta_temp = DestroyAlarmTemp[sensor] - cur_temp;
     // Serial.print("[mF] Trend > 0. delta_temp:"); Serial.println(delta_temp);
   }

   forecastSeconds = delta_temp / (tempTrend[0][sensor] / monPeriodLen[0]);
+  forecastMinutes = forecastSeconds / 60;
   //Serial.print(delta_temp); Serial.print("/"); Serial.print(tt1mTrend[deviceid]); Serial.print("="); Serial.println(forecastSeconds);
   if (debug)
   {
-    Serial.print("[DBG] "); Serial.print(int(round(forecastSeconds))); Serial.print("(sec) till ");
+    Serial.print("[DBG] "); Serial.print(timeToHuman(forecastSeconds)); Serial.print(" till ");
+    if (tempTrend[0][sensor] < 0 )
+    {
+      Serial.println(TargetTemp[sensor]);
+    }
+    else {
     if (tempTrend[0][sensor] > 0 )
-    {
-      Serial.println(TargetTemp[sensor]);
-    }
-    else {
-    if (tempTrend[0][sensor] < 0 )
     {
       Serial.println(DestroyAlarmTemp[sensor]);
     }
@@ -491,6 +494,38 @@

 }

+String timeToHuman (unsigned long inttime)
+{
+
+   unsigned long hours, mins, secs;
+   String timeString;
+
+
+   // Now, inttime is the remainder after subtracting the number of seconds
+   // in the number of days
+   hours    = inttime / 3600;
+   inttime  = inttime % 3600;
+
+   // Now, inttime is the remainder after subtracting the number of seconds
+   // in the number of days and hours
+   mins     = inttime / 60;
+   inttime  = inttime % 60;
+
+   // Now inttime is the number of seconds left after subtracting the number
+   // in the number of days, hours and minutes. In other words, it is the
+   // number of seconds.
+   secs = inttime;
+
+   // Don't bother to print days
+
+   timeString =  String(hours);
+   timeString = timeString + String(":");
+   timeString = timeString + String(mins);
+   timeString = timeString + String(".");
+   timeString = timeString + String(secs);
+   return timeString;
+
+}

 // proceed a call just for make a loud sound in the middle of the "do not distrub" mode on smartphone


Working version, with changed resistors and touch timing, and added LDR check when powering off in daylight so that it does not stop at 25% dim.

--- colorCurve.ino
+++ colorCurve.ino
@@ -12,8 +12,6 @@
     { 255, 255, 76 }
   };

-int oldbrightness = 0;
-
 /* Same as dimThousands, but slowly increases/decreases to end up at the given value */
 void goToDimThousands(int brightness) {
   goToDimThousands(brightness,1, false);
@@ -25,16 +23,17 @@
 //  Serial.print(" to "); Serial.println(brightness, DEC);

   int inc = 1;
-  if (brightness < oldbrightness) {
+  if (brightness < currentBrightness) {
     inc = -1;
   }

-  for (int i=oldbrightness; i!=brightness; i = i + inc) {
+  for (int i=currentBrightness; i!=brightness; i = i + inc) {
     dimThousands(i);
-    oldbrightness = i;
+    currentBrightness = i;
     delay(stepDelayMs);
     if (checkPIR && hasPIR()) break;
   }
+  currentBrightness = brightness;
 }


TemperatureMonitor: Added light sensing

TemperatureMonitor: Added light sensing

--- TemperatureMonitor/TemperatureMonitor.ino
+++ TemperatureMonitor/TemperatureMonitor.ino
@@ -1,6 +1,7 @@
 #include "DHT.h"

 int sampleRate = 2500; //Milliseconds between sampling
+bool debug = false;
 float tCorrection = -14.0;

 #define DHTPWR 7 //Power
@@ -10,6 +11,8 @@
 #define LM34PWR A0 //Power
 #define LM34GND A2 //Ground
 #define LM34PIN A1 //Data Pin (analog)
+
+#define LIGHTPIN A4 //Data Pin (analog)

 // Uncomment whatever type you're using!
 //#define DHTTYPE DHT11   // MDHT 11
@@ -29,6 +32,7 @@
   pinMode(LM34PWR, OUTPUT);
   pinMode(LM34GND, OUTPUT);
   pinMode(LM34PIN, INPUT);
+  pinMode(LIGHTPIN, INPUT);

   Serial.begin(9600);

@@ -49,12 +53,13 @@
   // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)

   float lm34 = analogRead(LM34PIN); //Read Analog Data from LM34
+  float light = analogRead(LIGHTPIN); //Read Analog Data from Light Sensor

   float h = dht.readHumidity(); //Read Humidity from DHT22
   float tC = dht.readTemperature(); //Read Temperature (in Celsius) from DHT22
   //float tF = (lm34/1024.0) * (readVcc() - 500) / 10; //Convert the LM34 analog value to a temperature
   float tF = tC * 9 / 5 + 32;
-  float l = 0; //Light Sensor, future use
+  float l = (1024 - light) / 1024 * 100; //Light Sensor, future use

   //float tArduino = readTemp()/1000.0 + tCorrection;
   float tArduino = GetTemp() + tCorrection;
@@ -62,35 +67,45 @@

   // check if returns are valid, if they are NaN (not a number) then something went wrong!
   if (isnan(tC) || isnan(h)) {
-    Serial.println(" - Failed to read from Sensor");
+    Serial.println(" - Failed to read from Temperature Sensor");
   } else {
-    //Nicely Formatted
-    //Serial.print("Humidity: ");
-    //Serial.print(h);
-    //Serial.print("%\t");
-    //Serial.print("Temperature: ");
-    //Serial.print(tF);
-    //Serial.write(176);
-    //Serial.print("F (");
-    //Serial.print(tC);
-    //Serial.write(176);
-    //Serial.print("C)");
-
-    //Delimited by |
-    Serial.print(tC);
-    Serial.print("|");
-    Serial.print(tF);
-    Serial.print("|");
-    Serial.print(h);
-    Serial.print("|");
-    Serial.print(l);
-    Serial.print("|");
-    Serial.print(vArduino);
-    Serial.print("|");
-    Serial.print(tArduino);
-    Serial.print("|");
-    Serial.print("(C,F,%,lm,Vcc,Ci)");
-    Serial.println();
+    if (debug) {
+      //Nicely Formatted
+      Serial.print("Temperature: ");
+      Serial.print(tF);
+      Serial.write(176);
+      Serial.print("F (");
+      Serial.print(tC);
+      Serial.write(176);
+      Serial.println("C)");
+
+      Serial.print("Humidity: ");
+      Serial.print(h);
+      Serial.println("%");
+
+      Serial.print("Light: ");
+      Serial.print(l);
+      Serial.println("%");
+
+      Serial.println();
+    }
+    else {
+      //Delimited by |
+      Serial.print(tC);
+      Serial.print("|");
+      Serial.print(tF);
+      Serial.print("|");
+      Serial.print(h);
+      Serial.print("|");
+      Serial.print(l);
+      Serial.print("|");
+      Serial.print(vArduino);
+      Serial.print("|");
+      Serial.print(tArduino);
+      Serial.print("|");
+      Serial.print("(C,F,%,lux,Vcc,Ci)");
+      Serial.println();
+    }
   }

   delay(sampleRate);


Add non-pwm argument

Add non-pwm argument

--- Photon/IoTlib/examples/starter/starter.ino
+++ Photon/IoTlib/examples/starter/starter.ino
@@ -33,10 +33,12 @@

     // Create devices
     //Note: D7 is not a PWM pin, so it can only turn on or off
+    //      The last 4th argument specifies this.
+    //      The 3rd argument can be used to invert on/off.
     // Alexa will respond to "Alexa, turn L E D on" or "Alexa, turn off L E D"
     // You can change the name 'LED' to whatever you like, but it needs to be something
     // that Alexa can recognize.
-    Light *light1 = new Light(D7, "LED");
+    Light *light1 = new Light(D7, "LED", false, true);

     // Tell IoT about the devices you defined above
     iot->addDevice(light1);


add motor pulse functionality.

add motor pulse functionality.

--- arduinoTest/USB_FocusST_PCB/USB_FocusST_PCB.ino
+++ arduinoTest/USB_FocusST_PCB/USB_FocusST_PCB.ino
@@ -47,7 +47,8 @@
 int dataPin = 4;

 int motorPin = 5;
-long motor_time = 500; //number of milliseconds the motor vibrates
+long motor_on = 200; //number of milliseconds the motor vibrates
+long motor_off = 100; //pause between pulses

 int buttonPin = 2;

@@ -59,6 +60,11 @@
 boolean stringComplete = false;
 boolean USB_connected = false;
 unsigned long time = 0;
+
+int motorCount = 2;
+int motorPulse = 2;
+volatile int motorState = LOW;
+boolean motorCommand = false;

 void setup() {
   //set pins to output so you can control the shift register
@@ -82,7 +88,30 @@

 void loop() {

-  if (millis() - time >= motor_time) analogWrite(motorPin, 0);
+  //handle motor control
+  if (motorState == HIGH && (millis() - time) >= motor_on && motorCommand) {
+    motorState = LOW;
+    digitalWrite(motorPin, motorState);
+    time = millis();
+  }
+
+  if (motorState == LOW && (millis() - time) >= motor_off
+                          && motorPulse > 0 && motorCommand) {
+    motorState = HIGH;
+    digitalWrite(motorPin, motorState);
+    motorPulse -= 1;
+    time = millis();
+
+    if (motorPulse <= 0) {
+      motorCommand = false;
+    }
+  }
+
+  if (millis()-time >= motor_on && !motorCommand) {
+    motorState = LOW;
+    digitalWrite(motorPin, motorState);
+    motorPulse = motorCount;
+  }

   if (!USB_connected) {
     for (int c = 0; c < 6; c++) {
@@ -100,7 +129,10 @@
     }

     if (inputString[inputString.length()-1] == ']') {
-      analogWrite(motorPin, 200);
+      motorState = HIGH;
+      motorCommand = true;
+      digitalWrite(motorPin, motorState);
+      motorPulse -= 1;
       time = millis();
     }


Add servo; fix button

Add servo; fix button

--- crypt-gears/gear_arduino/gear_arduino.ino
+++ crypt-gears/gear_arduino/gear_arduino.ino
@@ -1,3 +1,5 @@
+#include <Servo.h>
+
 // PIN NUMBERS
 int output_lights[7] = {38, 39, 40, 41, 42, 43, 44};

@@ -8,6 +10,10 @@
 int pot = A0;

 int photoresistors[3] = {A1, A2, A3};
+
+Servo servo;
+int servo_in = 10;
+int servo_power = 12;

 // CALIBRATION

@@ -73,6 +79,8 @@
 int winning_blink_state = -1;
 int debug_state = 0;

+int button_state = 0;
+
 // CONSTANTS DEFINING THE PUZZLE

 // Structure of the gears, represented as pairs that are connected.
@@ -98,7 +106,7 @@
 // How many frames to wait before toggling blinking lights
 int BLINK_SPEED = 50; // 0.5s
 // How many frames to wait before logging debug data, or 0 for never
-int DEBUG_FREQ = 100; // 1s
+int DEBUG_FREQ = 200; // 2s

 // MAIN TOPLEVEL STUFF

@@ -113,6 +121,10 @@
     pinMode(output_lights[i], OUTPUT);
     digitalWrite(output_lights[i], LOW);
   }
+
+  pinMode(servo_power, OUTPUT);
+  digitalWrite(servo_power, HIGH);
+  servo.attach(servo_in);

 }

@@ -256,6 +268,7 @@
       {
         state = 3;
         winning_blink_state = 0;
+        servo.write(180);
         sendCastleSuccessMessage();
       }

@@ -273,6 +286,7 @@
       state = 0;
       winning_blink_state = -1;
       resetLights();
+      servo.write(0);
     }
     else
     {
@@ -533,8 +547,6 @@
 {
   // turn on light
   digitalWrite(output_lights[n], HIGH);
-
-  // TODO(bhomberg): open solenoid??
 }

 // Reset all the lights.  (Caller should reset internal state.)
@@ -546,7 +558,6 @@
     digitalWrite(output_lights[i], LOW);
   }

-  // TODO(bhomberg): close all solenoids (??)
   digitalWrite(calibration_light, LOW);
 }

@@ -738,5 +749,12 @@
 // True if the button is pressed.
 boolean buttonPressed()
 {
-  return digitalRead(red_button);
-}
+  int val = digitalRead(red_button);
+  boolean ret = (button_state != val);
+  if (DEBUG_FREQ > 0 && ret)
+  {
+    Serial.println("BUTTON PRESSED");
+  }
+  button_state = val;
+  return ret;
+}


Sort of working: need smoother walking, and pause in-between leds

--- countdown/countdown.ino
+++ countdown/countdown.ino
@@ -1,4 +1,5 @@
 #include "FastSPI_LED2.h"
+#include "Streaming.h"

 #define ROWS 10
 #define COLS 10
@@ -124,7 +125,7 @@
 }

 #define UPDATE_TIME 20
-#define WALKER_TIMESTEP 50
+#define WALKER_TIMESTEP 100
 uint16_t step_period = 1;
 uint8_t leds_index = 0;
 uint8_t colour_counter=0; //keep track of the remaining colours in led (100-leds_left)
@@ -184,6 +185,55 @@
   walker_leds[step_counter] = moving_colours[colour_counter];
 }

+
+#define TOTAL_SECONDS ((uint16_t)(90*60))
+#define SECONDS_PER_LED ((uint16_t)TOTAL_SECONDS/NUM_LEDS)
+#define SECONDS_PER_COLOUR ((uint16_t) SECONDS_PER_LED/3)
+
+void draw_walker(uint16_t s){
+  // Draw the complete walker for the current amount of seconds left
+
+  // 1: determine the led that is currently 'walking out'
+  //    Since each led should take equal time to walk out, this is simply 100*s/T
+  uint8_t current_led = 100-(s / SECONDS_PER_LED);
+  // 2: determine which of the three colours is moving out
+  uint8_t secs_in_led = SECONDS_PER_LED-s%SECONDS_PER_LED;
+  uint8_t current_colour = ((uint16_t) secs_in_led * 3) / SECONDS_PER_LED;
+  // 3: determine the position of the current colour
+  uint8_t current_pos = current_led-1 - ((secs_in_led % SECONDS_PER_COLOUR) * current_led) / SECONDS_PER_COLOUR;
+
+  // The following happens at the very end of the last led
+  if(current_colour==3){
+    return;
+  }
+
+  // Then, do the colouring!
+  for(uint8_t i_led=0; i_led <= current_led; ++i_led){
+    // these are all black
+    walker_leds[i_led] = CRGB::Black;
+  }
+  for(uint8_t i_led= max(current_led+1,NUM_LEDS-1); i_led < NUM_LEDS; ++i_led){
+    // these are white
+    walker_leds[i_led] = CRGB::White;
+  }
+  // Now, the current led's colour
+  switch(current_colour){
+    case 0: //blue has left
+      walker_leds[current_led] = CRGB::Yellow;
+    break;
+    case 1: //green has also left
+      walker_leds[current_led] = CRGB::Red;
+    break;
+    break;
+    // TODO: default case?
+  }
+  // Finally, the walking led
+  // TODO: if this works, reverse moving_colours and remove 2- in the index below
+  walker_leds[current_pos] = moving_colours[2-current_colour];
+
+  Serial << "s: " << s << "; led: " << current_led << "; c: " << current_colour << "; p: " << current_pos << endl;
+}
+
 void update(){
   LEDS.show();
 }
@@ -209,7 +259,7 @@
 }

-uint16_t seconds_left = 90*60;
+uint16_t seconds_left = TOTAL_SECONDS;

 unsigned long prevStepTime = 0;
@@ -220,29 +270,32 @@
 void loop(){
   if(millis()-prevStepTime >= WALKER_TIMESTEP){
     prevStepTime = millis();
+    /*
     if(--step_period == 0){
       // step_period is reset inside step_led();
       step_led();
-    }
-  }
-
+    }*/
+    draw_walker(seconds_left--);
+  }
+  /*
   if(millis()-prevCounterTime >= 500){
     prevCounterTime = millis();
     writeDigits(seconds_left--);
-  }
+  }*/

   if(millis()-prevUpdateTime >= UPDATE_TIME){
     prevUpdateTime = millis();
     for(uint8_t i_led=0; i_led != NUM_LEDS; ++i_led){
       for(uint8_t i=0; i!=3; ++i)
-        leds[i_led][i] = (uint8_t) (((uint16_t)leds[i_led][i]*19 + (uint16_t)walker_leds[i_led][i]/2 + (uint16_t)counter_leds[i_led][i]/3)/20);
+        leds[i_led][i] = walker_leds[i_led][i];
+        // leds[i_led][i] = (uint8_t) (((uint16_t)leds[i_led][i]*19 + (uint16_t)walker_leds[i_led][i]/2 + (uint16_t)counter_leds[i_led][i]/3)/20);
     }
     update();
   }

   if(millis()-prevReportTime >= 500){
     prevReportTime = millis();
-    Serial.println(step_period);
-  }
-}
-
+//    Serial.println(step_period);
+  }
+}
+


Update arduino.ino

Update arduino.ino

Modification des vérifications des numéros de pin en mode binaire, de la durée et du nombre de clignotements, afin de correspondre au cahier des charges.

--- Arduino/arduino/arduino.ino
+++ Arduino/arduino/arduino.ino
@@ -257,7 +257,7 @@
   // valeur de la pin à eteindre
   int led = atoi(pin->valuestring);
   //paramètre pin non numérique ou hors des limites: erreur 202
-  if(!isValidNumber(pin) || led < 0 || led > 13) {
+  if(!isValidNumber(pin) || led < 1 || led > 13) {
     sendReponse(client, reponse(strId,"202",NULL));
     return;
   }
@@ -274,7 +274,7 @@
   // valeur de la durée
   int duree = atoi(dur->valuestring);
   //paramètre durée non numérique ou non supérieur à 0: erreur 204
-  if(!isValidNumber(dur) || duree < 1) {
+  if(!isValidNumber(dur) || duree < 100 || duree > 2000) {
     sendReponse(client, reponse(strId,"204",NULL));
     return;
   }
@@ -291,7 +291,7 @@
   // valeur du nombre de clignotements
   int nbClignotements = atoi(nb->valuestring);
   //paramètre nb non numérique ou non supérieur à 0: erreur 206
-  if(!isValidNumber(nb) || nbClignotements < 1) {
+  if(!isValidNumber(nb) || nbClignotements < 2) {
     sendReponse(client, reponse(strId,"206",NULL));
     return;
   }
@@ -350,7 +350,7 @@
     return;
   }
   //paramètre pin non numérique ou pas dans les bornes (selon mode binaire ou analogique): erreur 305
-  if(!isValidNumber(pin) || (strcmp(mod2, "b")==0 && (pin2 < 0 || pin2 > 13)) || (strcmp(mod2, "a")==0 && (pin2 < 0 || pin2 > 5)) ) {
+  if(!isValidNumber(pin) || (strcmp(mod2, "b")==0 && (pin2 < 1 || pin2 > 13)) || (strcmp(mod2, "a")==0 && (pin2 < 0 || pin2 > 5)) ) {
     sendReponse(client, reponse(strId,"305",NULL)); // réponse d'erreur
     return;
   }
@@ -405,7 +405,7 @@
   }

   //paramètre pin non numérique ou hors des limites: erreur 404
-  if(!isValidNumber(pin) || (strcmp(mod2, "b")==0 && (pin2 < 0 || pin2 > 13)) || (strcmp(mod2, "a")==0 && (pin2 < 0 || pin2 > 5)) ) {
+  if(!isValidNumber(pin) || (strcmp(mod2, "b")==0 && (pin2 < 1 || pin2 > 13)) || (strcmp(mod2, "a")==0 && (pin2 < 0 || pin2 > 5)) ) {
     sendReponse(client, reponse(strId,"404",NULL)); // réponse d'erreur
     return;
   }


comments + includes

comments + includes

--- refrigerator-lights.ino
+++ refrigerator-lights.ino
@@ -31,19 +31,23 @@
 #include <FontMatrise.h>
 #include <espduino.h>
 #include <mqtt.h>
+#include "Animation.h"
+#include "Ticker.h"
+#include "Twinkle.cpp"
 #include "Plasma.cpp"
-#include "TestPattern.cpp"
 #include "Snake.cpp"
-#include "Twinkle.cpp"
-#include "DeadChannel.cpp"
-#include "Bouncy.cpp"
-#include "HiRez.cpp"
-#include "Boxes.cpp"
 #include "Life.cpp"
 #include "Sprite.cpp"
 #include "RainbowColor.cpp"
-#include "Animation.h"
-#include "Ticker.h"
+
+// Teensy 3.1 pinout:
+// ====================
+// 0 = RX >> EXP8266 TX
+// 1 = TX >> ESP8266 RX
+// 2 = ESP8266 CH_PD
+// 3 = LED data pin 1
+// 4 = LED data pin 2
+// 5 = LED data pin 3

 // initial ESP8266
 ESP esp(&Serial1, &Serial, 2);
@@ -51,9 +55,9 @@
 boolean wifiConnected = false;

 // define LED digital pin, color order, chipset and brightness
-#define LED_PIN1    4 //2
-#define LED_PIN2    5 //14
-#define LED_PIN3    6 //7
+#define LED_PIN1    3
+#define LED_PIN2    4
+#define LED_PIN3    5
 #define COLOR_ORDER   GRB
 #define CHIPSET     WS2812B
 #define BRIGHTNESS  170


Green is working too!! (LaB)

Green is working too!! (LaB)

--- pug.ino
+++ pug.ino
@@ -71,8 +71,8 @@
   ultraCompteur++;
 }

-boolean isGreen(){
- return digitalRead(pinColor);
+boolean isGreen() {
+  return digitalRead(pinColor);
 }

 void stopRight() {
@@ -135,16 +135,16 @@
 }

 // Vitesse entre 0 et 100
-void goBackward(int vitesse){
+void goBackward(int vitesse) {
   setLeftSpeed(-vitesse);
   setRightSpeed(-vitesse);
-      }
-
-      // Vitesse entre 0 et 100
-void goForward(int vitesse){
+}
+
+// Vitesse entre 0 et 100
+void goForward(int vitesse) {
   setLeftSpeed(vitesse);
   setRightSpeed(vitesse);
-      }
+}

 // Servo control methods
 void smoothSploch () {
@@ -190,7 +190,7 @@
   motorTimer.begin(manageMotors, 30);

   // Ultrason
- // ultraTimer.begin(ultraCheck, 50000);
+  // ultraTimer.begin(ultraCheck, 50000);
   pinMode(ultraTrig, OUTPUT);
   digitalWrite(ultraTrig, LOW);
   pinMode(ultraEcho, INPUT);
@@ -202,65 +202,69 @@

   //DebugLed
   pinMode(13, OUTPUT);
-
+
   //Init Jumper
   pinMode(JUMPER, INPUT);

   // Serial
   Serial.begin(9600);
-
-    if (isGreen()) {
-    digitalWrite(13,LOW);
+
+  if (isGreen()) {
+    digitalWrite(13, LOW);
   } else {
-    digitalWrite(13,HIGH);
-  }
-
+    digitalWrite(13, HIGH);
+  }
+

   //  initializeTimer1();
 }

 void loop() {
-
-  if (!endScript){
-    for (int i = 0; i<2000; i++);
+
+  if (!endScript) {
+    for (int i = 0; i < 2000; i++);
     Serial.println("DEBUT DE SCRIPT");
     Serial.println("Attente de Jumper...");
-    while(!digitalRead(JUMPER));
+    while (!digitalRead(JUMPER));
     Serial.println("Debout!");
     prepareToStart();
     Serial.println("Retirer le jumper...");
-    while(digitalRead(JUMPER));
+    while (digitalRead(JUMPER));
     smoothSploch();
     Serial.println("Descente!");
     Serial.println("Calibrage en cours...");
     goBackward(35);
     delay(3000);
     stopMotors();
-
+
     goForward(30);
     delay(1800);
     goForward(1);
     delay(500);
     stopMotors();
     delay(1000);
-    rotateRight();
+    if (isGreen()) {
+      rotateLeft();
+    } else {
+      rotateRight();
+    }
     delay(1000);
     goBackward(60);
     delay(900);
     goBackward(1);
     delay(100);
     stopMotors();
-
-
-
+
+
+
     Serial.println("Calibrage OK!");
-
-
+
+
     endScript = true;
     Serial.println("FIN DE SCRIPT");
-    while(42);
-    }
-
+    while (42);
+  }
+
 }

 // Serial
@@ -353,7 +357,7 @@
       Serial.println("left on");
       setLeftSpeed( 30);
       break;
-
+
     case 'j':
     case 'J':
       JUMPER != JUMPER;


Improved OLED feedback

Improved OLED feedback

--- Code/ESP32_menu_btn/ESP32_menu_btn.ino
+++ Code/ESP32_menu_btn/ESP32_menu_btn.ino
@@ -1,6 +1,7 @@
 /*
- * For ESP32-WROOM board (OLED, battery, full pin breakout)
+ * For ESP32-WROOM board (OLED, battery, full pin breakout) and custom PCB
  * Don't forget to turn the device on, or it won't show up in the port list
+ * If UART disappears from port list, change board to UNO and attach an UNO
  *
  * Board:   Wemos Wifi&Bluetooth Battery
  * Flash:   80Mhz
@@ -75,44 +76,44 @@
   // LOW is button pressed
   u8x8.setFont(u8x8_font_victoriamedium8_u);

+  // Center button
+  if(digitalRead(buttonPin2) == 0){
+    u8x8.drawString(0,0,"X BUTTON");
+    chase(strip.Color(0, 255, 0));
+  }else{
+    u8x8.drawString(0,0,"  BUTTON");
+  }
+
   // Upper right
   if(digitalRead(buttonPin1) == 0){
-    u8x8.drawString(0,0,"BTN1 = LOW ");
+    u8x8.drawString(0,1,"X TOP RIGHT");
     chase(strip.Color(255, 0, 0));
   }else{
-    u8x8.drawString(0,0,"BTN1 = HIGH");
-  }
-
-  // Center button
-  if(digitalRead(buttonPin2) == 0){
-    u8x8.drawString(0,1,"BTN2 = LOW ");
-    chase(strip.Color(0, 255, 0));
-  }else{
-    u8x8.drawString(0,1,"BTN2 = HIGH");
+    u8x8.drawString(0,1,"  TOP RIGHT");
   }

   // Upper left
   if(digitalRead(buttonPin3) == 0){
-    u8x8.drawString(0,2,"BTN3 = LOW ");
+    u8x8.drawString(0,2,"X TOP LEFT");
     chase(strip.Color(0, 0, 255));
   }else{
-    u8x8.drawString(0,2,"BTN3 = HIGH");
+    u8x8.drawString(0,2,"  TOP LEFT");
   }

   // Lower right
   if(digitalRead(buttonPin4) == 0){
-    u8x8.drawString(0,3,"BTN4 = LOW ");
+    u8x8.drawString(0,3,"X BOT RIGHT");
     chase(strip.Color(255, 0, 255));
   }else{
-    u8x8.drawString(0,3,"BTN4 = HIGH");
+    u8x8.drawString(0,3,"  BOT RIGHT");
   }

   // Lower left
   if(digitalRead(buttonPin5) == 0){
-    u8x8.drawString(0,4,"BTN5 = LOW ");
+    u8x8.drawString(0,4,"X BOT LEFT");
     chase(strip.Color(255, 255, 255));
   }else{
-    u8x8.drawString(0,4,"BTN5 = HIGH");
+    u8x8.drawString(0,4,"  BOT LEFT");
   }
 }


removing full test suite

removing full test suite

--- examples/full_test_suite/full_test_suite.ino
+++ examples/full_test_suite/full_test_suite.ino
@@ -1,174 +0,0 @@
-/* RestClient full test suite
- *
- * Every REST method is called.
- *
- * by Chris Continanza (csquared)
- */
-
-#include <Ethernet.h>
-#include <SPI.h>
-#include "RestClient.h"
-
-int test_delay = 1000; //so we don't spam the API
-boolean describe_tests = true;
-
-RestClient client = RestClient("arduino-http-lib-test.herokuapp.com");
-//RestClient client  = RestClient("10.0.1.47",5000);
-
-
-//Setup
-void setup() {
-  Serial.begin(9600);
-  // Connect via DHCP
-  Serial.println("connect to network");
-  client.dhcp();
-/*
-  //Can still fall back to manual config:
-  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
-  //the IP address for the shield:
-  byte ip[] = { 192, 168, 2, 11 };
-  Ethernet.begin(mac,ip);
-*/
-  Serial.println("Setup!");
-}
-
-void test_status(int statusCode){
-   delay(test_delay);
-   if(statusCode == 200){
-    Serial.print("TEST RESULT: ok (");
-    Serial.print(statusCode);
-    Serial.println(")");
-   }else{
-    Serial.print("TEST RESULT: fail (");
-    Serial.print(statusCode);
-    Serial.println(")");
-   }
-}
-
-String response;
-void test_response(){
-  //Serial.println(response);
-  if(response == "OK"){
-   Serial.println("TEST RESULT: ok (response body)");
-  }else{
-   Serial.println("TEST RESULT: fail (response body = " + response + ")");
-  }
-  response = "";
-}
-
-void describe(char * description){
-  if(describe_tests) Serial.println(description);
-}
-
-//reusable test variables
-char* post_body = "POSTDATA";
-
-void GET_tests(){
-  describe("Test GET with path");
-  test_status(client.get("/get"));
-
-  describe("Test GET with path and response");
-  test_status(client.get("/get", &response));
-  test_response();
-
-  describe("Test GET with path and header");
-  client.setHeader("X-Test-Header: true");
-  test_status(client.get("/get-header"));
-
-  describe("Test GET with path and header and response");
-  client.setHeader("X-Test-Header: true");
-  test_status(client.get("/get-header", &response));
-  test_response();
-
-  describe("Test GET with 2 headers and response");
-  client.setHeader("X-Test-Header1: one");
-  client.setHeader("X-Test-Header2: two");
-  test_status(client.get("/get-headers", &response));
-  test_response();
-}
-
-void POST_tests(){
-    // POST TESTS
-  describe("Test POST with path and body");
-  test_status(client.post("/data", post_body));
-
-  describe("Test POST with path and body and response");
-  test_status(client.post("/data", post_body, &response));
-  test_response();
-
-  describe("Test POST with path and body and header");
-  client.setHeader("X-Test-Header: true");
-  test_status(client.post("/data-header", post_body));
-
-  describe("Test POST with path and body and header and response");
-  client.setHeader("X-Test-Header: true");
-  test_status(client.post("/data-header", post_body, &response));
-  test_response();
-
-  describe("Test POST with 2 headers and response");
-  client.setHeader("X-Test-Header1: one");
-  client.setHeader("X-Test-Header2: two");
-  test_status(client.post("/data-headers", post_body, &response));
-  test_response();
-}
-
-void PUT_tests(){
-  describe("Test PUT with path and body");
-  test_status(client.put("/data", post_body));
-
-  describe("Test PUT with path and body and response");
-  test_status(client.put("/data", post_body, &response));
-  test_response();
-
-  describe("Test PUT with path and body and header");
-  client.setHeader("X-Test-Header: true");
-  test_status(client.put("/data-header", post_body));
-
-  describe("Test PUT with path and body and header and response");
-  client.setHeader("X-Test-Header: true");
-  test_status(client.put("/data-header", post_body, &response));
-  test_response();
-
-  describe("Test PUT with 2 headers and response");
-  client.setHeader("X-Test-Header1: one");
-  client.setHeader("X-Test-Header2: two");
-  test_status(client.put("/data-headers", post_body, &response));
-  test_response();
-}
-
-void DELETE_tests(){
-  describe("Test DELETE with path");
-  //note: requires a special endpoint
-  test_status(client.del("/del"));
-
-  describe("Test DELETE with path and body");
-  test_status(client.del("/data", post_body));
-
-  describe("Test DELETE with path and body and response");
-  test_status(client.del("/data", post_body, &response));
-  test_response();
-
-  describe("Test DELETE with path and body and header");
-  client.setHeader("X-Test-Header: true");
-  test_status(client.del("/data-header", post_body));
-
-  describe("Test DELETE with path and body and header and response");
-  client.setHeader("X-Test-Header: true");
-  test_status(client.del("/data-header", post_body, &response));
-  test_response();
-
-  describe("Test DELETE with 2 headers and response");
-  client.setHeader("X-Test-Header1: one");
-  client.setHeader("X-Test-Header2: two");
-  test_status(client.del("/data-headers", post_body, &response));
-  test_response();
-}
-
-
-// Run the tests!
-void loop(){
-  GET_tests();
-  POST_tests();
-  PUT_tests();
-  DELETE_tests();
-}


Add TX Node TeleInfo

Add TX Node TeleInfo

--- MainStation/MainStation.ino
+++ MainStation/MainStation.ino
@@ -132,7 +132,7 @@
 // Main Application Structure
 typedef struct ApplicationStruct {
   byte nbrSensors;
-  SensorDefinition sensors[3]; // Sensors Definition
+  SensorDefinition sensors[4]; // Sensors Definition
   RenderDefinition render; // LCD rendering
   ReceiverDefinition rx; // RX receiver
   EthernetDefinition eth; // Ethernet
@@ -142,29 +142,36 @@

 // Static Definition
 static ApplicationDefinition _app = {
-  3, // Total number of sensors
+  4, // Total number of sensors
   // Sensors
   {
-    // Sensor #1
+    // Sensor #0
     {
       "Inside Temp",
       1, // Sensor ID
       -99.0, // Initial Value
       "C"
     },
-    // Sensor #2
+    // Sensor #1
     {
       "Outside Temp",
       42, // Sensor ID
       -99.0, // Initial Value
       "C"
     },
-    // Sensor #3
+    // Sensor #2
     {
       "Pressure",
       2, // Sensor ID
       -99.0, // Initial Value
       "hPa"
+    },
+    // Sensor #3
+    {
+      "Power",
+      5, // Sensor ID
+      -99.0, // Initial Value
+      "W"
     }
   },
     // Render
@@ -266,10 +273,7 @@

   // Paint
   render();
-
-  // Wait some time
-  //delay(20);
-
+
 }


purging duplicate file

purging duplicate file

--- Arduino/Master_Arduino_Metro.ino
+++ Arduino/Master_Arduino_Metro.ino
@@ -1,107 +0,0 @@
-
-// MIMIC!!! MIMIC!!!
-//
-//
-
-// Prior problems with Mega interrupt limitations led to use of Arduino Due instead.  This board can
-// support hardware interrupts on any digital pin, although pin 13 is avoided since connects to LED.
-// This means we can (theoretically) use an interrupt pin for each encoder signal on each motor.
-// That's two per motor, times ten (8 BGA and 2 SARJ) motors = 20 interrupts. A minor issue discovered
-// with the Due is that it's pull-up resistors have a large value (100 Kohms), which made for problems
-// with counting encoder pulses.  Web search indicated that using a 2.2K resistor on each utilized pin
-// to 3.3v is the solution, which seems to work well.
-// Subsequently, discovered Due is problematic with I2C, so moved to Metro M0
-
-// To Do's
-// 1) Test with four motors
-// 2) Set I2C address for 2nd and 3rd motor driver boards, as each board can drive only 4 DC motors.
-// 3) Try 20 interrupts (driven by encoders) at once to ensure no loss of counts
-// 4) Rewrite Motor algorithms as re-usable class, rather than explicit for each one.
-// 5) Add capability for servos, to drive the TRRJs.
-// 6) De-ugli-fication of the code.
-
-#include <Encoder.h>
-
-#include <Adafruit_MotorShield.h>
-#include "utility/Adafruit_MS_PWMServoDriver.h"
-#include <string.h>
-#include <Servo.h>
-Servo servo1;
-Servo servo2;
-
-// Temporarily setting some pins to ground and high (3.3v) for convenient connections.  Will mod when using more motors.
-//int MyHighPin13 = 13; // This is just to have a convenient 3.3volt source near the other utilized pins
-//int MyHighPin11 = 1;
-//int MyHighPin12 = 12;
-//
-//int MyLowPin0 = 0;
-//int MyLowPin14 = 14; //AKA Analog A0
-//int MyLowPin15 = 15; //AKA Analog A1
-//int MyLowPin16 = 16; //AKA Analog A2
-
-// Create the motor shield object with the default I2C address
-Adafruit_MotorShield AFMS = Adafruit_MotorShield();
-// Or, create it with a different I2C address (say for stacking)
-// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
-
-// Select which 'port' M1, M2, M3 or M4. In this case, M1,2,4
-Adafruit_DCMotor *myMotorB2A = AFMS.getMotor(1);
-Adafruit_DCMotor *myMotorB4A = AFMS.getMotor(2);
-Adafruit_DCMotor *myMotorB2B = AFMS.getMotor(3);
-Adafruit_DCMotor *myMotorB4B = AFMS.getMotor(4);
-
-//ManualSpeed Encoder myEnc4B(1, 2);
-Encoder myEnc2A(2, 3);
-Encoder myEnc4A(4, 5);
-Encoder myEnc2B(6, 7);
-Encoder myEnc4B(11, 12);
-
-void setup() {
-//  pinMode(MyHighPin13, OUTPUT);
-//  digitalWrite(MyHighPin13, HIGH); // This is just a convenient pin for 3.3 volts
-//  pinMode(MyHighPin11, OUTPUT);
-//  digitalWrite(MyHighPin11, HIGH); // This is just a convenient pin for 3.3 volts
-//  pinMode(MyHighPin12, OUTPUT);
-//  digitalWrite(MyHighPin12, HIGH); // This is just a convenient pin for 3.3 volts
-//
-//
-//  pinMode(MyLowPin0, OUTPUT);
-//  digitalWrite(MyLowPin0, LOW); // This is just a convenient pin for Gnd
-//
-//  pinMode(MyLowPin14, OUTPUT);
-//  digitalWrite(MyLowPin14, LOW); // This is just a convenient pin for Gnd
-//  pinMode(MyLowPin15, OUTPUT);
-//  digitalWrite(MyLowPin15, LOW); // This is just a convenient pin for Gnd
-//    pinMode(MyLowPin16, OUTPUT);
-//  digitalWrite(MyLowPin16, LOW); // This is just a convenient pin for Gnd
-
-
-
-  // Attach a servo to pin #10
-  servo1.attach(10);
-  servo2.attach(9);
-  AFMS.begin(200);  // I set this at 200 previously to reduce audible buzz.
-  Serial.begin(115200);
-  //Serial3.begin(115200);          //Serial1 is connected to the RasPi
-  //Serial3.setTimeout(50);
-
-  Serial.println("Motor test!");
-
-  // turn on motor   NOTE: May be able to remove all of these setSpeed and run commands here, although they are fine.
-  myMotorB2A->setSpeed(150);
-  myMotorB2A->run(RELEASE);
-
-  myMotorB4A->setSpeed(150);
-  myMotorB4A->run(RELEASE);
-
-  myMotorB2B->setSpeed(150);
-  myMotorB2B->run(RELEASE);
-
-  myMotorB4B->setSpeed(150);
-  myMotorB4B->run(RELEASE);
-
-  // For debugging
-  //  pinMode(13, OUTPUT); //LED
-}
-
-


Added /reset_wlan REST webservice command.

--- Arduino/McLighting/McLighting.ino
+++ Arduino/McLighting/McLighting.ino
@@ -217,6 +217,14 @@
     ESP.restart();
   });

+  server.on("/reset_wlan", []() {
+    DBG_OUTPUT_PORT.printf("/reset_wlan:\n");
+    server.send(200, "text/plain", "Resetting WLAN and restarting..." );
+    WiFiManager wifiManager;
+    wifiManager.resetSettings();
+    ESP.restart();
+  });
+

   // ***************************************************************************
   // Setup: SPIFFS Webserver handler


added SPI header to example

added SPI header to example

--- examples/DMASpi_example1/DMASpi_example1.ino
+++ examples/DMASpi_example1/DMASpi_example1.ino
@@ -1,5 +1,6 @@
 #include <WProgram.h>

+#include <SPI.h>
 #include <DmaSpi.h>

 /** Important


Minor change to delay between runs.

Minor change to delay between runs.

--- xy.ino
+++ xy.ino
@@ -443,7 +443,8 @@
       // c = Color( rgb.r, rgb.g, rgb.b);
       // strip.setPixelColor( run, c);
       strip.show();
-      delay( run < 3 ? 5000 : 20000); // Delay longer for HSL part of run (3 * 5 + 3 * 20 = 75 seconds)
+      // delay( run < 3 ? 5000 : 20000); // Delay longer for HSL part of run (3 * 5 + 3 * 20 = 75 seconds)
+      delay( 10000);
    }

    // Since we skipped "black" and "white", show a checkerboard of those.


Update Firmware.ino

Update Firmware.ino

--- src/piggy_back_loggers/SD_Mag_Prototype/Firmware/Firmware.ino
+++ src/piggy_back_loggers/SD_Mag_Prototype/Firmware/Firmware.ino
@@ -112,7 +112,7 @@
   rtcTransfer(reg_Tmr_A_freq_ctrl, WRITE, 0x02);
   rtcTransfer(reg_Tmr_A_reg, WRITE, 0x04);
   rtcTransfer(reg_Control_2, WRITE, 0x02);
-  rtcTransfer(reg_Control_3, WRITE, 0x40);                        // Set RTC to switch to Battery on power loss
+  rtcTransfer(reg_Control_3, WRITE, 0x80);                        // Set RTC to switch to Battery on power off

   /*Interrupts TODO: change the INT0_ISR to record magnetometer data*/