moving to 6 interrupt plan tested on Vehichle number 2

--- RC_Control_interrupts/RC_Control_interrupts.ino
+++ RC_Control_interrupts/RC_Control_interrupts.ino
@@ -1,12 +1,62 @@
-//RC_Control_interrupts.ino
-/*
-This version assumes that each of
-RC_STEER_PIN, RC_CRUISE_PIN, RC_THROTTLE_PIN, RC_ESTOP_PIN, RC_RUDDER_PIN and RC_REVERSE_PIN
-go into an OR gate to form RC_INTERRUPT_PIN.
-The variable rc_index tells where the next data will go in RC_results.
-
-*/
+
 #include <SPI.h>
+
+// New section    TCF 9/17/15
+// Indices for information stored in array RC_results
+#define VEHICLE_NUMBER 2
+// Channel order differs for differernt vehicles
+#if (VEHICLE_NUMBER == 1)
+#define RC_TURN 1
+#define RC_AUTO 2
+#define RC_GO   3
+#define RC_ESTP 4
+#define RC_RDR  5
+#define RC_RVS  6
+
+#define NUMBER_CHANNELS = 6
+
+//OUTPUT values -  0 to 255
+#define MIN_ACC_OUT 40
+#define MAX_ACC_OUT 227
+#define MIN_BRAKE_OUT 167
+#define MAX_BRAKE_OUT 207
+#define RIGHT_TURN_OUT 146
+#define LEFT_TURN_OUT 230
+#define STRAIGHT_TURN_OUT 187
+#define DAC_CHANNEL 0
+#define STEER_OUT_PIN 7 // Output to steer actuator
+#define BRAKE_OUT_PIN 6  // output to brake actuator
+
+#endif
+#if (VEHICLE_NUMBER == 2)
+
+#define RC_AUTO 1
+#define RC_ESTP 2
+#define RC_RDR  3
+#define RC_GO   4
+#define RC_TURN 5
+#define NUMBER_CHANNELS 5
+// Controller has no channel for RC_AUTO
+#define RC_RVS  6
+
+
+//OUTPUT values -  0 to 255
+#define MIN_ACC_OUT 40
+#define MAX_ACC_OUT 227
+#define MIN_BRAKE_OUT 167
+#define MAX_BRAKE_OUT 207
+#define RIGHT_TURN_OUT 146
+#define LEFT_TURN_OUT 230
+#define STRAIGHT_TURN_OUT 187
+
+#define DAC_CHANNEL 3
+#define STEER_OUT_PIN 7 // Output to steer actuator
+#define BRAKE_OUT_PIN 9  // output to brake actuator
+
+#endif
+
+
+// End new section

 //RC input values - pulse widths in microseconds
 const int LONG_DEADZONE_THRESHOLD = 10000; // used for syncing to determine if the last down time was the long down zone
@@ -18,14 +68,6 @@
 const int CYCLE_MAX = 25000;  // Pulses come at 42.27 Hz, every 21155 us
 const int MAX_PULSE = 4000; // Next pulse should be no longer than this time from last.

-//OUTPUT values -  0 to 255
-const int MIN_ACC_OUT = 40;
-const int MAX_ACC_OUT = 227;
-const int MIN_BRAKE_OUT = 167;
-const int MAX_BRAKE_OUT = 207;
-const int LEFT_TURN_OUT = 126;
-const int RIGHT_TURN_OUT = 250;
-const int STRAIGHT_TURN_OUT = 187;

 //ARDUINO PIN SELECTORS
 const int RC_STEER_PIN = 44; // Input from RC // was 2;
@@ -37,8 +79,6 @@
 const int RC_INTERRUPT_PIN = 20;
 const int RC_INTERRUPT = 3;
 const int PIN_ORDER[8] = {0, RC_STEER_PIN, RC_CRUISE_PIN, RC_THROTTLE_PIN, RC_ESTOP_PIN, RC_RUDDER_PIN, RC_REVERSE_PIN, 0};
-const int STEER_OUT_PIN = 7; // Output to steer actuator
-const int BRAKE_OUT_PIN = 6;  // output to brake actuator
 const int SelectCD = 49; // Select IC 3 DAC (channels C and D)
 const int SelectAB = 53; // Select IC 2 DAC (channels A and B)

@@ -51,6 +91,114 @@
 volatile int rc_state = RC_WAIT;
 volatile boolean synced = false;
 volatile unsigned long last_fallingedge_time = 4294967295; // max long
+volatile int RC_Done[7] = {0,0,0,0,0,0,0};
+
+const int Signals[6] = {1, 2, 3, 4, 5, 0}; // {4, 3, 2, 0, 0, 0};
+/* Arduino Mega:
+  D2 = Int 0  Chan 6 [closest to ind/Data]
+  D3 = Int 1  Wheel Click
+  D21 = Int 2 Green wire Chan 2
+  D20 = Int 3 Yellow wire Chan 3
+  D19 = Int 4 Orange wire Chan 4
+  D18 = Int 5 Red wire Chan 5
+  Blue wire Chan 1 No Connect
+*/
+
+void ProcessRiseOfINT(int intIndex) {
+  RC_results[intIndex] = micros();
+}
+
+void ISR1_rise() {
+  noInterrupts();
+  ProcessRiseOfINT(1);
+  attachInterrupt(Signals[0], ISR1_fall, FALLING);
+  interrupts();
+}
+
+void ISR2_rise() {
+  noInterrupts();
+  ProcessRiseOfINT(2);
+  attachInterrupt(Signals[1], ISR2_fall, FALLING);
+  interrupts();
+}
+
+void ISR3_rise() {
+  noInterrupts();
+  ProcessRiseOfINT(3);
+  attachInterrupt(Signals[2], ISR3_fall, FALLING);
+  interrupts();
+}
+
+void ISR4_rise() {
+  noInterrupts();
+  ProcessRiseOfINT(4);
+  attachInterrupt(Signals[3], ISR4_fall, FALLING);
+  interrupts();
+}
+
+void ISR5_rise() {noInterrupts();
+  ProcessRiseOfINT(5);
+  attachInterrupt(Signals[4], ISR5_fall, FALLING);
+  interrupts();
+}
+
+void ISR6_rise() {
+  noInterrupts();
+  ProcessRiseOfINT(6);
+  attachInterrupt(Signals[5], ISR6_fall, FALLING);
+  interrupts();
+}
+
+void ProcessFallOfINT(int intIndex) {
+  RC_results[intIndex] = micros() - RC_results[intIndex];
+}
+
+void ISR1_fall() {
+  noInterrupts();
+  ProcessFallOfINT(1);
+  RC_Done[1] = 1;
+  attachInterrupt(Signals[0], ISR1_rise, RISING);
+  interrupts();
+}
+
+void ISR2_fall() {
+  noInterrupts();
+  ProcessFallOfINT(2);
+  RC_Done[2] = 1;
+  attachInterrupt(Signals[1], ISR2_rise, RISING);
+  interrupts();
+}
+
+void ISR3_fall() {
+  noInterrupts();
+  ProcessFallOfINT(3);
+  RC_Done[3] = 1;
+  attachInterrupt(Signals[2], ISR3_rise, RISING);
+  interrupts();
+}
+void ISR4_fall() {
+  noInterrupts();
+  ProcessFallOfINT(4);
+  RC_Done[4] = 1;
+  attachInterrupt(Signals[3], ISR4_rise, RISING);
+  interrupts();
+}
+
+void ISR5_fall() {
+  noInterrupts();
+  ProcessFallOfINT(5);
+  RC_Done[5] = 1;
+  attachInterrupt(Signals[4], ISR5_rise, RISING);
+  interrupts();
+}
+
+void ISR6_fall() {
+  noInterrupts();
+  ProcessFallOfINT(6);
+  RC_Done[6] = 1;
+  attachInterrupt(Signals[5], ISR6_rise, RISING);
+  interrupts();
+}

 void setup()
 { //Set up pins
@@ -74,65 +222,21 @@
           RC_results[i] = INVALID_DATA;
       rc_state = RC_WAIT;

-      attachInterrupt(RC_INTERRUPT, ISR_rise, RISING);
-}
-void ISR_rise()
-{
-    noInterrupts();
-
-    if (rc_state != RC_WAIT)
-    {
-      if (!synced)
-      {
-        unsigned int elapsed = micros() - last_fallingedge_time;
-        if (elapsed > LONG_DEADZONE_THRESHOLD)
-        {
-          RC_results[rc_index] = micros();
-          synced = true;
-          rc_index = 1;
-        }
-      }
-      else
-      {
-        RC_results[rc_index] = micros();
-      }
-      attachInterrupt(RC_INTERRUPT, ISR_fall, FALLING);
-    }
-
-    interrupts();
-}
-void ISR_fall()
-{
-    noInterrupts();
-
-    if (rc_state != RC_WAIT)
-    {
-      if (!synced)
-      {
-        last_fallingedge_time = micros();
-      }
-      else
-      {
-        RC_results[rc_index] = micros() - RC_results[rc_index];
-        rc_index++;
-        if (rc_index == 7)
-        {
-          rc_index = 1;
-          rc_state = RC_DONE;
-        }
-      }
-      attachInterrupt(RC_INTERRUPT, ISR_rise, RISING);
-    }
-    interrupts();
-}
-void loop()  {
+    attachInterrupt(Signals[0], ISR1_rise, RISING);
+    attachInterrupt(Signals[1], ISR2_rise, RISING);
+    attachInterrupt(Signals[2], ISR3_rise, RISING);
+    attachInterrupt(Signals[3], ISR4_rise, RISING);
+    attachInterrupt(Signals[4], ISR5_rise, RISING);
+    attachInterrupt(Signals[5], ISR6_rise, RISING);
+}
+void loop() {
     unsigned long Start_us = micros();

     startCapturingRCState();

     unsigned long local_results[7];
-    while (rc_state != RC_DONE)
-        ;
+    while (!(RC_Done[2] == 1&& RC_Done[3] == 1&& RC_Done[4] == 1&& RC_Done[5] == 1&& RC_Done[6] == 1))
+    ;
     // got data;
     rc_state = RC_WAIT;  // ignore pulses on data line.
     for (int i = 0; i < 8; i++)
@@ -140,7 +244,7 @@
     unsigned long Elapsed_us = micros() - Start_us;
     Serial.print(Start_us);      Serial.print("\t");
     Serial.print(Elapsed_us);    Serial.print("\t");
-    Serial.print(local_results[0]); Serial.print("\t");
+    Serial.print(local_results[0]);  Serial.print("\t");
     Serial.print(local_results[1]); Serial.print("\t");
     Serial.print(local_results[2]); Serial.print("\t");
     Serial.print(local_results[3]); Serial.print("\t");
@@ -149,89 +253,112 @@
     Serial.println(local_results[6]);

     processRC(local_results);
+    delay(200);
 }

 void startCapturingRCState()
 {
-  synced = false;
-  rc_index = 1;
-  rc_state = RC_PROCESSING;
-}
-
+  for (int i = 1; i < 7; i++) {
+    RC_Done[i] = 0;
+  }
+}
+
+// processRC modified by TCF  9/17/15
 void processRC (unsigned long *RC_results)
 {
     // 1st pulse is aileron (position 5 on receiver; controlled by Right left/right joystick on transmitter)
     //     used for Steering
-    int aileron = RC_results[1];
-    RC_results[1] = liveTurn(aileron)? convertTurn(aileron): STRAIGHT_TURN_OUT;
+    int aileron = RC_results[RC_TURN];
+//    RC_results[RC_TURN] = liveTurn(aileron)? convertTurn(aileron): STRAIGHT_TURN_OUT;
+    RC_results[RC_TURN] = convertTurn(aileron);

     /* 2nd pulse is aux (position 1 on receiver; controlled by flap/gyro toggle on transmitter)
        will be used for selecting remote control or autonomous control. */
-    RC_results[2] = (RC_results[2] > MIDDLE? HIGH: LOW);
+    if (NUMBER_CHANNELS > 5)
+        RC_results[RC_AUTO] = (RC_results[RC_AUTO] > MIDDLE? HIGH: LOW);

     /* 4th pulse is gear (position 2 on receiver; controlled by gear/mode toggle on transmitter)
     will be used for emergency stop. D38 */
-    RC_results[4] = (RC_results[4] > MIDDLE? HIGH: LOW);
-
-    if (RC_results[4] == HIGH)
+    RC_results[RC_ESTP] = (RC_results[RC_ESTP] > MIDDLE? HIGH: LOW);
+
+    if (RC_results[RC_ESTP] == HIGH)
     {
         E_Stop();
-        if (RC_results[2] == HIGH) // under RC control
-            steer(RC_results[1]);
+        if (RC_results[RC_AUTO] == HIGH  && NUMBER_CHANNELS > 5) // under RC control
+            steer(RC_results[RC_TURN]);
         return;
     }
-    if ( RC_results[2] == LOW)
+    if ( RC_results[RC_AUTO] == LOW  && NUMBER_CHANNELS > 5)
         return;  // not under RC control

     /*  6th pulse is marked throttle (position 6 on receiver; controlled by Left up/down joystick on transmitter).
     It will be used for shifting from Drive to Reverse . D40
     */
-    RC_results[6] = (RC_results[6] > MIDDLE? HIGH: LOW);
+    RC_results[RC_RVS] = (RC_results[RC_RVS] > MIDDLE? HIGH: LOW);

-// TO DO: Select Forward / reverse based on RC_results[6]
+// TO DO: Select Forward / reverse based on RC_results[RC_RVS]

     /*   3rd pulse is elevator (position 4 on receiver; controlled by Right up/down.
        will be used for throttle/brake: RC_Throttle
     */
     // Braking or Throttle
-    if (liveBrake(RC_results[3]))
-        brake(convertTurn(RC_results[3]));
+    if (liveBrake(RC_results[RC_GO]))
+        brake(convertBrake(RC_results[RC_GO]));
     else
         brake(MIN_BRAKE_OUT);
     //Accelerating
-    if(liveThrottle(RC_results[3]))
-        moveVehicle(RC_results[3]);
+    if(liveThrottle(RC_results[RC_GO]))
+        moveVehicle(RC_results[RC_GO]);
     else
         moveVehicle(MIN_ACC_OUT);

-    steer(RC_results[1]);
+    steer(RC_results[RC_TURN]);

     /* 5th pulse is rudder (position 3 on receiver; controlled by Left left/right joystick on transmitter)
     Not used */
-    RC_results[5] = (RC_results[5] > MIDDLE? HIGH: LOW);  // could be analog
-
-}
-//Converts RC values to corresponding values for the DAC
+    RC_results[RC_RDR] = (RC_results[RC_RDR] > MIDDLE? HIGH: LOW);  // could be analog
+
+}
+//Converts RC values to corresponding values for the PWM output
 int convertTurn(int input)
 {
-      //full turn right = 250, full turn left = 126
-      int dacRange = RIGHT_TURN_OUT - LEFT_TURN_OUT;
-      int rcRange = MAX_RC - MIN_RC;
-      input-= MIN_RC;
-      // TO DO: No doubles
-      double output = (double)input /(double)rcRange;
-      //swap left and right
-      output = 1 - output;
-      output *= dacRange;
-      output += LEFT_TURN_OUT;
-      //set max and min values if out of range
-      int trueOut = (int)output;
-      if(trueOut > RIGHT_TURN_OUT)
-          trueOut = RIGHT_TURN_OUT;
-      else if(trueOut < LEFT_TURN_OUT)
-          trueOut = LEFT_TURN_OUT;
-      return trueOut;
+     long int steerRange, rcRange;
+     long output;
+     int trueOut;
+//  Check if Input is in steer dead zone
+      if (input <= MIDDLE + DEAD_ZONE && input >= MIDDLE - DEAD_ZONE)
+       return STRAIGHT_TURN_OUT;
+       // MIN_RC = 1 msec = right; MAX_RC = 2 msec = left
+      // LEFT_TURN_OUT > RIGHT_TURN_OUT
+      if (input > MIDDLE + DEAD_ZONE)
+      {  // left turn
+         steerRange = LEFT_TURN_OUT - STRAIGHT_TURN_OUT;
+         rcRange = MAX_RC - (MIDDLE + DEAD_ZONE);
+        input-= MIDDLE + DEAD_ZONE;
+        output = STRAIGHT_TURN_OUT + input * steerRange / rcRange;
+        //set max and min values if out of range
+        trueOut = (int)output;
+        if(trueOut > LEFT_TURN_OUT)
+            trueOut = LEFT_TURN_OUT;
+        if(trueOut < STRAIGHT_TURN_OUT)
+            trueOut = STRAIGHT_TURN_OUT;
+        return trueOut;
+    }
+      if (input < MIDDLE - DEAD_ZONE)
+      {  // right turn
+         steerRange = STRAIGHT_TURN_OUT - RIGHT_TURN_OUT;
+         rcRange = MIDDLE - DEAD_ZONE - MIN_RC;
+        input = input - DEAD_ZONE - MIDDLE;  // input is negative
+        output = STRAIGHT_TURN_OUT + input * steerRange / rcRange;
+        //set max and min values if out of range
+        trueOut = (int)output;
+        if(trueOut < RIGHT_TURN_OUT)
+            trueOut = RIGHT_TURN_OUT;
+        if(trueOut > STRAIGHT_TURN_OUT)
+            trueOut = STRAIGHT_TURN_OUT;
+        return trueOut;
+    }
 }
 int convertBrake(int input)
 {
@@ -264,11 +391,6 @@
       return trueOut;
 }
 //Tests for inputs
-// Input is not in steer dead zone
-boolean liveTurn(int turn)
-{
-      return (turn > MIDDLE + DEAD_ZONE || turn < MIDDLE - DEAD_ZONE);
-}
 // Input not in throttle dead zone
 boolean liveThrottle(int acc)
 {
@@ -294,19 +416,6 @@
 void brake(int amount)
 {
       analogWrite(BRAKE_OUT_PIN, amount);
-}
-void moveVehicle(int acc)
-{
-      /* Observed behavior on ElCano #1 E-bike no load (May 10, 2013, TCF)
-      0.831 V at rest 52 counts
-      1.20 V: nothing 75
-      1.27 V: just starting 79
-      1.40 V: slow, steady 87
-      1.50 V: brisker 94
-      3.63 V: max 227 counts
-      255 counts = 4.08 V
-      */
-      DAC_Write(3, acc);
 }
 /*---------------------------------------------------------------------------------------*/
 /* DAC_Write applies value to address, producing an analog voltage.
@@ -367,3 +476,16 @@
           digitalWrite(SelectCD,HIGH);
       }
 }
+void moveVehicle(int acc)
+{
+      /* Observed behavior on ElCano #1 E-bike no load (May 10, 2013, TCF)
+      0.831 V at rest 52 counts
+      1.20 V: nothing 75
+      1.27 V: just starting 79
+      1.40 V: slow, steady 87
+      1.50 V: brisker 94
+      3.63 V: max 227 counts
+      255 counts = 4.08 V
+      */
+      DAC_Write(DAC_CHANNEL, acc);
+}


Using light sleep

Using light sleep

--- ESP32/ble_button/ble_button.ino
+++ ESP32/ble_button/ble_button.ino
@@ -8,6 +8,7 @@

 #define INPUT_PIN 0
 #define DEBOUNCE_TIME_MILLIS 50
+#define SLEEP_TIME_MILLIS 10000

 BLEServer* pServer = NULL;
 BLECharacteristic* pCharacteristic = NULL;
@@ -15,10 +16,47 @@
 bool connected = false;
 bool pendingValue = false;

+unsigned long lastEvent = 0;
+
+
+bool notify(){
+  bool notified = false;
+  if(connected == true){
+    delay(500); //Wait for stable connection
+    // Read input and store
+    uint8_t value =  0;
+    if(digitalRead(INPUT_PIN) == LOW){
+      value = 1;
+    }
+
+    // Send 1 byte of data with value
+    pCharacteristic->setValue((uint8_t*)&value, 1);
+    pCharacteristic->notify();
+    Serial.println("Notification sent");
+    notified = true;
+  }
+  else{
+    Serial.println("Value not sent. Not connected.");
+  }
+  return notified;
+}
+

 class BLECallback: public BLEServerCallbacks {
     void onConnect(BLEServer* pServer) {
       Serial.println("Connected");
+//      esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL0, ESP_PWR_LVL_N12);
+//      esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL1, ESP_PWR_LVL_N12);
+//      esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL2, ESP_PWR_LVL_N12);
+//      esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL3, ESP_PWR_LVL_N12);
+//      esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL4, ESP_PWR_LVL_N12);
+//      esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL5, ESP_PWR_LVL_N12);
+//      esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL6, ESP_PWR_LVL_N12);
+//      esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL7, ESP_PWR_LVL_N12);
+//      esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL8, ESP_PWR_LVL_N12);
+//      esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV, ESP_PWR_LVL_N12);
+//      esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_SCAN, ESP_PWR_LVL_N12);
+//      esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, ESP_PWR_LVL_N12);
       connected = true;
     };

@@ -60,30 +98,18 @@
 }

-void notify(){
-  if(connected == true){
-    // Read input and store
-    uint8_t value =  0;
-    if(digitalRead(INPUT_PIN) == LOW){
-      value = 1;
-    }
-
-    // Send 1 byte of data with value
-    pCharacteristic->setValue((uint8_t*)&value, 1);
-    pCharacteristic->notify();
-    Serial.println("Notification sent");
-  }
-  else{
-    Serial.println("Value not sent. Not connected.");
-  }
-}
-
-void IRAM_ATTR onPinChanged(){
+void newValue(){
   pendingValue = true;
+  lastEvent = millis();
 }

+void IRAM_ATTR onPinChanged(){
+  newValue();
+}
+
 void setup() {
+  setCpuFrequencyMhz(80);
   Serial.begin(115200);

   // Set up BLE
@@ -97,12 +123,28 @@
 }

+void go_to_sleep(){
+  esp_sleep_enable_ext0_wakeup(GPIO_NUM_0,0);
+  Serial.println("Sleeping...");
+  delay(10);
+  esp_light_sleep_start();
+  Serial.println("Woken up");
+  connected = false;
+  newValue();
+}
+
+
 void loop() {
-  if(pendingValue == true){
+  while(pendingValue == true){
     // Wait for pin to stabilize
-    delay(DEBOUNCE_TIME_MILLIS);
-    notify();
-    pendingValue = false;
+    delay(100);
+    if(notify()){
+      pendingValue = false;
+    }
   }
-  delay(10);
+  if(connected == true){
+    if(millis() - lastEvent > SLEEP_TIME_MILLIS){
+      go_to_sleep();
+    }
+  }
 }


Update SendPPGSignal.ino

Update SendPPGSignal.ino

--- SendPPGSignal/SendPPGSignal.ino
+++ SendPPGSignal/SendPPGSignal.ino
@@ -15,6 +15,6 @@
   int sensorValue = analogRead(PPG_INPUT); // A0

   Serial.println(sensorValue);
-  delay(50); // fs = 25 Hz (delay(5) -> fs = 200 Hz )
+  delay(50); // fs = 20 Hz (delay(5) -> fs = 200 Hz )
 }


More resiliency to spurious readouts and flaky WiFi

--- Particle/THLMqttSensor/src/THLMqttSensor.ino
+++ Particle/THLMqttSensor/src/THLMqttSensor.ino
@@ -56,7 +56,7 @@
   hum = dht.getHumidity();
   //dp = dht.getDewPoint();
   // Check if any reads failed and exit early
-  if (isnan(hum) || isnan(temp) || (temp > 60)) {
+  if (isnan(hum) || isnan(temp) || (temp > 60) || (temp < 10)) {
     return -1;
   }
   // apply a correction factor to the humidity reading, following
@@ -153,8 +153,8 @@
       "}";
   // make sure we're online, but give up after 10 seconds
   if(!waitFor(WiFi.ready, 10000)) {
-    // we failed to get online, try again after 2 seconds
-    lastReadoutTime = Time.now() - readoutTimeIntervalMins*60 + 2;
+    // we failed to get online, try again after 10 seconds
+    lastReadoutTime = Time.now() - readoutTimeIntervalMins*60 + 10;
     return -1;
   }
   // connect to the MQTT broker


implementando funcaoSimples, ciclo da mandíbula

--- EMP-B-Due.ino
+++ EMP-B-Due.ino
@@ -5,8 +5,8 @@
  Controlador de Empacotadeira com Arduino Due.
 */

-// Constantes
-// Entradas
+// CONSTANTES
+// ENTRADAS
 const byte bt_geral = 22;        // Entrada do botão de Liga/Desliga Geral
 const byte bt_dosador = 24;      // Entrada do botão de Liga/Desliga do Dosador
 const byte bt_datador = 26;      // Entrada do botão de Liga/Desliga do Datador
@@ -17,19 +17,21 @@
 const byte pot_solda_vertical = A0;    // Potenciômetro da Solda Vertical
 const byte pot_solda_horizontal = A1;  // Potenciômetro da Solda Vertical
 const byte pot_solda_datador = A2;     // Potenciômetro da Solda Vertical
-                                       // Saídas
-const byte geral = 40;                 // Saída Geral
-const byte dosador = 42;               // Saída do Dosador
-const byte datador = 44;               // Saída do Datador
-const byte solda_vertical = 33;        // Saída da Solda Vertical
-const byte solda_horizontal = 35;      // Saída da Solda Horizontal
-const byte solda_datador = 37;         // Saída da Solda do Datador
-const byte led_teste_1 = 23;
-const byte led_teste_2 = 25;
-const byte led_teste_3 = 27;
-
-// Variáveis
-// Configurações
+
+// SAÍDAS
+const byte geral = 23;                 // Saída Geral
+const byte dosador = 25;               // Saída do Dosador
+const byte datador = 27;               // Saída do Datador
+const byte mandibula = 40;
+const byte solda_vertical_PWM = 33;        // Saída da Solda Vertical
+const byte solda_horizontal_PWM = 35;      // Saída da Solda Horizontal
+const byte solda_datador_PWM = 37;         // Saída da Solda do Datador
+// REMOVER
+const byte saida_teste = 2;
+const byte entrada_teste = 4;
+
+// VARIÁVEIS
+// CONFIGURAÇÕES
 #define BOTAO INPUT_PULLUP  // INPUT ou INPUT_PULLUP
 #define SENSOR INPUT        // INPUT ou INPUT_PULLUP
 #define SAIDA OUTPUT
@@ -39,14 +41,17 @@
 #define DESLIGA LOW
 #define VERDADEIRO true
 #define FALSO false
-// Nomes de Funções
+
+// NOMES DE FUNÇÕES
 #define NomeGeral "Geral"
 #define NomeDosador "Dosador"
 #define NomeDatador "Datador"
+#define NomeMandibula "Mandibula"
 #define NomeSoldaVertical "Solda Vertical"
 #define NomeSoldaHorizontal "Solda Horizontal"
 #define NomeSoldaDatador "Solda Datador"
-// Botões de Entrada Um Clique
+
+// BOTOÕES UM-CLIQUE
 unsigned long atraso = 50;
 int estbt_geral;                // Estado do Botão Geral
 int estbta_geral = BAIXO;       // Estado anterior do Botão Geral
@@ -57,12 +62,14 @@
 int estbt_datador;              // Estado do Botão Datador
 int estbta_datador = BAIXO;     // Estado anterior do Botão Dosador
 unsigned long atr_datador = 0;  // Atraso do Botão Dosador
-// PWM das Soldas
+
+// PWM DAS SOLDAS
 const unsigned long ciclo_PWM = 1000;
 unsigned long tempo_PWM_vertical = 0;    // Tempo do PWM da solda vertical
 unsigned long tempo_PWM_horizontal = 0;  // Tempo do PWM da solda horizontal
 unsigned long tempo_PWM_datador = 0;     // Tempo do PWM da solda do Datador
-// Programa
+
+// MODOS DE TRABALHO
 boolean stand_by = FALSO;
 boolean maquina_ligada = FALSO;
 boolean dosador_ligado = FALSO;
@@ -72,9 +79,12 @@
 boolean fotocelula_cortou = FALSO;
 boolean produzindo = FALSO;
 boolean resetado = FALSO;
-// Tempos do Ciclo
-// Ciclo
+
+// TEMPOS DE CICLO
+// CONTROLE DE CICLO
+unsigned long tempo_atual = millis();
 unsigned long ciclo_padrao = 1500;
+unsigned long ciclo_padrao_anterior = ciclo_padrao;
 unsigned long inicio_ciclo = 0;
 unsigned long ciclo_minimo = 900;
 unsigned long ciclo_maximo = 2000;
@@ -83,65 +93,70 @@
 unsigned long fim_ciclo = 0;
 unsigned long minimo = 0;
 unsigned long maximo = 0;
-// Mandibula
+
+// MANDÍBULA
 unsigned long inicio_mandibula = 550;
 unsigned long fim_mandibula = 1500;
-// Fotocélula
+
+// FOTOCÉLULA
 unsigned long inicio_fotocelula = 1250;
 unsigned long fim_fotocelula = 1400;
-// Faca
+
+// FACA
 unsigned long inicio_faca = 600;
 unsigned long fim_faca = 800;
-// Refrigeração
+
+// REFRIGERAÇÃO
 unsigned long inicio_refrigeracao = 800;
 unsigned long fim_refrigeracao = 1450;
-// Datador
+
+// DATADOR
 unsigned long inicio_datador = 0;
 unsigned long fim_datador = 400;
-// Solda Vertical
+
+// SOLDAS VERTICAL E HORIZONTAL
 unsigned long inicio_soldas = 0;
 unsigned long fim_soldas = 400;

 void setup() {
   Serial.begin(9600);
-  // Botões
+  // BOTÕES
   pinMode(bt_geral, BOTAO);
   pinMode(bt_dosador, BOTAO);
   pinMode(bt_datador, BOTAO);
   pinMode(sensor_reset, BOTAO);  // Mudar para Sensor após os testes.
-  // Potenciômetros das Soldas
+  // POTENCIÔMETROS DAS SOLDAS
   pinMode(pot_solda_vertical, SENSOR);
   pinMode(pot_solda_horizontal, SENSOR);
   pinMode(pot_solda_datador, SENSOR);
-  // Saídas PWM das Soldas
-  pinMode(solda_vertical, SAIDA);
-  pinMode(solda_horizontal, SAIDA);
-  pinMode(solda_datador, SAIDA);
-  // Sensores
+  // SAÍDAS PWM DAS SOLDAS
+  pinMode(mandibula, SAIDA);
+  pinMode(solda_vertical_PWM, SAIDA);
+  pinMode(solda_horizontal_PWM, SAIDA);
+  pinMode(solda_datador_PWM, SAIDA);
+  // SENSORES
   pinMode(sensor_porta, BOTAO);
   pinMode(sensor_painel, BOTAO);
   pinMode(sensor_maquina, BOTAO);

+  // REMOVER
+  pinMode(saida_teste, SAIDA);
+
+
   pinMode(geral, SAIDA);
   pinMode(dosador, SAIDA);
   pinMode(datador, SAIDA);
-  pinMode(led_teste_1, SAIDA);
-  pinMode(led_teste_2, SAIDA);
-  pinMode(led_teste_3, SAIDA);
-
-  // Define estado inicial das saídas
+
+  // ESTADO INICIAL DAS SAÍDAS
   resetCompleto();
 }

 void loop() {
   modoAlarme();

-  geraPWM(pot_solda_vertical, &tempo_PWM_vertical, solda_vertical,
-          NomeSoldaVertical);
-  geraPWM(pot_solda_horizontal, &tempo_PWM_horizontal, solda_horizontal,
-          NomeSoldaHorizontal);
-  geraPWM(pot_solda_datador, &tempo_PWM_datador, solda_datador,
-          NomeSoldaDatador);
+  geraPWM(pot_solda_vertical, &tempo_PWM_vertical, solda_vertical_PWM);
+  geraPWM(pot_solda_horizontal, &tempo_PWM_horizontal, solda_horizontal_PWM);
+  geraPWM(pot_solda_datador, &tempo_PWM_datador, solda_datador_PWM);

   if (!alarme_ativo) {
     standBy();
@@ -175,8 +190,8 @@
     reiniciaCiclo(millis());
   }
   if (conta_ciclos >= 3) {
-    ligaFuncao(led_teste_1, "Led Teste 1");  // Exemplo para teste.
-                                             // ciclo de trabalho
+    funcaoSimples(mandibula, NomeMandibula, inicio_mandibula, fim_mandibula);
+    funcaoSimples(saida_teste, "Teste", 1500, 1501);
   }
   funcaoReset();
 }
@@ -221,12 +236,13 @@
 }

 void funcaoReset() {
-  unsigned long tempo_atual = millis();
+  tempo_atual = millis();
   if (resetado){
     fim_ciclo = inicio_ciclo + ciclo_padrao;
     minimo = inicio_ciclo + ciclo_minimo;
     maximo = inicio_ciclo + ciclo_maximo;
     resetado = FALSO;
+    reiniciaSaidas();
   }

   if (tempo_atual >= minimo) {
@@ -252,11 +268,13 @@

 void cicloMedio() {
   if (conta_ciclos > 0) {
+    ciclo_padrao_anterior = ciclo_padrao;
     ciclo_padrao = soma_ciclos / conta_ciclos;
-  }
-}
-
-void geraPWM(byte pot, unsigned long *inicio, byte saida, String nome) {
+    inicio_mandibula *= (long)((float)ciclo_padrao_anterior / (float)ciclo_padrao);
+  }
+}
+
+void geraPWM(byte pot, unsigned long *inicio, byte saida) {
   unsigned long ativo = map(analogRead(pot), 0, 1023, 0, ciclo_PWM);
   unsigned long inativo = ciclo_PWM - ativo;
   if (maquina_ligada && !alarme_ativo) {
@@ -273,16 +291,32 @@
   }
 }

+// FUNÇÕES DE CICLO
+
+void funcaoSimples(const byte saida, String nome, unsigned long inicio, unsigned long fim) {
+  inicio += inicio_ciclo;
+  fim += inicio_ciclo;
+  if ((tempo_atual >= inicio) && (tempo_atual < fim) && desligado(saida)) {
+    ligaFuncao(saida, nome);
+  } else if (tempo_atual >= fim) {
+    desligaFuncao(saida, nome);
+  }
+}
+
 // FERRAMENTAS AUXILIARES

 byte leEntrada(byte pino) { return digitalRead(pino); }

 void liga(byte saida) { digitalWrite(saida, LIGA); }

-void ligaFuncao(byte saida, String texto) {
+void ligaFuncao(byte saida, String nome) {
   if (desligado(saida)) {
     liga(saida);
-    escreveSerial(texto + " Ligado.");
+    if (ligado(saida)){
+      escreveSerial(nome + " Ligado.");
+    } else {
+      escreveSerial("Ocorreu um erro ao ligar " + nome);
+    }
   }
 }

@@ -352,31 +386,23 @@
 }

 void reiniciaSaidas() {
+  desligaFuncao(dosador, NomeDosador);
+  desligaFuncao(datador, NomeDatador);
+  desligaFuncao(mandibula, NomeMandibula);
+}
+
+void resetCompleto() {
   dosador_ligado = FALSO;
   datador_ligado = FALSO;
   conta_ciclos = 0;
-
-  desligaFuncao(geral, NomeGeral);
-  desligaFuncao(dosador, NomeDosador);
-  desligaFuncao(datador, NomeDatador);
-
-  desliga(led_teste_1);  // Para testes
-  desliga(led_teste_2);  // Para testes
-  desliga(led_teste_3);  // Para testes
-}
-
-void resetCompleto() {
   desliga(geral);
   desliga(dosador);
   desliga(datador);
-
-  desliga(solda_vertical);
-  desliga(solda_horizontal);
-  desliga(solda_datador);
-
-  desliga(led_teste_1);  // Para testes
-  desliga(led_teste_2);  // Para testes
-  desliga(led_teste_3);  // Para testes
+  desliga(mandibula);
+
+  desliga(solda_vertical_PWM);
+  desliga(solda_horizontal_PWM);
+  desliga(solda_datador_PWM);
 }

 void modoTeste() {


모드 변경 기능 추가 RGB LED로 교

모드 변경 기능 추가
RGB LED로 교

--- src/footswitch/footswitch.ino
+++ src/footswitch/footswitch.ino
@@ -5,13 +5,27 @@
 const int KEYCODE_A = 0x04;
 const int KEYCODE_B = 0x05;

+const int KEYCODE_F8 = 0x41;
+const int KEYCODE_F9 = 0x42;
+
+const int KEYCODE_SPACE = 0x2c;

 const int pedalPin1 = 2;
 const int pedalPin2 = 3;
-const int ledPin1 = 4;
+const int ledRedPin = 4;
+const int ledGreenPin = 5;
+const int ledBluePin = 6;
+const int modeButtonPin = 7;
+
+const int MODE_EMACS = 0;
+const int MODE_INTELLIJ = 1;
+const int MODE_INTERNET = 2;

 int lastPedalEvent1 = 0;
 int lastPedalEvent2 = 0;
+int lastModeEvent = 1;
+
+int mode = 3;

 int DBG_MODE = 0;

@@ -21,7 +35,10 @@
   Serial.begin(9600);
   pinMode(pedalPin1, INPUT);
   pinMode(pedalPin2, INPUT);
-  pinMode(ledPin1, OUTPUT);
+  pinMode(ledRedPin, OUTPUT);
+  pinMode(ledGreenPin, OUTPUT);
+  pinMode(ledBluePin, OUTPUT);
+  pinMode(modeButtonPin, INPUT);

 }

@@ -30,22 +47,87 @@
   int pedalEvent1 = digitalRead(pedalPin1);
   int pedalEvent2 = digitalRead(pedalPin2);

+  int modeButtonEvent = digitalRead(modeButtonPin);
+
+
+  if(lastModeEvent != modeButtonEvent) {
+    if(modeButtonEvent == HIGH) {
+      mode = (mode+1)%3;
+      if(DBG_MODE) {
+        Serial.print("mode:");
+        Serial.println(mode);
+      }
+    switch(mode) {
+      case MODE_EMACS:
+        setColor(50, 0, 0);
+      break;
+      case MODE_INTELLIJ:
+        setColor(0, 50, 0);
+      break;
+      case MODE_INTERNET:
+        setColor(0, 0, 50);
+      break;
+    }
+      delay(50);
+    }
+    lastModeEvent = modeButtonEvent;
+  }
+
   if((lastPedalEvent1 == pedalEvent1) && (lastPedalEvent2 == pedalEvent2)) {
     return;
   }

   if((pedalEvent1 == HIGH) || (pedalEvent2 == HIGH)) {
-    if(pedalEvent1 == HIGH) input(KEYCODE_A);
-    if(pedalEvent2 == HIGH) input(KEYCODE_B);
+    if(pedalEvent1 == HIGH) input(getLeftInput());
+    if(pedalEvent2 == HIGH) input(getRightInput());
     lastPedalEvent1 = pedalEvent1;
     lastPedalEvent2 = pedalEvent2;
-    digitalWrite(ledPin1, HIGH);
+    setColor(50, 50, 0);
   } else {
     releaseKey();
     lastPedalEvent1 = pedalEvent1;
     lastPedalEvent2 = pedalEvent2;
-    digitalWrite(ledPin1, LOW);
+    setColor(0, 0, 0);
   }
+}
+
+void setColor(int red, int green, int blue)
+{
+  analogWrite(ledRedPin, red);
+  analogWrite(ledGreenPin, green);
+  analogWrite(ledBluePin, blue);
+}
+
+int getLeftInput() {
+  int keycode = LEFT_CTRL;
+  switch(mode) {
+    case MODE_EMACS:
+      keycode = LEFT_CTRL;
+    break;
+    case MODE_INTELLIJ:
+      keycode = KEYCODE_F8;
+    break;
+    case MODE_INTERNET:
+      keycode = KEYCODE_SPACE;
+    break;
+  }
+  return keycode;
+}
+
+int getRightInput() {
+  int keycode = LEFT_ALT;
+  switch(mode) {
+    case MODE_EMACS:
+      keycode = LEFT_ALT;
+    break;
+    case MODE_INTELLIJ:
+      keycode = KEYCODE_F9;
+    break;
+    case MODE_INTERNET:
+      keycode = KEYCODE_SPACE;
+    break;
+  }
+  return keycode;
 }

 void input(int keycode) {


Fixed the read 24-bit register problem.  CSB needs to be toggled after each register read.  This is still messy, but it's slowly starting to come to life.

--- TICC/TICC.ino
+++ TICC/TICC.ino
@@ -114,8 +114,13 @@
 	stopTime = 0;
 }

-unsigned long readReg24(uint8_t address) {
+unsigned long tdc7200Channel::readReg24(byte address) {
 	unsigned long value = 0;
+
+  // CSB needs to be toggled between 24-bit register reads
+
+  SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0));
+  digitalWrite(CSB, LOW);

 	SPI.transfer(address & 0x1f);

@@ -131,6 +136,9 @@
   int lsb = SPI.transfer(0x00);

   value = (msb << 16) + (mid << 8) + lsb;
+
+  digitalWrite(CSB, HIGH);
+  SPI.endTransaction();

 //  This clobbers the stack at runtime:
 //	SPI.transfer((uint8_t *) &value + 1, 3);
@@ -143,8 +151,8 @@
   //  Start a SPI transaction
   //  Max speed for the tdc7200 is 20MHz
   //  CPOL = 0; CPHA = 0
-  SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0));
-  digitalWrite(CSB, LOW);
+//  SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0));
+//  digitalWrite(CSB, LOW);

   time1Result = readReg24(TIME1);
   time2Result  = readReg24(TIME2);
@@ -174,8 +182,8 @@
   // inputs, these two 32 bits still won't overflow.
   tempu32 += clock1Result * CLOCK_PERIOD_PS;
   // return tempu32;
-  digitalWrite(CSB, HIGH);
-  SPI.endTransaction();
+//  digitalWrite(CSB, HIGH);
+//  SPI.endTransaction();

   return (long)tempu32;
 }


allowing for repetitive parsing with dynamic buffer

the DynamicJsonBuffer could be a potential source for error by taking
up too much memory. It works as of now.

--- SensorShirt/SensorShirt.ino
+++ SensorShirt/SensorShirt.ino
@@ -17,7 +17,9 @@
 int lUnderarmValue = -1;
 int rUnderarmValue = -1;

-StaticJsonBuffer<200> jsonBuffer;
+//Could potentially take up too much memory
+DynamicJsonBuffer jsonBuffer;
+boolean updated = false;

 void setup() {
   Serial.begin(9600);
@@ -45,17 +47,24 @@
   while(Serial.available()) {
       character = Serial.read();
       content.concat(character);
+      updated = true;
   }

-  if (content != "") {
-    Serial.println(content);
-    JsonObject& root = jsonBuffer.parseObject(const_cast<char*>(content.c_str()));
-
-    if (!root.success()) {
-      Serial.println("parseObject() failed");
-      return;
-    } else {
-      Serial.println("parseObject() succeeded");
-    }
+  if (updated) {
+    parseJSON(content);
   }
 }
+
+void parseJSON(String content) {
+  updated = false;
+  Serial.println(content);
+  JsonObject& root = jsonBuffer.parseObject(const_cast<char*>(content.c_str()));
+
+  if (!root.success()) {
+    Serial.println("parseObject() failed");
+    return;
+  } else {
+    Serial.println("parseObject() succeeded");
+  }
+  content = "";
+}


added blinkenlight to Nano

added blinkenlight to Nano

--- WheelwriterControlNano/WheelwriterControlNano.ino
+++ WheelwriterControlNano/WheelwriterControlNano.ino
@@ -113,6 +113,7 @@
           } else {
             charCount = printOne(command,charCount);
           }
+          digitalWrite(LED,0); // turn off LED when we are finished processing
       }
       // button for testing
       byte button = digitalRead(4);


Removing watchdog. Not used in this sketch.

--- examples/VWI/CosaVWImonitor/CosaVWImonitor.ino
+++ examples/VWI/CosaVWImonitor/CosaVWImonitor.ino
@@ -28,7 +28,6 @@
 #include "Cosa/VWI.hh"
 #include "Cosa/VWI/Codec/VirtualWireCodec.hh"
 #include "Cosa/Trace.hh"
-#include "Cosa/Watchdog.hh"
 #include "Cosa/IOStream/Driver/UART.hh"
 #include "Cosa/Memory.h"

@@ -40,7 +39,6 @@
   uart.begin(9600);
   trace.begin(&uart, PSTR("CosaVWImonitor: started"));
   TRACE(free_memory());
-  Watchdog::begin();
   VWI::begin(4000);
   rx.begin();
 }


Only show absolute values as results

Only show absolute values as results

--- examples/GyroErrorCalculator/GyroErrorCalculator.ino
+++ examples/GyroErrorCalculator/GyroErrorCalculator.ino
@@ -50,7 +50,7 @@

   // Print the baseline error
   Serial.print("Mean error: ");
-  printFloat(mean / 1000.0f, 6);
+  printFloat(fabs(mean / 1000.0f), 6);
   Serial.println(" rad/s");

   // Reset the mean to zero
@@ -88,7 +88,7 @@

   // Print out the bias
   Serial.print("Mean bias: ");
-  printFloat(mean / 1000.0f, 6);
+  printFloat(fabs(mean / 1000.0f), 6);
   Serial.println(" rad/s/s");

   // Bye


Temporary disabled SIM900A calls for training purposes

--- mwsIWMIv3/mwsIWMIv3.ino
+++ mwsIWMIv3/mwsIWMIv3.ino
@@ -30,19 +30,19 @@

 //This is for the 16x2 LCD
 //Most of them are using this
-//LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
+LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
 //Some use this PCF8574
-LiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
+//LiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

 //FOR GSM COMS
 GSM_Module Module(SIM900);// For SIM900 GSM
 //GSM_Module Module(SM5100B);// For SM5100B GSM
 String Mobile_No1 = "+94773709854";          // S. Mobile Number 1 which the SMS Sends
-String Mobile_No2 = "+94778351854";          // R. Mobile Number 2 which the SMS Sends
+String Mobile_No2 = "+94767201637";          // Y. Mobile Number 2 which the SMS Sends (temporary, plz remove)
 String Mobile_No3 = "+94776141305";          // L. Mobile Number 3 which the SMS Sends
 //String Mobile_No4 = "+94776141305";          // Mobile Number 4 which the SMS Sends
 //String Mobile_No5 = "+94776141305";          // Mobile Number 5 which the SMS Sends
-String Test_SMS  = "IWMIMWSv3 Station initializing";    // Test content of the SMS
+String Test_SMS  = "IWMI MWS v3 Station initializing";    // Test content of the SMS
 int Status;
 //PhP SERVER Definitions
 //String HOST      = "lahiruwije.ddns.net";   // Host name or address of the web server
@@ -258,22 +258,22 @@
   *****************************************************************************************************************/
   lcd.clear();
   lcd.print(F("Module Initializing.."));
-  Status = Module.Init(9600);
-  if( Status == OK ){
-    lcd.setCursor(0, 2);
-    lcd.print(F("Module Ready."));
-  }else{
-    lcd.setCursor(0, 2);
-    lcd.print(F("Module Initializing Failed."));
-    delay(1000);
-    lcd.clear();
-    lcd.print(F("ERROR : "));
-    lcd.setCursor(0, 2);
-    lcd.print(Status);
-    while(1){};
-  }
-  Module.Refresh();
-  delay(5000);
+  //Status = Module.Init(9600);
+  //if( Status == OK ){
+  //  lcd.setCursor(0, 2);
+  //  lcd.print(F("Module Ready."));
+  //}else{
+  //  lcd.setCursor(0, 2);
+  //  lcd.print(F("Module Initializing Failed."));
+  //  delay(1000);
+  //  lcd.clear();
+  //  lcd.print(F("ERROR : "));
+  //  lcd.setCursor(0, 2);
+  //  lcd.print(Status);
+  //  while(1){};
+  //}
+  //Module.Refresh();
+  //delay(5000);
   /*****************************************************************************************************************
     Finished Initializing the GSM module.
   *****************************************************************************************************************/
@@ -282,20 +282,20 @@
   *****************************************************************************************************************/
   lcd.clear();
   lcd.print(F("Sending a Test SMS"));
-  Status = Module.Send_SMS(Mobile_No1, Test_SMS);
-  Status = Module.Send_SMS(Mobile_No2, Test_SMS);
-  Status = Module.Send_SMS(Mobile_No3, Test_SMS);
-  //Status = Module.Send_SMS(Mobile_No4, Test_SMS);
-  //Status = Module.Send_SMS(Mobile_No5, Test_SMS);
-  if( Status == OK ){
-    lcd.setCursor(0, 2);
-    lcd.print(F("SMS Sent"));
-  }else{
-    lcd.clear();
-    lcd.print(F("SMS ERROR : "));
-    lcd.setCursor(0, 2);
-    lcd.print(Status);
-  }
+  //Status = Module.Send_SMS(Mobile_No1, Test_SMS);
+  //Status = Module.Send_SMS(Mobile_No2, Test_SMS);
+  //Status = Module.Send_SMS(Mobile_No3, Test_SMS);
+  ////Status = Module.Send_SMS(Mobile_No4, Test_SMS);
+  ////Status = Module.Send_SMS(Mobile_No5, Test_SMS);
+  //if( Status == OK ){
+  //  lcd.setCursor(0, 2);
+  //  lcd.print(F("SMS Sent"));
+  //}else{
+  //  lcd.clear();
+  //  lcd.print(F("SMS ERROR : "));
+  //  lcd.setCursor(0, 2);
+  //  lcd.print(Status);
+  //}
   /*****************************************************************************************************************
     Finished Sending a test SMS
   *****************************************************************************************************************/
@@ -339,7 +339,7 @@
     minutes = 0;
     //SMS Alert if hourly rain > 25 mm/h
     if(rainin > 25.0){
-      sendSMS();
+      //sendSMS();
     }
     //Hourly online reporting
     //Send temperature&humidity to PhP Server (to be enhanced)


Attempt to fix no-clockwise bug. Suspicion is that an invalid negative speed is being passed to driveClockwise.

--- src/SabertoothDriverROS/SabertoothDriverROS.ino
+++ src/SabertoothDriverROS/SabertoothDriverROS.ino
@@ -292,8 +292,8 @@
  */
 void articulateWheel(int motorID, int direction) {

-  int articulationSpeed = 50*direction*ARTICULATION_DRIVE_SPEED;
-  int wheelSpeed = 50*direction;
+  int articulationSpeed = 50*ARTICULATION_DRIVE_SPEED;
+  int wheelSpeed = 50;

   //TODO: Make a constant
   int articulationID = motorID + 6;


disable interrupts while reading rate values

--- sonytrackball/sonytrackball.ino
+++ sonytrackball/sonytrackball.ino
@@ -32,6 +32,10 @@
 }

 void loop() {
-  Serial.print (10000L/xRate);
+
+  noInterrupts();
+  long rate = xRate;
+  interrupts();
+  Serial.print (10000L/rate);
   Serial.println (dir);
 }


Updated for use with Stepper Motor and recieves correction factors from Raspberry Pi 3 UART.

--- software/Arduino/ServoController/ServoController.ino
+++ software/Arduino/ServoController/ServoController.ino
@@ -2,9 +2,9 @@
  * Arduino Uno Program - Controls Servo and Reads IMU                 *
  * Project: Eclipse Tracking (2017)                                   *
  * Version: 1.0 (3/18/2017)                                           *
- * Max Bowman / Jeremy Seeman                                         *
+ * Max Bowman / Jeremy Seeman / George Moe                            *
  **********************************************************************/
-#include <Servo.h>
+#include <Stepper.h>
 #include <Wire.h>
 #include <MsTimer2.h>
 #include <SparkFunLSM9DS1.h>
@@ -12,27 +12,27 @@

 // Declare global variables
 LSM9DS1 imu; // imu chip
-Servo xy; // x-y plane servo
+int stepperPins[] = {9, 10, 11, 12};
+int stepperSteps = 200;
+Stepper motor(stepperSteps, stepperPins[0], stepperPins[1], stepperPins[2], stepperPins[3]);

 int n = 10; // gyro sample
 int k = 200; // servo sample
 int j = 0; // keep track of what to sample
 float runningSum = 0;

-float oldVal = 90;
-float servoVal = 90; // initial value to set servo at
 bool int_flag = false; // interrupt flag for executing gyro read every 100 ms
 const int LED = 13; // indicator LED

+char ch[4]; // for receiving commands from Raspberry Pi 3
+
 void setup() {
-  Serial.begin(9600);
+  Serial.begin(115200);
   pinMode(LED, OUTPUT);
   setupIMU(); // set up hardware
+  motor.setSpeed(10);

   blinkLED(20, 10); // Let the use know everything initialized
-
-  xy.attach(3); // pro mini / uno pwm pin
-  xy.write(servoVal); // Start at a 90 degrees

   MsTimer2::set(n, a); // accepts ms argument
   MsTimer2::start(); // set up and start a timer interrupt
@@ -40,13 +40,22 @@
 }

 void loop() {
+  if (Serial.available() == 4) {
+    int correctionFactor = 0;
+    int neg = 0;
+    if (Serial.read() == '1') neg = 1;
+    correctionFactor += (Serial.read() - '0') * 100;
+    correctionFactor += (Serial.read() - '0') * 10;
+    correctionFactor += (Serial.read() - '0');
+    if (neg) correctionFactor -= 2 * correctionFactor;
+    rotateStepperBy(correctionFactor);
+  }
   if (int_flag) {
     j++;
     j %= k / n + 1;
     runningSum += n * readGyro() / 1000;
     if (j == 0) {
-      oldVal += runningSum;
-      xy.write(oldVal);
+      rotateStepperBy(-runningSum); // runningSum is the total theta change
       runningSum = 0;
     }
   }
@@ -65,9 +74,10 @@
   }
 }

-// For continous rotation servos
-void rotateTo(float deg) {
-
+// For stepper motors
+void rotateStepperBy(float deg) {
+  int steps = deg*5/9;
+  motor.step(steps);
 }

 float readGyro() {


check that usb is ready before sending

check that usb is ready before sending

--- gamecubecontroller.ino
+++ gamecubecontroller.ino
@@ -424,8 +424,10 @@
   if (dual)
     dual = (bool)receiveReport(&data2,1);
   DEBUG("joystick = "+String(data.joystickX)+","+String(data.joystickY));
-  inject(&Joystick, x360_1, injectors + injectionMode, &data, &exerciseMachine);
+
   if (USBComposite.isReady()) {
+    inject(&Joystick, x360_1, injectors + injectionMode, &data, &exerciseMachine);
+
     if (dual) {
        inject(&Joystick2, x360_2, injectors + injectionMode, &data2, &exerciseMachine);
     }


Ajout \n manquant sur info debug teleinfo

--- Logiciel/remora/remora.ino
+++ Logiciel/remora/remora.ino
@@ -161,15 +161,9 @@
     if (display_setup())
     {
       status |= STATUS_OLED ;
-      Serial.print("OLED OK!");
-
       // Splash screen
       display_splash();
     }
-    else
-    {
-      Serial.print("OLED non trouvé!");
-    }
   #endif

   #ifdef MOD_TELEINFO
@@ -177,25 +171,18 @@
     if (tinfo_setup(true))
     {
       status |= STATUS_TINFO;
-      Serial.print("Teleinfo OK!");
+      Serial.println("Teleinfo OK!");
     }
     else
     {
-      Serial.print("Teleinfo non fonctionelle!");
+      Serial.println("Teleinfo non fonctionelle!");
     }
   #endif

   #ifdef MOD_RF69
     // Initialisation RFM69 Module
     if ( rfm_setup())
-    {
       status |= STATUS_RFM ;
-      Serial.print("RFM69 OK!");
-    }
-    else
-    {
-    Serial.print("RFM69 non trouvé!");
-    }
   #endif

   // Led verte durant le test


Update RS485_UnoR3_Master.ino

Update RS485_UnoR3_Master.ino

--- rs485/RS485_UnoR3_Master.ino
+++ rs485/RS485_UnoR3_Master.ino
@@ -24,8 +24,9 @@

 void setup()
 {
-  modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS, 0, 1, 0);
-  modbus_construct(&packets[PACKET2], 1, PRESET_MULTIPLE_REGISTERS, 0, 1, 0);
+     modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS, 0, 1, 0);
+     modbus_construct(&packets[PACKET2], 1, PRESET_MULTIPLE_REGISTERS, 1, 1, 0);
+// modbus_construct(&packets[PACKET2], slaveID: 1, PRESET_MULTIPLE_REGISTERS, address_of_register: 1 , quantity_registers: 1, 0)

   modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);


Tidied up this

Tidied up this

--- src/SerialPrint/SerialPrint.ino
+++ src/SerialPrint/SerialPrint.ino
@@ -4,9 +4,9 @@
 OneWire oneWire(2); //connect data to pin 2
 DallasTemperature sensors(&oneWire);

-DeviceAddress black = { 0x28, 0xFF, 0x1A, 0xAA, 0x62, 0x15, 0x03, 0x20 };
-DeviceAddress red   = { 0x28, 0xFF, 0xA9, 0xB4, 0x62, 0x15, 0x03, 0x0C };
-DeviceAddress green = { 0x28, 0xFF, 0xF5, 0xB3, 0x62, 0x15, 0x03, 0x3E };
+DeviceAddress black = {0x28, 0xFF, 0x1A, 0xAA, 0x62, 0x15, 0x03, 0x20};
+DeviceAddress red   = {0x28, 0xFF, 0xA9, 0xB4, 0x62, 0x15, 0x03, 0x0C};
+DeviceAddress green = {0x28, 0xFF, 0xF5, 0xB3, 0x62, 0x15, 0x03, 0x3E};

 const int delayTime = 1000;


Simplifying comments

Simplifying comments

--- AndyMark_LED_Lightchaser_Example/AndyMark_LED_Lightchaser_Example.ino
+++ AndyMark_LED_Lightchaser_Example/AndyMark_LED_Lightchaser_Example.ino
@@ -21,7 +21,7 @@
 // Data pin that led data will be written out over
 #define DATA_PIN 11	//Green Wire

-// Clock pin only needed for SPI based chipsets
+// Clock pin SPI
 #define CLOCK_PIN 13  //Blue Wire

 // This is an array of leds.  One item for each led in your strip.


Added sensor begin and setResolution

Added sensor begin and setResolution

--- src/SerialPrint/SerialPrint.ino
+++ src/SerialPrint/SerialPrint.ino
@@ -10,6 +10,11 @@

 void setup() {

+
+  sensors.begin();
+  sensors.setResolution(black, 10);
+  sensors.setResolution(red, 10);
+  sensors.setResolution(green, 10;
 }

 void loop() {


freeze colors while button 1 is pressed

freeze colors while button 1 is pressed

--- super_freq/super_freq.ino
+++ super_freq/super_freq.ino
@@ -290,6 +290,11 @@
     // this line reserved for color palette pin
     button1State = digitalRead(button1Pin);

+    if (button1State == HIGH) {
+        // pauses the colors
+        return;
+    }
+
     // check if palette changed
     // Note: this equality will be changed when color palette chooser
     // is implemented


Remove stray line

Remove stray line

--- examples/ttn-otaa-network-time/ttn-otaa-network-time.ino
+++ examples/ttn-otaa-network-time/ttn-otaa-network-time.ino
@@ -194,7 +194,6 @@
 // Utility function for digital clock display: prints preceding colon and
 // leading 0
 void printDigits(int digits) {
-
     Serial.print(':');
     if (digits < 10) Serial.print('0');
     Serial.print(digits);


Added more comments to the led-mask.ino

Added more comments to the led-mask.ino

--- led-mask.ino
+++ led-mask.ino
@@ -6,16 +6,16 @@
 #include "neopixel/neopixel.h"

 // SYSTEM_MODE(AUTOMATIC);
-SYSTEM_MODE(SEMI_AUTOMATIC);
-
-#define PATTERN_INDEX_MAX 9
-#define DEBOUNCE_DELAY 300
+SYSTEM_MODE(SEMI_AUTOMATIC); // This stops the board from automatically searching for WiFi connectivity
+
+#define PATTERN_INDEX_MAX 9 // The maximum index allowed for the patterns
+#define DEBOUNCE_DELAY 300 // The delay for the debouncing of the button to stop false positives

 #define LED_PIN D3
 #define TOGGLE_PIN D2
 #define WIFI_PIN D1

-// IMPORTANT: Set pixel COUNT, PIN and TYPE
+// IMPORTANT: Set Pixel PIN, COUNT, and TYPE
 #define PIXEL_PIN A5
 #define PIXEL_COUNT 120
 #define PIXEL_TYPE WS2812B
@@ -37,67 +37,67 @@
 ------------------------------115---116---117---118---119------------------------------ // 5
 */

-int patternIndex = 0; // This is the index to which pattern to play
+int patternIndex = 0; // This is the index to select which pattern to play
 bool patternToggled = true; // Every function must check this between frames in order to allow for a quick response to the button
-unsigned long lastDebounceTime;
-
-void setup()
+unsigned long lastDebounceTime; // The last time when the button was triggered
+
+void setup()
 {
     attachInterrupt(TOGGLE_PIN, togglePattern, FALLING); // This will allow you to create a button that triggers the patternChange
     attachInterrupt(WIFI_PIN, connect, CHANGE); // This will allow you to create switch that triggers the WiFi connection call
-
-    strip.begin();
+
+    strip.begin(); // Sends the start protocol for the LEDs.
     strip.show(); // Initialize all pixels to 'off'
-    strip.setBrightness(10);
-}
-
-void loop()
+    strip.setBrightness(10); // Stops the LEDs from being blinding
+}
+
+void loop()
 {
     // Unfortunately, particle's build doesn't currently allow for function pointers,
     // so we'll have to do a simple switch case
     switch(patternIndex)
     {
         case 0:
-            rainbow(20);
+            rainbow(20); // generic rainbow pattern
             break;
         case 1:
-            bucktoothJack();
+            bucktoothJack(); // an orange jack-o-lantern pattern
             break;
         case 2:
-            subzero();
+            subzero(); // a blue subzero pattern
             break;
         case 3:
-            winter(200);
+            winter(200); // random white pixels around a christmas tree
             break;
         case 4:
-            rainyWeather(200);
+            rainyWeather(200); // random blue pixels
             break;
         case 5:
-            heartAnimation(200);
+            heartAnimation(200); // an animating red heart
             break;
         case 6:
-            smile();
+            smile(); // a mask in white with a smile
             break;
         case 7:
-            hi();
+            hi(); // shows 'hi'
             break;
         case 8:
-            bye();
+            bye(); // shows 'bye'
             break;
         case 9:
-            rainbowMask();
+            rainbowMask(); // a rainbow mask similar to subzeros
             break;
         default:
             rainbow(20);
             break;
     }
-
+
     if(patternToggled){
         patternToggled = false;
     }
 }

-// Pretends that it is a 30 by 15 Matrix
+// Pretends that it is a 30 by 15 Matrix and maps to the correct pixels
 uint16_t customMappingFunction (uint16_t x, uint16_t y){
     if(x > 28 || y > 10)
     {
@@ -117,7 +117,7 @@
     countInRow[8] = 9;
     countInRow[9] = 6;
     countInRow[10] = 5;
-
+
     int numSpacersPerSide = maxCountInRow - countInRow[y];
     if(((y % 2) == 0) && ((x % 2) == 0)) // this means that it's an even row, so all odd pixels are dropped in the row.
     {
@@ -133,13 +133,13 @@
         {
             return 11*15-1;
         }
-
+
         leftover = leftover / 2; // divides by two due to the dropping

         if(leftover >= countInRow[y]){ // Also, drop the spacers on the right side
              return 11*15-1;
         }
-
+
         return leftover + pixelCount;
     }else if(((y % 2) > 0) && ((x % 2) > 0)){  // this means that it's an odd row, so all even pixels are dropped in the row
         // count up the number of pixels in the rows prior
@@ -154,19 +154,20 @@
         {
             return 11*15-1;
         }
-
+
         leftover = leftover / 2; // divides by two due to the dropping
-
+
         if(leftover >= countInRow[y]){ // Also, drop the spacers on the right side
              return 11*15-1;
         }
-
+
         return countInRow[y] - leftover + pixelCount-1;
     }else{ // it's a dropped pixel so forget it
         return 11*15-1;
     }
 }

+// Signals the stop of the pattern and increments the pattern index
 void togglePattern(){
     if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY) //if current time minus the last trigger time is greater than
     {                                                  //the delay (debounce) time, button is completley closed.
@@ -182,6 +183,7 @@
     }
 }

+// Attempts to connect using the normal WiFi connectivity capabilities
 void connect() {
     strip.setBrightness(30);
     if (Spark.connected() == false) {
@@ -189,6 +191,7 @@
     }
 }

+// Fills from the start pixel, to the finish pixel with the color
 void fillFrom(uint16_t start, uint16_t finish, uint32_t color)
 {
     uint16_t i;
@@ -200,7 +203,7 @@

 void rainbow(uint8_t wait) {
     uint16_t i, j;
-
+
     for(j=0; j<256 && !patternToggled; j++) {
         for(i=0; i<strip.numPixels(); i++) {
             strip.setPixelColor(i, Wheel((i+j) & 255));
@@ -230,11 +233,11 @@
         xsmallHeart();
         strip.show();
         delay(wait*2);
-
+
         smallHeart();
         strip.show();
-        delay(wait);
-
+        delay(wait);
+
         bigHeart();
         strip.show();
         delay(wait*2);
@@ -244,57 +247,57 @@
 void xsmallHeart()
 {
     strip.clear();
-
+
     fillFrom(48, 49, strip.Color(255, 0, 0));
     fillFrom(46, 47, strip.Color(255, 0, 0));
-
+
     strip.setPixelColor(104, strip.Color(255, 0, 0));
-
+
     fillFrom(94, 95, strip.Color(255, 0, 0));
-
+
     fillFrom(83, 85, strip.Color(255, 0, 0));
-
+
     fillFrom(71, 74, strip.Color(255, 0, 0));
-
+
     fillFrom(58, 62, strip.Color(255, 0, 0));
 }

 void smallHeart()
 {
     strip.clear();
-
+
     strip.setPixelColor(117, strip.Color(255, 0, 0));
-
+
     strip.setPixelColor(33, strip.Color(255, 0, 0));
     strip.setPixelColor(34, strip.Color(255, 0, 0));
-
+
     fillFrom(48, 50, strip.Color(255, 0, 0));
-
+
     strip.setPixelColor(60, strip.Color(255, 0, 0));
-
+
     strip.setPixelColor(111, strip.Color(255, 0, 0));
     strip.setPixelColor(112, strip.Color(255, 0, 0));
-
+
     fillFrom(103, 105, strip.Color(255, 0, 0));
-
+
     fillFrom(93, 96, strip.Color(255, 0, 0));
-
+
     fillFrom(82, 86, strip.Color(255, 0, 0));
-
+
     fillFrom(70, 75, strip.Color(255, 0, 0));
-
+
     strip.setPixelColor(37, strip.Color(255, 0, 0));
     strip.setPixelColor(36, strip.Color(255, 0, 0));
-
+
     fillFrom(45, 47, strip.Color(255, 0, 0));
-
+
     fillFrom(58, 62, strip.Color(255, 0, 0));
 }

 void bigHeart()
 {
     strip.clear();
-
+
     fillFrom(4, 5, strip.Color(255, 0, 0));
     fillFrom(9, 10, strip.Color(255, 0, 0));
     fillFrom(18, 20, strip.Color(255, 0, 0));
@@ -533,7 +536,7 @@

 void winter(int delayAmount){
     strip.clear();
-
+
     for(int i = 0; i<40; i++)
     {
         strip.setPixelColor(random(120), strip.Color(255, 255, 255));
@@ -570,7 +573,7 @@

 void rainyWeather(int delayAmount){
     strip.clear();
-
+
     for(int i = 0; i<40; i++)
     {
         strip.setPixelColor(random(120), strip.Color(57, 78, 215));
@@ -954,4 +957,4 @@
     strip.setPixelColor(customMappingFunction(26, 10), strip.Color(255, 255, 255));
     strip.setPixelColor(customMappingFunction(28, 10), strip.Color(255, 255, 255));
     strip.show();
-}+}


removed unused code

removed unused code

--- read_flow_meter_test/read_flow_meter_test.ino
+++ read_flow_meter_test/read_flow_meter_test.ino
@@ -1,12 +0,0 @@
-void setup() {
-  // put your setup code here, to run once:
-  pinMode(0, INPUT);
-  Serial.begin(9600);
-}
-
-void loop() {
-  // put your main code here, to run repeatedly:
-  Serial.print("Flow: ");
-  Serial.println(analogRead(0));
-  delay(200);
-}


Update Mimic_LED_Controller.ino

Update Mimic_LED_Controller.ino

Fixing Issue #190

--- Arduino/Mimic_LED_Controller/Mimic_LED_Controller.ino
+++ Arduino/Mimic_LED_Controller/Mimic_LED_Controller.ino
@@ -402,8 +402,7 @@
   }
   if(Disco)
   {
-    theaterChaseRainbow_portIEA(50);
-    theaterChaseRainbow_stbdIEA(50);
+    theaterChaseRainbow_disco(50);
   }
   Disco = false;
 }
@@ -518,7 +517,25 @@
     }
   }
 }
-
+void theaterChaseRainbow_disco(uint8_t wait) {
+  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
+    for (int q=0; q < 3; q++) {
+      for (uint16_t i=0; i < stbdIEA.numPixels(); i=i+3) {
+        stbdIEA.setPixelColor(i+q, Wheel_stbdIEA( (i+j) % 255));    //turn every third pixel on
+        portIEA.setPixelColor(i+q, Wheel_portIEA( (i+j) % 255));    //turn every third pixel on
+      }
+      stbdIEA.show();
+      portIEA.show();
+
+      delay(wait);
+
+      for (uint16_t i=0; i < stbdIEA.numPixels(); i=i+3) {
+        stbdIEA.setPixelColor(i+q, 0);        //turn every third pixel off
+        portIEA.setPixelColor(i+q, 0);        //turn every third pixel off
+      }
+    }
+  }
+}
 // Input a value 0 to 255 to get a color value.
 // The colours are a transition r - g - b - back to r.
 uint32_t Wheel_stbdIEA(byte WheelPos) {


COH-80: WIP

COH-80: WIP

--- COHEAT2015/20160316-COHEAT-M1/COHEAT-M1/COHEAT-M1.ino
+++ COHEAT2015/20160316-COHEAT-M1/COHEAT-M1/COHEAT-M1.ino
@@ -377,7 +377,7 @@
     const OTRadioLink::SimpleSecureFrame32or0BodyTXBase::fixed32BTextSize12BNonce16BTagSimpleEnc_ptr_t e = OTAESGCM::fixed32BTextSize12BNonce16BTagSimpleEnc_DEFAULT_STATELESS;
     const uint8_t txIDLen = OTRadioLink::ENC_BODY_DEFAULT_ID_BYTES;
     uint8_t buf[OTRadioLink::SimpleSecureFrame32or0BodyTXBase::generateSecureBeaconMaxBufSize];
-    const uint8_t bodylen = OTRadioLink::generateSecureBeaconRawForTXXXX(buf, sizeof(buf), XXX, e, NULL, key);
+    const uint8_t bodylen = secureTXState.generateSecureBeaconRawForTX(buf, sizeof(buf), 2, e, NULL, key);
     // ASSUME FRAMED CHANNEL 0 (but could check with config isUnframed flag).
     // When sending on a channel with framing, do not explicitly send the frame length byte.
     // DO NOT attempt to send if construction of the secure frame failed;


pak hem aan ouwe from HeiligBoontje/master

pak hem aan ouwe

--- Claw/Distance_meter/DistanceMeter/DistanceMeter.ino
+++ Claw/Distance_meter/DistanceMeter/DistanceMeter.ino
@@ -70,8 +70,17 @@
 void SweepForward(int NUM_OF_CYCLES) {
   for (int j = 1; j < NUM_OF_CYCLES; j++)
     for (pos = 0; pos = 170; pos += 1)
-    { servo.write(pos);
+    {
+      servo.write(pos);
       delay(100);
-    }
-
+    }
 }
+
+lastButtonState = buttonState;
+ if (buttonPushCounter % 2 == 0) // moet misschien een keer drukken zijn
+  {
+    digitalWrite(servoPin, HIGH);
+  } else {
+    digitalWrite(servoPin, LOW);
+ }
+


Update normal.ino

Update normal.ino

--- examples/normal/normal.ino
+++ examples/normal/normal.ino
@@ -22,13 +22,13 @@
   ### Troubleshooting

   1. 'Device' type is reported to be missing.
-  - Make sure to properly add the 'iot_att' library
+  - Make sure to properly add the arduino/libraries/allthingstalk_arduino_standard_lib/ library

 */

-char deviceId[] = ""; // Your device id comes here
-char clientId[] = ""; // Your client id comes here
-char clientKey[] = "";// Your client key comes here
+char deviceId[] = "YOUR_DEVICE_ID_HERE";
+char clientId[] = "YOUR_CLIENT_ID_HERE";
+char clientKey[] = "YOUR_CLIENT_KEY_HERE";

 ATTDevice Device(deviceId, clientId, clientKey);            //create the object that provides the connection to the cloud to manager the device.
 char httpServer[] = "api.smartliving.io";                  // HTTP API Server host


delete test sketch

delete test sketch

--- testSketch/testSketch.ino
+++ testSketch/testSketch.ino
@@ -1,9 +0,0 @@
-void setup() {
-  // put your setup code here, to run once:
-
-}
-
-void loop() {
-  // put your main code here, to run repeatedly:
-
-}


Revert "Revert "Edit SD Server example to use the new Write(Stream) method""

This reverts commit 163a98375637ab8e3e177bb7853303e397e39dc0.

--- hardware/esp8266com/esp8266/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino
+++ hardware/esp8266com/esp8266/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino
@@ -111,23 +111,10 @@
     dataType = 0;
     path = 0;

-    uint8_t obuf[WWW_BUF_SIZE];
+    if(client.write(dataFile) != dataFile.size()){
+      DBG_OUTPUT_PORT.println("Sent less data than expected!");
+    }

-    while (dataFile.available() > WWW_BUF_SIZE){
-      dataFile.read(obuf, WWW_BUF_SIZE);
-      if(client.write(obuf, WWW_BUF_SIZE) != WWW_BUF_SIZE){
-        DBG_OUTPUT_PORT.println("Sent less data than expected!");
-        dataFile.close();
-        return true;
-      }
-    }
-    uint16_t leftLen = dataFile.available();
-    dataFile.read(obuf, leftLen);
-    if(client.write(obuf, leftLen) != leftLen){
-      DBG_OUTPUT_PORT.println("Sent less data than expected!");
-      dataFile.close();
-      return true;
-    }
     dataFile.close();
     client.stop();
     return true;


adjusted angle

adjusted angle

--- src/arduino/bear.ino
+++ src/arduino/bear.ino
@@ -14,7 +14,7 @@
 const int LED_1 = 9;
 const int LED_2 = 8;

-const int SERVO_BASE_ANGLE = 60;
+const int SERVO_BASE_ANGLE = 40;
 const int SERVO_MAX_ANGLE = 60;

 const int BLINK_INTERVAL = 150; // in milliseconds


Delete ArduinoFirmware.ino

Delete ArduinoFirmware.ino

--- ArduinoFirmware/ArduinoFirmware/ArduinoFirmware.ino
+++ ArduinoFirmware/ArduinoFirmware/ArduinoFirmware.ino
@@ -1,415 +0,0 @@
-#include <SoftwareSerial.h>
-#include <Wire.h>
-#include <Servo.h>
-#include <EEPROM.h>
-
-SoftwareSerial *sserial = NULL;
-Servo servos[8];
-int servo_pins[] = {0, 0, 0, 0, 0, 0, 0, 0};
-boolean connected = false;
-
-int Str2int (String Str_value)
-{
-  char buffer[10]; //max length is three units
-  Str_value.toCharArray(buffer, 10);
-  int int_value = atoi(buffer);
-  return int_value;
-}
-
-void split(String results[], int len, String input, char spChar) {
-  String temp = input;
-  for (int i=0; i<len; i++) {
-    int idx = temp.indexOf(spChar);
-    results[i] = temp.substring(0,idx);
-    temp = temp.substring(idx+1);
-  }
-}
-
-void Version(){
-  Serial.println("version");
-}
-
-uint8_t readCapacitivePin(String data) {
-  int pinToMeasure = Str2int(data);
-  // readCapacitivePin
-  //  Input: Arduino pin number
-  //  Output: A number, from 0 to 17 expressing
-  //  how much capacitance is on the pin
-  //  When you touch the pin, or whatever you have
-  //  attached to it, the number will get higher
-  //  http://playground.arduino.cc/Code/CapacitiveSensor
-  //
-  // Variables used to translate from Arduino to AVR pin naming
-  volatile uint8_t* port;
-  volatile uint8_t* ddr;
-  volatile uint8_t* pin;
-  // Here we translate the input pin number from
-  //  Arduino pin number to the AVR PORT, PIN, DDR,
-  //  and which bit of those registers we care about.
-  byte bitmask;
-  port = portOutputRegister(digitalPinToPort(pinToMeasure));
-  ddr = portModeRegister(digitalPinToPort(pinToMeasure));
-  bitmask = digitalPinToBitMask(pinToMeasure);
-  pin = portInputRegister(digitalPinToPort(pinToMeasure));
-  // Discharge the pin first by setting it low and output
-  *port &= ~(bitmask);
-  *ddr  |= bitmask;
-  delay(1);
-  // Make the pin an input with the internal pull-up on
-  *ddr &= ~(bitmask);
-  *port |= bitmask;
-
-  // Now see how long the pin to get pulled up. This manual unrolling of the loop
-  // decreases the number of hardware cycles between each read of the pin,
-  // thus increasing sensitivity.
-  uint8_t cycles = 17;
-       if (*pin & bitmask) { cycles =  0;}
-  else if (*pin & bitmask) { cycles =  1;}
-  else if (*pin & bitmask) { cycles =  2;}
-  else if (*pin & bitmask) { cycles =  3;}
-  else if (*pin & bitmask) { cycles =  4;}
-  else if (*pin & bitmask) { cycles =  5;}
-  else if (*pin & bitmask) { cycles =  6;}
-  else if (*pin & bitmask) { cycles =  7;}
-  else if (*pin & bitmask) { cycles =  8;}
-  else if (*pin & bitmask) { cycles =  9;}
-  else if (*pin & bitmask) { cycles = 10;}
-  else if (*pin & bitmask) { cycles = 11;}
-  else if (*pin & bitmask) { cycles = 12;}
-  else if (*pin & bitmask) { cycles = 13;}
-  else if (*pin & bitmask) { cycles = 14;}
-  else if (*pin & bitmask) { cycles = 15;}
-  else if (*pin & bitmask) { cycles = 16;}
-
-  // Discharge the pin again by setting it low and output
-  //  It's important to leave the pins low if you want to
-  //  be able to touch more than 1 sensor at a time - if
-  //  the sensor is left pulled high, when you touch
-  //  two sensors, your body will transfer the charge between
-  //  sensors.
-  *port &= ~(bitmask);
-  *ddr  |= bitmask;
-
-  //return cycles;
-  Serial.println(cycles);
-}
-
-void Tone(String data){
-  int idx = data.indexOf('%');
-  int len = Str2int(data.substring(0,idx));
-  String data2 = data.substring(idx+1);
-  int idx2 = data2.indexOf('%');
-  int pin = Str2int(data2.substring(0,idx2));
-  String data3 = data2.substring(idx2+1);
-  String melody[len*2];
-  split(melody,len*2,data3,'%');
-
-  for (int thisNote = 0; thisNote < len; thisNote++) {
-    int noteDuration = 1000/Str2int(melody[thisNote+len]);
-    int note = Str2int(melody[thisNote]);
-    tone(pin, note, noteDuration);
-    int pause = noteDuration * 1.30;
-    delay(pause);
-    noTone(pin);
-  }
-}
-
-void ToneNo(String data){
-  int pin = Str2int(data);
-  noTone(pin);
-}
-
-void DigitalHandler(int mode, String data){
-      int pin = Str2int(data);
-    if(mode<=0){ //read
-        Serial.println(digitalRead(pin));
-    }else{
-        if(pin <0){
-            digitalWrite(-pin,LOW);
-        }else{
-            digitalWrite(pin,HIGH);
-        }
-        //Serial.println('0');
-    }
-}
-
-void AnalogHandler(int mode, String data){
-     if(mode<=0){ //read
-        int pin = Str2int(data);
-        Serial.println(analogRead(pin));
-    }else{
-        String sdata[2];
-        split(sdata,2,data,'%');
-        int pin = Str2int(sdata[0]);
-        int pv = Str2int(sdata[1]);
-        analogWrite(pin,pv);
-    }
-}
-
-void ConfigurePinHandler(String data){
-    int pin = Str2int(data);
-    if(pin <=0){
-        pinMode(-pin,INPUT);
-    }else{
-        pinMode(pin,OUTPUT);
-    }
-}
-
-void shiftOutHandler(String data) {
-    String sdata[4];
-    split(sdata, 4, data, '%');
-    int dataPin = sdata[0].toInt();
-    int clockPin = sdata[1].toInt();
-    String bitOrderName = sdata[2];
-    byte value = (byte)(sdata[3].toInt());
-    if (bitOrderName == "MSBFIRST") {
-       shiftOut(dataPin, clockPin, MSBFIRST, value);
-    } else {
-       shiftOut(dataPin, clockPin, LSBFIRST, value);
-    }
-}
-
-void shiftInHandler(String data) {
-    String sdata[3];
-    split(sdata, 3, data, '%');
-    int dataPin = sdata[0].toInt();
-    int clockPin = sdata[1].toInt();
-    String bitOrderName = sdata[2];
-    int incoming;
-    if (bitOrderName == "MSBFIRST") {
-       incoming = (int)shiftIn(dataPin, clockPin, MSBFIRST);
-    } else {
-       incoming = (int)shiftIn(dataPin, clockPin, LSBFIRST);
-    }
-    Serial.println(incoming);
-}
-
-void SS_set(String data){
-  delete sserial;
-  String sdata[3];
-  split(sdata,3,data,'%');
-  int rx_ = Str2int(sdata[0]);
-  int tx_ = Str2int(sdata[1]);
-  int baud_ = Str2int(sdata[2]);
-  sserial = new SoftwareSerial(rx_, tx_);
-  sserial->begin(baud_);
-  Serial.println("ss OK");
-}
-
-void SS_write(String data) {
- int len = data.length()+1;
- char buffer[len];
- data.toCharArray(buffer,len);
- Serial.println("ss OK");
- sserial->write(buffer);
-}
-void SS_read(String data) {
- char c = sserial->read();
- Serial.println(c);
-}
-
-void pulseInHandler(String data){
-    int pin = Str2int(data);
-    long duration;
-    if(pin <=0){
-          pinMode(-pin, INPUT);
-          duration = pulseIn(-pin, LOW);
-    }else{
-          pinMode(pin, INPUT);
-          duration = pulseIn(pin, HIGH);
-    }
-    Serial.println(duration);
-}
-
-void pulseInSHandler(String data){
-    int pin = Str2int(data);
-    long duration;
-    if(pin <=0){
-          pinMode(-pin, OUTPUT);
-          digitalWrite(-pin, HIGH);
-          delayMicroseconds(2);
-          digitalWrite(-pin, LOW);
-          delayMicroseconds(5);
-          digitalWrite(-pin, HIGH);
-          pinMode(-pin, INPUT);
-          duration = pulseIn(-pin, LOW);
-    }else{
-          pinMode(pin, OUTPUT);
-          digitalWrite(pin, LOW);
-          delayMicroseconds(2);
-          digitalWrite(pin, HIGH);
-          delayMicroseconds(5);
-          digitalWrite(pin, LOW);
-          pinMode(pin, INPUT);
-          duration = pulseIn(pin, HIGH);
-    }
-    Serial.println(duration);
-}
-
-void SV_add(String data) {
-    String sdata[3];
-    split(sdata,3,data,'%');
-    int pin = Str2int(sdata[0]);
-    int min = Str2int(sdata[1]);
-    int max = Str2int(sdata[2]);
-    int pos = -1;
-    for (int i = 0; i<8;i++) {
-        if (servo_pins[i] == pin) { //reset in place
-            servos[pos].detach();
-            servos[pos].attach(pin, min, max);
-            servo_pins[pos] = pin;
-            Serial.println(pos);
-            return;
-            }
-        }
-    for (int i = 0; i<8;i++) {
-        if (servo_pins[i] == 0) {pos = i;break;} // find spot in servo array
-        }
-    if (pos == -1) {;} //no array position available!
-    else {
-        servos[pos].attach(pin, min, max);
-        servo_pins[pos] = pin;
-        Serial.println(pos);
-        }
-}
-
-void SV_remove(String data) {
-    int pos = Str2int(data);
-    servos[pos].detach();
-    servo_pins[pos] = 0;
-}
-
-void SV_read(String data) {
-    int pos = Str2int(data);
-    int angle;
-    angle = servos[pos].read();
-    Serial.println(angle);
-}
-
-void SV_write(String data) {
-    String sdata[2];
-    split(sdata,2,data,'%');
-    int pos = Str2int(sdata[0]);
-    int angle = Str2int(sdata[1]);
-    servos[pos].write(angle);
-}
-
-void SV_write_ms(String data) {
-    String sdata[2];
-    split(sdata,2,data,'%');
-    int pos = Str2int(sdata[0]);
-    int uS = Str2int(sdata[1]);
-    servos[pos].writeMicroseconds(uS);
-}
-
-void sizeEEPROM() {
-    Serial.println(E2END + 1);
-}
-
-void EEPROMHandler(int mode, String data) {
-    String sdata[2];
-    split(sdata, 2, data, '%');
-    if (mode == 0) {
-        EEPROM.write(Str2int(sdata[0]), Str2int(sdata[1]));
-    } else {
-        Serial.println(EEPROM.read(Str2int(sdata[0])));
-    }
-}
-
-void SerialParser(void) {
-  char readChar[64];
-  Serial.readBytesUntil(33,readChar,64);
-  String read_ = String(readChar);
-  //Serial.println(readChar);
-  int idx1 = read_.indexOf('%');
-  int idx2 = read_.indexOf('$');
-  // separate command from associated data
-  String cmd = read_.substring(1,idx1);
-  String data = read_.substring(idx1+1,idx2);
-
-  // determine command sent
-  if (cmd == "dw") {
-      DigitalHandler(1, data);
-  }
-  else if (cmd == "dr") {
-      DigitalHandler(0, data);
-  }
-  else if (cmd == "aw") {
-      AnalogHandler(1, data);
-  }
-  else if (cmd == "ar") {
-      AnalogHandler(0, data);
-  }
-  else if (cmd == "pm") {
-      ConfigurePinHandler(data);
-  }
-  else if (cmd == "ps") {
-      pulseInSHandler(data);
-  }
-  else if (cmd == "pi") {
-      pulseInHandler(data);
-  }
-  else if (cmd == "ss") {
-      SS_set(data);
-  }
-  else if (cmd == "sw") {
-      SS_write(data);
-  }
-  else if (cmd == "sr") {
-      SS_read(data);
-  }
-  else if (cmd == "sva") {
-      SV_add(data);
-  }
-  else if (cmd == "svr") {
-      SV_read(data);
-  }
- else if (cmd == "svw") {
-      SV_write(data);
-  }
- else if (cmd == "svwm") {
-      SV_write_ms(data);
-  }
-  else if (cmd == "svd") {
-      SV_remove(data);
-  }
-  else if (cmd == "version") {
-      Version();
-  }
-  else if (cmd == "to") {
-      Tone(data);
-  }
-  else if (cmd == "nto") {
-      ToneNo(data);
-  }
-  else if (cmd == "cap") {
-      readCapacitivePin(data);
-  }
-  else if (cmd == "so") {
-      shiftOutHandler(data);
-  }
-  else if (cmd == "si") {
-      shiftInHandler(data);
-  }
-  else if (cmd == "eewr") {
-      EEPROMHandler(0, data);
-  }
-  else if (cmd == "eer") {
-      EEPROMHandler(1, data);
-  }
-  else if (cmd == "sz") {
-      sizeEEPROM();
-  }
-}
-
-void setup()  {
-  analogReference(EXTERNAL);
-  Serial.begin(115200);
-    while (!Serial) {
-    ; // wait for serial port to connect. Needed for Leonardo only
-  }
-}
-
-void loop() {
-   SerialParser();
-   }


Update CastleAritechArduinoRKP.ino

Update CastleAritechArduinoRKP.ino

--- CastleAritechArduinoRKP/CastleAritechArduinoRKP.ino
+++ CastleAritechArduinoRKP/CastleAritechArduinoRKP.ino
@@ -1,7 +1,7 @@
 /*
 *   Castle KeyPad
 *
-*   Aritech Alarm Panel Arduino Internet Enabled Keypad -  CS350 - CD34 - CD72 - CD91 and more
+*   Aritech Alarm Panel Arduino Internet Enabled Keypad -  CS350 - CD34 - CD72 - CD91 - CS350 and more
 *
 *   For Arduino (UNO or Leonardo) with added Ethernet Shield
 *


Delete OTTO_smooth_criminal_US.ino

Delete OTTO_smooth_criminal_US.ino

--- OTTO_smooth_criminal_US/OTTO_smooth_criminal_US.ino
+++ OTTO_smooth_criminal_US/OTTO_smooth_criminal_US.ino
@@ -1,608 +0,0 @@
-//----------------------------------------------------------------
-//-- OTTO Dance smooth criminal by Michael Jackson
-//-- Released under a GPL licencse
-//-- Originally made for Zowi project remake for Otto
-//-- Authors:  Javier Isabel:  javier.isabel@bq.com
-//--           Juan Gonzalez (obijuan): juan.gonzalez@bq.com
-// Nicu FLORICA (niq_ro) add ultrasonic sensor for activate dance
-// and deactivate servo in standby (ver1b)
-// http://www.arduinotehniq.com & nicu.florica@gmail.com
-//-----------------------------------------------------------------
-#include <Servo.h>
-#include <Oscillator.h>
-#include <EEPROM.h>
-
-#define N_SERVOS 4
-//-- First step: Configure the pins where the servos are attached
-/*
-         ---------------
-        |     O   O     |
-        |---------------|
-YR 3==> |               | <== YL 2
-         ---------------
-            ||     ||
-RR 5==>   -----   ------  <== RL 4
-         |-----   ------|
-*/
-#define EEPROM_TRIM false
-// Activate to take callibration data from internal memory
-#define TRIM_RR 7
-#define TRIM_RL 4
-#define TRIM_YR  4
-#define TRIM_YL -7
-//OTTO.setTrims(-7,-4,-4,7);
-
-#define PIN_RR 5
-#define PIN_RL 4
-#define PIN_YR 3
-#define PIN_YL 2
-
-#define INTERVALTIME 10.0
-
-Oscillator servo[N_SERVOS];
-
-/*
-void goingUp(int tempo);
-void drunk (int tempo);
-void noGravity(int tempo);
-void kickLeft(int tempo);
-void kickRight(int tempo);
-void run1(int steps, int T=500);
-void walk(int steps, int T=1000);
-void backyard(int steps, int T=3000);
-void backyardSlow(int steps, int T=5000);
-void turnLeft(int steps, int T=3000);
-void turnRight(int steps, int T=3000);
-void moonWalkLeft(int steps, int T=1000);
-void moonWalkRight(int steps, int T=1000);
-void crusaito(int steps, int T=1000);
-void swing(int steps, int T=1000);
-void upDown(int steps, int T=1000);
-void flapping(int steps, int T=1000);
-*/
-
-#define ECHOPIN 9        // Pin to receive echo pulse
-#define TRIGPIN 8        // Pin to send trigger pulse
-
-  int trimu;
-  int dansezpttine = 0;
-
-void setup()
-{
-//  Serial.begin(19200);
-
-  servo[0].attach(PIN_RR);
-  servo[1].attach(PIN_RL);
-  servo[2].attach(PIN_YR);
-  servo[3].attach(PIN_YL);
-
-  //EEPROM.write(0,TRIM_RR);
-  //EEPROM.write(1,TRIM_RL);
-  //EEPROM.write(2,TRIM_YR);
-  //EEPROM.write(3,TRIM_YL);
-
-
-  if(EEPROM_TRIM){
-    for(int x=0;x<4;x++){
-      trimu=EEPROM.read(x);
-      if(trimu>128)trimu=trimu-256;
-      Serial.print("TRIM ");
-      Serial.print(x);
-      Serial.print(" en ");
-      Serial.println(trimu);
-      servo[x].SetTrim(trimu);
-    }
-  }
-  else{
-    servo[0].SetTrim(TRIM_RR);
-    servo[1].SetTrim(TRIM_RL);
-    servo[2].SetTrim(TRIM_YR);
-    servo[3].SetTrim(TRIM_YL);
-  }
-
-  for(int i=0;i<4;i++) servo[i].SetPosition(90);
-  delay(500);
-  for(int i=0;i<4;i++) servo[i].detach();
-
-  pinMode(ECHOPIN, INPUT);
-  pinMode(TRIGPIN, OUTPUT);
-}
-
-// TEMPO: 121 BPM
-int t=495;
-double pause=0;
-
-void loop()
-{
- // if(Serial.available()){
-  //  char init = Serial.read();
-   // if (init=='X'){
-   //   delay(4000); //3000 - 4500
-
-// Start Ranging
-  digitalWrite(TRIGPIN, LOW);
-  delayMicroseconds(2);
-  digitalWrite(TRIGPIN, HIGH);
-  delayMicroseconds(10);
-  digitalWrite(TRIGPIN, LOW);
-  // Compute distance
-  float distance = pulseIn(ECHOPIN, HIGH);
-  distance= distance/58;
-  Serial.print(distance);
-  Serial.println("cm");
- if ((distance >1) && (distance < 25))
-  {
-  Serial.println ("Danceeeee !");
-  dansezpttine = 1;
-  }
-
-
- if (dansezpttine == 1)
- {
-  servo[0].attach(PIN_RR);
-  servo[1].attach(PIN_RL);
-  servo[2].attach(PIN_YR);
-  servo[3].attach(PIN_YL);
-
-  if(EEPROM_TRIM){
-    for(int x=0;x<4;x++){
-      trimu=EEPROM.read(x);
-      if(trimu>128)trimu=trimu-256;
-      Serial.print("TRIM ");
-      Serial.print(x);
-      Serial.print(" en ");
-      Serial.println(trimu);
-      servo[x].SetTrim(trimu);
-    }
-  }
-  else{
-    servo[0].SetTrim(TRIM_RR);
-    servo[1].SetTrim(TRIM_RL);
-    servo[2].SetTrim(TRIM_YR);
-    servo[3].SetTrim(TRIM_YL);
-  }
-delay(100);
- dance();
-delay(500);
- for(int i=0;i<4;i++) servo[i].SetPosition(90);
-delay(500);
- for(int i=0;i<4;i++) servo[i].detach();
- dansezpttine = 0;
- }
-delay(200);
-
-//for(int i=0;i<4;i++) servo[i].SetPosition(90);
-
-
-   // }
- // }
-}
-
-void dance(){
-  primera_parte();
-  segunda_parte();
-  moonWalkLeft(4,t*2);
-  moonWalkRight(4,t*2);
-  moonWalkLeft(4,t*2);
-  moonWalkRight(4,t*2);
-  primera_parte();
-  crusaito(1,t*8);
-  crusaito(1,t*7);
-
-  for (int i=0; i<16; i++){
-    flapping(1,t/4);
-    delay(3*t/4);
-  }
-
-  moonWalkRight(4,t*2);
-  moonWalkLeft(4,t*2);
-  moonWalkRight(4,t*2);
-  moonWalkLeft(4,t*2);
-
-  drunk(t*4);
-  drunk(t*4);
-  drunk(t*4);
-  drunk(t*4);
-  kickLeft(t);
-  kickRight(t);
-  drunk(t*8);
-  drunk(t*4);
-  drunk(t/2);
-  delay(t*4);
-
-  drunk(t/2);
-
-  delay(t*4);
-  walk(2,t*2);
-  backyard(2,t*2);
-  goingUp(t*2);
-  goingUp(t*1);
-  noGravity(t*2);
-  crusaito(1,t*2);
-  crusaito(1,t*8);
-  crusaito(1,t*2);
-  crusaito(1,t*8);
-  crusaito(1,t*2);
-  crusaito(1,t*3);
-
-  delay(t);
-  primera_parte();
-    for (int i=0; i<32; i++){
-    flapping(1,t/2);
-    delay(t/2);
-  }
-
-  for(int i=0;i<4;i++) servo[i].SetPosition(90);
-}
-
-
-
-
-////////////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////FUNCIONES DE CONTROL//////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////////////
-
-void oscillate(int A[N_SERVOS], int O[N_SERVOS], int T, double phase_diff[N_SERVOS]){
-  for (int i=0; i<4; i++) {
-    servo[i].SetO(O[i]);
-    servo[i].SetA(A[i]);
-    servo[i].SetT(T);
-    servo[i].SetPh(phase_diff[i]);
-  }
-  double ref=millis();
-   for (double x=ref; x<T+ref; x=millis()){
-     for (int i=0; i<4; i++){
-        servo[i].refresh();
-     }
-  }
-}
-
-unsigned long final_time;
-unsigned long interval_time;
-int oneTime;
-int iteration;
-float increment[N_SERVOS];
-int oldPosition[]={90,90,90,90};
-
-void moveNServos(int time, int  newPosition[]){
-  for(int i=0;i<N_SERVOS;i++)	increment[i] = ((newPosition[i])-oldPosition[i])/(time/INTERVALTIME);
-
-  final_time =  millis() + time;
-
-  iteration = 1;
-  while(millis() < final_time){ //Javi del futuro cambia esto
-      interval_time = millis()+INTERVALTIME;
-
-      oneTime=0;
-      while(millis()<interval_time){
-          if(oneTime<1){
-              for(int i=0;i<N_SERVOS;i++){
-                  servo[i].SetPosition(oldPosition[i] + (iteration * increment[i]));
-              }
-              iteration++;
-              oneTime++;
-          }
-      }
-  }
-
-  for(int i=0;i<N_SERVOS;i++){
-    oldPosition[i] = newPosition[i];
-  }
-}
-
-
-//////////////////////////////////////////////////////////////////////////////
-////////////////////////////////PASOS DE BAILE////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////
-
-void goingUp(int tempo){
-
-      pause=millis();
-      for(int i=0;i<4;i++) servo[i].SetPosition(90);
-      delay(tempo);
-      servo[0].SetPosition(80);
-      servo[1].SetPosition(100);
-      delay(tempo);
-      servo[0].SetPosition(70);
-      servo[1].SetPosition(110);
-      delay(tempo);
-      servo[0].SetPosition(60);
-      servo[1].SetPosition(120);
-      delay(tempo);
-      servo[0].SetPosition(50);
-      servo[1].SetPosition(130);
-      delay(tempo);
-      servo[0].SetPosition(40);
-      servo[1].SetPosition(140);
-      delay(tempo);
-      servo[0].SetPosition(30);
-      servo[1].SetPosition(150);
-      delay(tempo);
-      servo[0].SetPosition(20);
-      servo[1].SetPosition(160);
-      delay(tempo);
-
-      while(millis()<pause+8*t);
-
-}
-
-void primera_parte(){
-
-  int move1[4] = {60,120,90,90};
-  int move2[4] = {90,90,90,90};
-  int move3[4] = {40,140,90,90};
-
-  for(int x=0; x<3; x++){
-    for(int i=0; i<3; i++){
-      lateral_fuerte(1,t/2);
-      lateral_fuerte(0,t/4);
-      lateral_fuerte(1,t/4);
-      delay(t);
-    }
-
-    pause=millis();
-    for(int i=0;i<4;i++) servo[i].SetPosition(90);
-    moveNServos(t*0.4,move1);
-    moveNServos(t*0.4,move2);
-    while(millis()<(pause+t*2));
-  }
-
-  for(int i=0; i<2; i++){
-    lateral_fuerte(1,t/2);
-    lateral_fuerte(0,t/4);
-    lateral_fuerte(1,t/4);
-    delay(t);
-  }
-
-  pause=millis();
-  for(int i=0;i<4;i++) servo[i].SetPosition(90);
-  crusaito(1,t*1.4);
-  moveNServos(t*1,move3);
-  for(int i=0;i<4;i++) servo[i].SetPosition(90);
-  while(millis()<(pause+t*4));
-}
-
-void segunda_parte(){
-
-  int move1[4] = {90,90,80,100};
-  int move2[4] = {90,90,100,80};
-  int move3[4] = {90,90,80,100};
-  int move4[4] = {90,90,100,80};
-
-  int move5[4] = {40,140,80,100};
-  int move6[4] = {40,140,100,80};
-  int move7[4] = {90,90,80,100};
-  int move8[4] = {90,90,100,80};
-
-  int move9[4] = {40,140,80,100};
-  int move10[4] = {40,140,100,80};
-  int move11[4] = {90,90,80,100};
-  int move12[4] = {90,90,100,80};
-
-  for(int x=0; x<7; x++){
-    for(int i=0; i<3; i++){
-      pause=millis();
-      moveNServos(t*0.15,move1);
-      moveNServos(t*0.15,move2);
-      moveNServos(t*0.15,move3);
-      moveNServos(t*0.15,move4);
-      while(millis()<(pause+t));
-    }
-    pause=millis();
-    moveNServos(t*0.15,move5);
-    moveNServos(t*0.15,move6);
-    moveNServos(t*0.15,move7);
-    moveNServos(t*0.15,move8);
-    while(millis()<(pause+t));
-  }
-
-  for(int i=0; i<3; i++){
-    pause=millis();
-    moveNServos(t*0.15,move9);
-    moveNServos(t*0.15,move10);
-    moveNServos(t*0.15,move11);
-    moveNServos(t*0.15,move12);
-    while(millis()<(pause+t));
-  }
-}
-
-void lateral_fuerte(boolean side, int tempo){
-
-  for(int i=0;i<4;i++) servo[i].SetPosition(90);
-  if (side) servo[0].SetPosition(40);
-  else servo[1].SetPosition(140);
-  delay(tempo/2);
-  servo[0].SetPosition(90);
-  servo[1].SetPosition(90);
-  delay(tempo/2);
-
-}
-
-void drunk (int tempo){
-
-  pause=millis();
-
-  int move1[] = {60,70,90,90};
-  int move2[] = {110,120,90,90};
-  int move3[] = {60,70,90,90};
-  int move4[] = {110,120,90,90};
-
-  moveNServos(tempo*0.235,move1);
-  moveNServos(tempo*0.235,move2);
-  moveNServos(tempo*0.235,move3);
-  moveNServos(tempo*0.235,move4);
-  while(millis()<(pause+tempo));
-
-}
-
-
-void noGravity(int tempo){
-
-  int move1[4] = {120,140,90,90};
-  int move2[4] = {140,140,90,90};
-  int move3[4] = {120,140,90,90};
-  int move4[4] = {90,90,90,90};
-
-
-  for(int i=0;i<4;i++) servo[i].SetPosition(90);
-  for(int i=0;i<N_SERVOS;i++) oldPosition[i]=90;
-  moveNServos(tempo*2,move1);
-  moveNServos(tempo*2,move2);
-  delay(tempo*2);
-  moveNServos(tempo*2,move3);
-  moveNServos(tempo*2,move4);
-
-
-
-}
-
-void kickLeft(int tempo){
-  for(int i=0;i<4;i++) servo[i].SetPosition(90);
-  delay(tempo);
-  servo[0].SetPosition(50); //pie derecho
-  servo[1].SetPosition(70); //pie izquiero
-  delay(tempo);
-  servo[0].SetPosition(80); //pie derecho
-  servo[1].SetPosition(70); //pie izquiero
-  delay(tempo/4);
-  servo[0].SetPosition(30); //pie derecho
-  servo[1].SetPosition(70); //pie izquiero
-  delay(tempo/4);
-  servo[0].SetPosition(80); //pie derecho
-  servo[1].SetPosition(70); //pie izquiero
-  delay(tempo/4);
-  servo[0].SetPosition(30); //pie derecho
-  servo[1].SetPosition(70); //pie izquiero
-  delay(tempo/4);
-  servo[0].SetPosition(80); //pie derecho
-  servo[1].SetPosition(70); //pie izquiero
-  delay(tempo);
-}
-
-void kickRight(int tempo){
-for(int i=0;i<4;i++) servo[i].SetPosition(90);
-  delay(tempo);
-  servo[0].SetPosition(110); //pie derecho
-  servo[1].SetPosition(130); //pie izquiero
-  delay(tempo);
-  servo[0].SetPosition(110); //pie derecho
-  servo[1].SetPosition(100); //pie izquiero
-  delay(tempo/4);
-  servo[0].SetPosition(110); //pie derecho
-  servo[1].SetPosition(150); //pie izquiero
-  delay(tempo/4);
-  servo[0].SetPosition(110); //pie derecho
-  servo[1].SetPosition(80); //pie izquiero
-  delay(tempo/4);
-  servo[0].SetPosition(110); //pie derecho
-  servo[1].SetPosition(150); //pie izquiero
-  delay(tempo/4);
-  servo[0].SetPosition(110); //pie derecho
-  servo[1].SetPosition(100); //pie izquiero
-  delay(tempo);
-}
-
-void walk(int steps, int T){
-    int A[4]= {15, 15, 30, 30};
-    int O[4] = {0, 0, 0, 0};
-    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};
-
-    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);
-}
-
-void run1(int steps, int T){
-    int A[4]= {10, 10, 10, 10};
-    int O[4] = {0, 0, 0, 0};
-    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};
-
-    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);
-}
-
-void backyard(int steps, int T){
-    int A[4]= {15, 15, 30, 30};
-    int O[4] = {0, 0, 0, 0};
-    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(-90), DEG2RAD(-90)};
-
-    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);
-}
-
-void backyardSlow(int steps, int T){
-    int A[4]= {15, 15, 30, 30};
-    int O[4] = {0, 0, 0, 0};
-    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(-90), DEG2RAD(-90)};
-
-    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);
-}
-
-
-void turnLeft(int steps, int T){
-    int A[4]= {20, 20, 10, 30};
-    int O[4] = {0, 0, 0, 0};
-    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};
-
-    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);
-}
-
-void turnRight(int steps, int T){
-    int A[4]= {20, 20, 30, 10};
-    int O[4] = {0, 0, 0, 0};
-    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};
-
-    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);
-}
-
-void moonWalkRight(int steps, int T){
-    int A[4]= {25, 25, 0, 0};
-    int O[4] = {-15 ,15, 0, 0};
-    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 + 120), DEG2RAD(90), DEG2RAD(90)};
-
-    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);
-}
-
-void moonWalkLeft(int steps, int T){
-    int A[4]= {25, 25, 0, 0};
-    int O[4] = {-15, 15, 0, 0};
-    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 - 120), DEG2RAD(90), DEG2RAD(90)};
-
-    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);
-}
-
-void crusaito(int steps, int T){
-    int A[4]= {25, 25, 30, 30};
-    int O[4] = {- 15, 15, 0, 0};
-    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 + 120), DEG2RAD(90), DEG2RAD(90)};
-
-    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);
-}
-
-void swing(int steps, int T){
-    int A[4]= {25, 25, 0, 0};
-    int O[4] = {-15, 15, 0, 0};
-    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};
-
-    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);
-}
-
-void upDown(int steps, int T){
-    int A[4]= {25, 25, 0, 0};
-    int O[4] = {-15, 15, 0, 0};
-    double phase_diff[4] = {DEG2RAD(180), DEG2RAD(0), DEG2RAD(270), DEG2RAD(270)};
-
-    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);
-}
-
-void flapping(int steps, int T){
-    int A[4]= {15, 15, 8, 8};
-    int O[4] = {-A[0], A[1], 0, 0};
-    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180), DEG2RAD(90), DEG2RAD(-90)};
-
-    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);
-}
-
-void test(int steps, int T){
-    int A[4]= {15, 15, 8, 8};
-    int O[4] = {-A[0] + 10, A[1] - 10, 0, 0};
-    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180), DEG2RAD(90), DEG2RAD(-90)};
-
-    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);
-}


Removed trailing whitespace

Removed trailing whitespace

--- examples/h_SDI-12_interface/h_SDI-12_interface.ino
+++ examples/h_SDI-12_interface/h_SDI-12_interface.ino
@@ -1,4 +1,4 @@
-/*
+/*
  *  SDI-12 Interface
  *
  *  Arduino-based USB dongle translates serial comm from PC to SDI-12 (electrical and timing)


[modified] testPin_I2C.ino

[modified] testPin_I2C.ino

--- arduino_sketches/PGA309/testPin_I2C/testPin_I2C.ino
+++ arduino_sketches/PGA309/testPin_I2C/testPin_I2C.ino
@@ -1,26 +1,11 @@
-#include <SendOnlySoftwareSerial.h>
-
 int testPin = 52;
-int prgPin = 48;
-
-SendOnlySoftwareSerial PGA309UART (prgPin);

 void setup(){
   Serial.begin(9600);
-  PGA309UART.begin(9600);
+  //Setting the test pin high enables direct writing of internal registers and stops transactions with External EEPROM
   pinMode(testPin, OUTPUT);
-  pinMode(prgPin, OUTPUT);
-  //Setting the test pin high enables direct writing of internal registers and stops transactions with External EEPROM
   digitalWrite(testPin, HIGH);
-  //The PRG pin should always be high when no communication is in progress
-  digitalWrite(prgPin, HIGH);
-  delay(50);
-  //Setting up the external EEPROM pointer address
-  //Sending initialisation byte 0x55
-  PGA309UART.write(0x55);
-  PGA309UART.write(0x02);
-  PGA309UART.write();
-  PGA309UART.write();
+  delay(20);
 }

 void loop(){


Update HC-SR04_test.ino

Update HC-SR04_test.ino

--- Arduino/Sensors/Ultrasonic/HC-SR04_test/HC-SR04_test.ino
+++ Arduino/Sensors/Ultrasonic/HC-SR04_test/HC-SR04_test.ino
@@ -59,7 +59,10 @@
   // 13.524 in/msec
   // 0.013524 in/microsec OR 1/0.013524 = 73.94 microsecs/in
   // for more visit: https://en.wikipedia.org/wiki/Speed_of_sound
-
+
+  // The pulseIn() function returns the length of a pulse in microseconds
+  // so we use 29.11 microsecs/cm and 73.94 microsecs/in to calculate the
+  // distance in centimeters and inches respectively.
   cm = (duration/2) / 29.11; // (duration/2) * 0.034351 will also work
   inches = (duration/2) / 73.94; // (duration/2) * 0.013524 will also work


fixing bug in replace

fixing bug in replace

--- module/module_wifi.ino
+++ module/module_wifi.ino
@@ -22,8 +22,8 @@

 void updateThingSpeak(unsigned char ID, unsigned int time) {
     getStr = "GET /update?key=CSV1YP0YIE2STS0Z&field1=ID&field2=TIME\r\n";
-    getStr = getStr.replace("ID", ID);
-    getStr = getStr.replace("TIME", time);
+    getStr.replace("ID", ID);
+    getStr.replace("TIME", time);

     cmd = "AT+CIPSEND=0,";
     cmd += String(getStr.length());


corrected commented code out bug

corrected commented code out bug

--- short-circuit-limiter/short-circuit-limiter.ino
+++ short-circuit-limiter/short-circuit-limiter.ino
@@ -481,7 +481,7 @@
     Serial.println("Enter Max Temp mode");
   }

-  float temperature = 0;//getTemperature();
+  float temperature = getTemperature();

   //We remain in this mode until the temperature drops below TEMP_WARN to prevent oscillating into this mode and out
   if(temperature >= TEMP_WARN){


added interface mode related code

added interface mode related code

--- src/sonoff-core.ino
+++ src/sonoff-core.ino
@@ -19,13 +19,13 @@
     runSwitch();
   } else if (Configuration.mode == MODE_CONFIGURATION) {
     runConfigurationLAN();
-  } else if (Configuration.mode == MODE_ACCESSPOINT) {
+  } else { /* Configuration: Access point */
     runConfigurationAP();
-  } else {
-    if (Configuration.debugger) Serial << "Internal Application error" << endl;
-  }
-}
-
+  }
+}
+
+
+/* It removed configuration */
 void Sonoff::reset() {
   if (Configuration.debugger) Serial << "- ereasing EEPROM" << endl;
   Eeprom.erase();
@@ -99,10 +99,14 @@

 void Sonoff::listener() {
   if (Configuration.mode == MODE_SWITCH) {
-    if (!Mqtt.connected()) {
-      connectMQTT();
-    }
-    Mqtt.loop();
+    if (Configuration.interface == INTERFACE_MQTT) {
+      if (!Mqtt.connected()) {
+        connectMQTT();
+      }
+      Mqtt.loop();
+    } else if (Configuration.interface == INTERFACE_HTTP) {
+      /* HTTP */
+    }
   } else if (Configuration.mode == MODE_CONFIGURATION) {
     server.handleClient();
   } else if (Configuration.mode == MODE_ACCESSPOINT) {
@@ -141,30 +145,37 @@

 /* Private methods */

+
+
+/* Method: launch into swich mode */
 void Sonoff::runSwitch() {
   Led.on();
   if (Configuration.debugger) Serial << endl << "Device mode: SWITCH" << endl;
   if (Configuration.debugger) Serial << endl << "Configuring MQTT" << endl;
-  WiFi.mode(WIFI_STA);
-  connectWiFi();
-  WiFi.mode(WIFI_STA);
-  if (Configuration.ds18b20_present) {
-    if (Configuration.debugger) Serial << endl << "Starting DS18B20" << endl;
-    setDS18B20Interval(Configuration.ds18b20_interval);
-  } else {
-    if (Configuration.debugger) Serial << endl << "DS18B20 not present" << endl;
-  }
-  if (Configuration.switch_present) {
+  if (Configuration.interface != INTERFACE_NONE) { /* If not standalone mode connect to WiFi and run DS18B20 sensor if configured */
+    WiFi.mode(WIFI_STA); /* @TODO: does it make sense? */
+    connectWiFi();
+    WiFi.mode(WIFI_STA);
+    if (Configuration.ds18b20_present) {
+      if (Configuration.debugger) Serial << endl << "Starting DS18B20" << endl;
+      setDS18B20Interval(Configuration.ds18b20_interval);
+    } else {
+
+      if (Configuration.debugger) Serial << endl << "DS18B20 not present" << endl;
+    }
+  }
+
+  if (Configuration.switch_present) { /* Run external switch if configured */
     if (Configuration.debugger) Serial << endl << "Initiating external switch" << endl;
     Switch.init(Configuration.switch_gpio);
   } else {
-      if (Configuration.debugger) Serial << endl << "External switch present" << endl;
-  }
+    if (Configuration.debugger) Serial << endl << "External switch present" << endl;
+  }
 }

 void Sonoff::runConfigurationLAN() {
   Led.on();
-  if (Configuration.debugger) Serial << endl << "Device mode: LAN Configuration" << endl;
+  if (Configuration.debugger) Serial << endl << "Device mode: LAN Configuration" << endl;
   WiFi.mode(WIFI_STA);
   connectWiFi();
   WiFi.mode(WIFI_STA);
@@ -244,6 +255,14 @@
       Eeprom.saveDebuggable(0);
     }

+    if (String(Configuration.version) == "0.3.2" ||
+        String(Configuration.version) == "0.4.0" ||
+        String(Configuration.version) == "0.5.0" ||
+        String(Configuration.version) == "0.6.1" ||
+        String(Configuration.version) == "0.7.0")
+        {
+      Eeprom.saveInterface(1);
+    }

     Configuration = Eeprom.getConfiguration();
   }


get edges add (preliminary version)

get edges add (preliminary version)

--- hb/hb.ino
+++ hb/hb.ino
@@ -56,7 +56,7 @@
 // run_state 0=not_running, 1=running, 2=on_hold
 short run_state = 0;
 boolean graph_loaded = 0;
-boolean run_noisy = 0;
+int run_delay = 0;

 // message queue
 short message_count = 0;
@@ -126,6 +126,13 @@
     debug(edges[e_index].type);
     #endif
     //n0_index = get_node("id", edges[e_index].from);
+    if (run_delay) {
+      Serial.print("buz: ");
+      Serial.print(edges[e_index].type);
+      Serial.print(" edge ");
+      Serial.println(e_index);
+      delay(run_delay);
+    }
     n1_index = get_node("id", edges[e_index].to);
     run_node(n1_index);
   }
@@ -186,12 +193,23 @@
   debug("run_node named");
   debug(nodes[n_index].name);
   #endif
+  if (run_delay) {
+    Serial.print("buz: start node ");
+    Serial.println(n_index);
+    delay(run_delay);
+  }

   // get, process, set transition
   //nodes[n_index].value = run_get_edges(n_index);
+  run_get_edges(n_index);
   //run_process();
   run_set_edges(n_index);
   run_transition(n_index);
+  if (run_delay) {
+    Serial.print("buz: end node ");
+    Serial.println(n_index);
+    delay(run_delay);
+  }

 }

@@ -206,6 +224,11 @@
     Serial.print(e_i, DEC);
     Serial.println(" fired");
     #endif
+    if (run_delay) {
+      Serial.print("buz: set edge ");
+      Serial.println(e_i);
+      delay(run_delay);
+    }
     // set edge transfers the value
     nodes[to_n_i].value = nodes[from_n_i].value;
     // ToDo better identification of an IO attribute maybe is_io() or get_io_attr().
@@ -213,6 +236,32 @@
       // ToDo stop assuming digitalWrite(...)
       digitalWrite(nodes[to_n_i].io, nodes[to_n_i].value);
     }
+  }
+}
+
+// ToDo handle more than one get edge!
+void run_get_edges(int n_index) {
+  int e_i = get_edge("get", "from", n_index);
+  if (e_i >= 0) {
+    int from_n_i = edges[e_i].from;
+    int to_n_i = edges[e_i].to;
+    #ifdef DUBUG_BUILD
+    Serial.print("get edge ");
+    Serial.print(e_i, DEC);
+    Serial.println(" fired");
+    #endif
+    if (run_delay) {
+      Serial.print("buz: get edge ");
+      Serial.println(e_i);
+      delay(run_delay);
+    }
+    // ToDo better identification of an IO attribute maybe is_io() or get_io_attr().
+    if (nodes[to_n_i].io != UNDEF_INT) {
+      // ToDo stop assuming digitalRead(...)
+      nodes[to_n_i].value = digitalRead(nodes[to_n_i].io);
+    }
+    // set edge transfers the value
+    nodes[from_n_i].value = nodes[to_n_i].value;
   }
 }