Updating low signal to blink.

Updating low signal to blink.

--- src/rx5808-pro-diversity-oled/rx5808-pro-diversity-oled.ino
+++ src/rx5808-pro-diversity-oled/rx5808-pro-diversity-oled.ino
@@ -795,9 +795,12 @@
 #endif
             if(rssi < 20)
             {
-                display.setTextColor(WHITE,BLACK);
+                display.setTextColor((millis()%250 < 125) ? WHITE : BLACK, BLACK);
                 display.setCursor(50,display.height()-13);
-                display.print("BAD SIGNAL");
+                display.print("LOW SIGNAL");
+            }
+            else {
+                display.drawLine(50,display.height()-10,110,display.height()-10,BLACK);
             }


Updated TimeCheck example

Updated TimeCheck example

--- hardware/arduino/avr/libraries/Bridge/examples/TimeCheck/TimeCheck.ino
+++ hardware/arduino/avr/libraries/Bridge/examples/TimeCheck/TimeCheck.ino
@@ -74,23 +74,6 @@
     minutes = minString.toInt();
     lastSecond = seconds;          // save to do a time comparison
     seconds = secString.toInt();
-
-    /*
-    NOTE: If the parseInt() and parseFloar() methods from Stream
-     were included with Process, this would be simpler:
-
-     hours = date.parseInt();
-     minutes = date.parseInt();
-     seconds = date.parseInt();
-
-     */
   }

 }
-
-
-
-
-
-
-


OSD usability improvements

OSD usability improvements

--- FirmwareManager/src/FirmwareManager.ino
+++ FirmwareManager/src/FirmwareManager.ino
@@ -217,10 +217,12 @@
                 break;
         }

-        safeSwitchResolution(value, [](uint8_t Address, uint8_t Value) {
-            currentMenu = &outputResSaveMenu;
-            currentMenu->Display();
-        });
+        if (value != CurrentResolution) {
+            safeSwitchResolution(value, [](uint8_t Address, uint8_t Value) {
+                currentMenu = &outputResSaveMenu;
+                currentMenu->Display();
+            });
+        }
         return;
     }
 }, [](uint8_t* menu_text) {
@@ -273,14 +275,16 @@
                 break;
         }

-        writeVideoMode2(vidMode);
-        currentMenu = &videoModeSaveMenu;
-        currentMenu->Display();
+        if (vidMode != String(videoMode)) {
+            writeVideoMode2(vidMode);
+            currentMenu = &videoModeSaveMenu;
+            currentMenu->Display();
+        }
         return;
     }
 }, [](uint8_t* menu_text) {
     // restore original menu text
-    for (int i = MENU_VM_FIRST_SELECT_LINE ; i <= MENU_OR_LAST_SELECT_LINE ; i++) {
+    for (int i = MENU_VM_FIRST_SELECT_LINE ; i < MENU_OR_LAST_SELECT_LINE ; i++) {
         menu_text[i * MENU_WIDTH] = '-';
     }
     String vidMode = String(videoMode);


Fixed slave address determination code

Fixed slave address determination code

--- I2CTest/I2CTest_Slave/I2CTest_Slave.ino
+++ I2CTest/I2CTest_Slave/I2CTest_Slave.ino
@@ -13,8 +13,10 @@
 int my_address = 0;

 void setup() {
-  pinMode(PIN_ADDRESS_BIT0, INPUT);
-  pinMode(PIN_ADDRESS_BIT1, INPUT);
+  Serial.begin(9600);
+
+  pinMode(PIN_ADDRESS_BIT0, INPUT_PULLUP);
+  pinMode(PIN_ADDRESS_BIT1, INPUT_PULLUP);
   if (my_address == 0) {
     if (digitalRead(PIN_ADDRESS_BIT0) == HIGH) my_address |= 0x1;
     if (digitalRead(PIN_ADDRESS_BIT1) == HIGH) my_address |= 0x2;
@@ -35,7 +37,14 @@
 void loop() {
   if (led_on) digitalWrite(PIN_STATUS_LED, HIGH);
   else digitalWrite(PIN_STATUS_LED, LOW);
+
+  Serial.print(my_address);
+  Serial.print(" ");
+  Serial.print(digitalRead(PIN_ADDRESS_BIT0));
+  Serial.print(" ");
+  Serial.println(digitalRead(PIN_ADDRESS_BIT1));

+  delay(10);
 }

 void receiveEvent(int howMany) {


temp fix for choosing secondary radio config

- We need to have a talk about this


Link update in comments

Link update in comments

--- leds/leds.ino
+++ leds/leds.ino
@@ -1,7 +1,7 @@
 #include <FastLED.h>
 /*
   Universal USB LED
-  https://github.com/pigetArduino/UniversalLed
+  https://github.com/madnerdorg/leds
   -----------------
   Components:
   WS2812b led (NEOPIXEL clone)
@@ -45,7 +45,7 @@
     BlinkLeds(3);
   }

-  if (readString == "/info\n"){
+  if (readString == "/info"){
     Serial.println(usb_name);
   }
 }


updating comments

updating comments

--- ESP8266-code/SharpGP2Y10.ino
+++ ESP8266-code/SharpGP2Y10.ino
@@ -1,3 +1,10 @@
+/*
+   See http://kitwallace.tumblr.com/post/141890535929/dust-sensor for details
+
+   Kit Wallace March 2016
+
+*/
+
 #include <RunningMedian.h>
 #include <ESP8266WiFi.h>

@@ -38,7 +45,7 @@
    int baseDigital = analogRead(dustPin);
    digitalWrite(ledPower,LOW); // power on the LED
    delayMicroseconds(waitToRead);
-   int readDigital =analogRead(dustPin); // read the dust value via pin 5 on the sensor
+   int readDigital =analogRead(dustPin);
    delayMicroseconds(waitToTurnOff);
    digitalWrite(ledPower,HIGH); // turn the LED off
    int dustDigital = readDigital - baseDigital;


added dummy value for MPUAddr

added dummy value for MPUAddr

--- SpaceTeam-Wireless-Arduino/SpaceTeam-Wireless-Arduino.ino
+++ SpaceTeam-Wireless-Arduino/SpaceTeam-Wireless-Arduino.ino
@@ -8,10 +8,10 @@
 #include "printf.h"
 #define DEBOUNCE_CONSTANT 10
 #define BUFFER_SIZE 128
+#define MPUAddr 1

 #include <SPI.h>
 #include "RF24.h"
-#include <Wire.h>

 int battery_pin = A1;
@@ -33,8 +33,6 @@
 int button_left = 4;
 int button_right = 6;

-
-
 typedef enum btnPrs {
   none,
   left,
@@ -46,21 +44,6 @@
   double battery_voltage;
 };

-typedef enum : uint8_t
-{
-  GYRO_PREC_250 = 0,
-  GYRO_PREC_500,
-  GYRO_PREC_1000,
-  GYRO_PREC_2000
-} gyro_precision_e;
-typedef enum : uint8_t
-{
-  ACCEL_PREC_2 = 0,
-  ACCEL_PREC_4,
-  ACCEL_PREC_8,
-  ACCEL_PREC_16
-} accel_precision_e;
-

 TransmissionStruct packet;
@@ -69,100 +52,10 @@
 int dbLS = 0;
 int dbC = 0;

-
-
-
-// This function must be able to toggle sleep mode for the MPU6050
-void setSleep(bool enable) {
-  Wire.beginTransmission(MPUAddr);
-  Wire.write(0x6B);
-  Wire.endTransmission(false);
-  Wire.requestFrom(MPUAddr, 1, true);
-  uint8_t power = Wire.read(); // read 0x6B
-  power &= ~(1 << 6);
-  power |= (power ? 1 : 0) << 6;
-
-  Wire.beginTransmission(MPUAddr);
-  Wire.write(0x6B);
-  Wire.write(power);
-  Wire.endTransmission(true);
-}
-
-void read3_16Bits( int a_h, int16_t* ax, int b_h, int16_t* bx, int c_h, int16_t* cx) {
-
-  for (int j = 0; j < 3; j++) {
-    for (int i = 0; i < 2; i++) {
-
-      int address;
-      int16_t* value;
-
-      if (j == 0) {
-        address = a_h;
-        value = ax;
-      } else if (j == 1) {
-        address = b_h;
-        value = bx;
-      } else if (j == 2) {
-        address = c_h;
-        value = cx;
-      }
-
-      Wire.beginTransmission(MPUAddr);
-      Wire.write(address + i);
-      bool lastTransmission = (i == 1 && j == 2);
-      Wire.endTransmission(lastTransmission);
-      Wire.requestFrom(MPUAddr, 1, true);
-      *(((int8_t *) value) + i) = Wire.read(); // read 0x6B
-    }
-  }
-}
-
-// This function needs to return by reference the accelerometer values stored in the accelerometer registers.
-void getAccelData( int16_t* ax,int16_t* ay, int16_t* az) {
-  read3_16Bits(
-    0x3B, ax,
-    0x3D, ay,
-    0x3F, az
-  );
-}
-
-// This function needs to return by reference the gyroscope values stored in the accelerometer registers.
-void getGyroData( int16_t* gx,int16_t* gy, int16_t* gz) {
-  read3_16Bits(
-    0x43, gx,
-    0x45, gy,
-    0x47, gz
-  );
-}
-
-// This function needs to set the precision bits for the gyroscope to val (refer to the lecture slides)
-void setGyroPrec(gyro_precision_e prec) {
-  Wire.beginTransmission(MPUAddr);
-  Wire.write(0x1B);
-  Wire.write((0b11 & prec) << 3);
-  Wire.endTransmission(true);
-}
-
-// This function needs to set the precision bits for the accelerometer to val (refer to the lecture slides)
-void setAccelPrec(accel_precision_e prec) {
-  Wire.beginTransmission(MPUAddr);
-  Wire.write(0x1C);
-  Wire.write((0b11 & prec) << 3);
-  Wire.endTransmission(true);
-
-}
-
-
-
-
-
-
-
 // the setup routine runs once when you press reset:
 void setup() {
   // initialize serial communication at 9600 bits per second:
   Serial.begin(9600);
-  Wire.Begin();

   pinMode(button_left, INPUT);
   pinMode(button_right, INPUT);
@@ -287,5 +180,3 @@
   // radio.stopListening();
   radio.write(&packet, sizeof(TransmissionStruct));
 }
-
-


Restructure control logic

Restructure control logic

--- interduino/src/sketch.ino
+++ interduino/src/sketch.ino
@@ -16,12 +16,12 @@
 		int ledState = Serial.read();
 		if(ledState == 65){
 			digitalWrite(13, HIGH);
+			delay(7000);
+			digitalWrite(13, LOW);
 		}
 //		if(ledState == 90){
 //			digitalWrite(13, LOW);
 //		}
-	delay(7000);
-	digitalWrite(13, LOW);
 	}
 }


rename variable to avoid mistake

rename variable to avoid mistake

--- arduino/sadr_meteo_no_firmata/sadr_meteo_no_firmata.ino
+++ arduino/sadr_meteo_no_firmata/sadr_meteo_no_firmata.ino
@@ -143,7 +143,7 @@
   int samples[NUMSAMPLES];
   // Variables pour PID
   // Measured temperature
-  double Temp;
+  double TempRain;
   // PWM value 0-255 :
   double Mosfet;

@@ -152,7 +152,7 @@
   // Define the aggressive and conservative Tuning Parameters
   double aggKp = 43.7, aggKi = 0.323, aggKd = 7.18;
   double consKp = 4.47, consKi = 0.033, consKd = 0.734;
-  PID myPID(&Temp, &Mosfet, &Consigne, consKp, consKi, consKd, DIRECT);
+  PID myPID(&TempRain, &Mosfet, &Consigne, consKp, consKi, consKd, DIRECT);
 #endif //USE_RAIN_SENSOR*/

 float T22int,Hr22int,DewInt,T22ext,Hr22ext,DewExt,Light,Tp,P,T,IR,Clouds,skyT,Tir,WindSpeed,MaxWindSpeed,Capacity,reedSwitchDeltaTime, stringCheck;
@@ -172,8 +172,8 @@
         SUM += 8.1328e-3 * (pow(10,(-3.49149*(AZERO-1)))-1) ;
         SUM += log10(1013.246);
         double VP = pow(10, SUM-3) * humidity;
-        double T = log(VP/0.61078);   // temp var
-        return (241.88 * T) / (17.558-T);
+        double Tvar = log(VP/0.61078);   // temp var
+        return (241.88 * Tvar) / (17.558-Tvar);
 }

 // delta max = 0.6544 wrt dewPoint()
@@ -435,7 +435,7 @@

 #ifdef USE_RAIN_SENSOR
     //Asking for temperature of the rain sensor
-    Temp = getTemperature();
+    TempRain = getTemperature();
     Capacity = rain(NUMSAMPLES);
     if (Capacity > RAIN_FLAG_TRIGGER) {
       rainy=1;
@@ -463,7 +463,7 @@
     // Sum output variable
     float checksum = stringCheck = T + frezzing + Light + daylight + T22int + Hr22int + T22ext + Hr22ext + DewExt +
     dewing + Tir + IR + skyT + Clouds + cloudy + P + Tp + WindSpeed + MaxWindSpeed + windy + Capacity +
-    rainy + Consigne + Temp + Mosfet ;
+    rainy + Consigne + TempRain + Mosfet ;

     // If everything is ok, function return TRUE
     if (isnan(checksum) || isinf(checksum)) {
@@ -546,7 +546,7 @@
     Serial.print(":");
     Serial.print(Consigne);
     Serial.print(":");
-    Serial.print(Temp);
+    Serial.print(TempRain);
     Serial.print(":");
     Serial.println(Mosfet);
 #endif //USE_DHT_RAIN_SENSOR*/
@@ -580,8 +580,8 @@
      }
   }

-  if ((Temp <= HOT_TEMPERATURE_SECURITY) | (Temp >= COLD_TEMPERATURE_SECURITY)) {
-    regulHeat(Temp, Consigne);
+  if ((TempRain <= HOT_TEMPERATURE_SECURITY) | (TempRain >= COLD_TEMPERATURE_SECURITY)) {
+    regulHeat(TempRain, Consigne);
   } else {
     if (rainy == 1) {
         Mosfet = 100;


Is this a compiler bug? @jcw help?

Is this a compiler bug? @jcw help?

At "Workplace" replacing /* ...49-day... */ with compiler directives
causes all sorts of compile problems. Change it back and all OK!

--- examples/RF12/RF12demo/RF12demo.ino
+++ examples/RF12/RF12demo/RF12demo.ino
@@ -11,8 +11,9 @@
 #include <avr/eeprom.h>
 #include <avr/pgmspace.h>
 #include <util/parity.h>
-
+#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
 #include <ttyIn.h>
+#endif

 #define DEBUG 1

@@ -34,14 +35,14 @@
 #define FLASH_MBIT  16  // support for various dataflash sizes: 4/8/16 Mbit

 #define LED_PIN   9     // activity LED, comment out to disable
-
-#endif
-
+#endif
+///////////   Workplace   //////////
+/*
 static unsigned long now () {
   // FIXME 49-day overflow
   return millis() / 1000;
 }
-
+*/
 static void activityLed (byte on) {
 #ifdef LED_PIN
   pinMode(LED_PIN, OUTPUT);
@@ -174,7 +175,8 @@
    return band == 4 ? RF12_433MHZ : band == 8 ? RF12_868MHZ : band == 9 ? RF12_915MHZ : 0;
 }

-#if not defined(__AVR_ATtiny84__) || not defined(__AVR_ATtiny44__)
+#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
+#else
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 // OOK transmit code

@@ -1068,7 +1070,8 @@
       showByte(rf12_data[i]);
     }
     Serial.println();
-/*
+#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
+#else
   if (useHex > 1) {  // Print ascii interpretation under hex output
     showString(PSTR("ASC"));
     if (config.group == 0) {
@@ -1078,10 +1081,11 @@
     Serial.print(char((rf12_hdr & RF12_HDR_MASK) | 0x40)); // Convert node number into a letter, A to Z to undersore (1-31)
     displayASCII(rf12_data, n);
   }
-*/
+#endif
     if (rf12_crc == 0) {
       activityLed(1);
-#if not defined(__AVR_ATtiny84__) || not defined(__AVR_ATtiny44__)
+#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
+#else
       if (df_present())
         df_append((const char*) rf12_data - 2, rf12_len + 2);
 #endif


cleanup

cleanup

--- examples/RF12/RF12demo/RF12demo.ino
+++ examples/RF12/RF12demo/RF12demo.ino
@@ -133,7 +133,7 @@
     byte hex_output   :2;   // 0 = dec, 1 = hex, 2 = hex+ascii
     byte collect_mode :1;   // 0 = ack, 1 = don't send acks
     byte quiet_mode   :1;   // 0 = show all, 1 = show only valid packets
-    byte spare_flags  :4;
+    byte spare_flags  :4;
     word frequency_offset;  // used by rf12_config, offset 4
     byte pad[RF12_EEPROM_SIZE-8];
     word crc;
@@ -334,7 +334,7 @@
         value = 10 * value + c - '0';
         return;
     }
-
+
     if (c == ',') {
         if (top < sizeof stack)
             stack[top++] = value;
@@ -477,10 +477,13 @@
         case 'v': //display the interpreter version and configuration
             displayVersion();
             rf12_configDump();
+#if TINY
+            Serial.println();
+#endif
             break;

 // the following commands all get optimised away when TINY is set
-
+
         case 'l': // turn activity LED on or off
             activityLed(value);
             break;
@@ -568,7 +571,7 @@
         rf12_configSilent();
     }

-    rf12_configDump();
+    rf12_configDump();
     df_initialize();
 #if !TINY
     showHelp();
@@ -616,7 +619,7 @@
         showString(PSTR(") "));
 #endif
         Serial.println();
-
+
         if (config.hex_output > 1) { // also print a line as ascii
             showString(PSTR("ASC "));
             if (config.group == 0) {
@@ -626,7 +629,7 @@
             printOneChar('@' + (rf12_hdr & RF12_HDR_MASK));
             displayASCII((const uint8_t*) rf12_data, n);
         }
-
+
         if (rf12_crc == 0) {
             activityLed(1);


implement gauge button

implement gauge button

--- main/main.ino
+++ main/main.ino
@@ -133,9 +133,17 @@

 // GAUGE ARRAYS FOR EACH MODE ////////////////////////

-EngineVariable* dualModeGauges[3][2];
-EngineVariable* quadModeGauges[2][4];
-EngineVariable* octoModeGauges[1][8];
+const byte DUAL_LEN = 3;
+const byte QUAD_LEN = 2;
+const byte OCTO_LEN = 1;
+
+byte dualIndex = 0;
+byte quadIndex = 0;
+byte octoIndex = 0;
+
+EngineVariable* dualModeGauges[DUAL_LEN][2];
+EngineVariable* quadModeGauges[QUAD_LEN][4];
+EngineVariable* octoModeGauges[OCTO_LEN][8];

 // MODE VARIABLES ////////////////////////////////////

@@ -152,9 +160,6 @@
 bool octoModeReady = false;
 bool diagModeReady = false;

-bool dualModeIndex = 0;
-bool quadModeIndex = 0;
-bool octoModeIndex = 0;
 bool inError = false;

 bool currentModeButton = 1;
@@ -197,10 +202,23 @@
   dualModeGauges[0][0] = &engine_rpm;
   dualModeGauges[0][1] = &engine_afr;

+  dualModeGauges[1][0] = &engine_map;
+  dualModeGauges[1][1] = &engine_afr;
+
+  dualModeGauges[2][0] = &engine_afr;
+  dualModeGauges[2][1] = &engine_tgt;
+
   quadModeGauges[0][0] = &engine_rpm;
   quadModeGauges[0][1] = &engine_map;
   quadModeGauges[0][2] = &engine_afr;
   quadModeGauges[0][3] = &engine_tps;
+
+  quadModeGauges[1][0] = &engine_map;
+  quadModeGauges[1][1] = &engine_afr;
+  quadModeGauges[1][2] = &engine_clt;
+  quadModeGauges[1][3] = &engine_iat;
+
+

   allGauges[0] = &engine_map;
   allGauges[1] = &engine_rpm;
@@ -289,6 +307,7 @@
     if(currentGaugeButton == 0) {
       gaugeButtonMillis = currentMillis;
       Serial.println("next gauge");
+      next_gauge();
     }
     else {
       if((currentMillis - gaugeButtonMillis) < DEBOUNCE_DELAY) {
@@ -309,6 +328,39 @@
     currentMode = dual;
   }
   //diag mode is not implemented yet
+}
+
+void next_gauge() {
+
+  clear_mode();
+
+  if(currentMode == dual) {
+    if(dualIndex == (DUAL_LEN - 1)) {
+      dualIndex = 0;
+    }
+    else {
+      dualIndex++;
+    }
+  }
+  else if(currentMode == quad) {
+    if(quadIndex == (QUAD_LEN - 1)) {
+      quadIndex = 0;
+    }
+    else {
+      quadIndex++;
+    }
+  }
+  else if(currentMode == octo) {
+    if(octoIndex == (OCTO_LEN - 1)) {
+      octoIndex = 0;
+    }
+    else {
+      octoIndex++;
+    }
+  }
+  else {
+    Serial.println("unknown mode");
+  }
 }

 void clear_mode() {
@@ -323,28 +375,28 @@
   if(!dualModeReady) {
     clear_mode();
     lcd.setCursor(0, 0);
-    lcd.print(dualModeGauges[0][0]->shortLabel);
+    lcd.print(dualModeGauges[dualIndex][0]->shortLabel);
     lcd.setCursor(0, 2);
-    lcd.print(dualModeGauges[0][1]->shortLabel);
+    lcd.print(dualModeGauges[dualIndex][1]->shortLabel);
     dualModeReady = true;
   }
-  //if(dualModeGauges[0][0]->currentValue != dualModeGauges[0][0]->previousValue) {
+  //if(dualModeGauges[0][0]->currentValue != dualModeGauges[dualIndex][0]->previousValue) {
     lcd.setCursor(4, 0);
     if(is_current_value_shorter(*dualModeGauges[0][0])) {
       lcd.print(F("     "));
       lcd.setCursor(4, 0);
     }
-    lcd.print(dualModeGauges[0][0]->currentValue, dualModeGauges[0][0]->decimalPlaces);
-    draw_bar(*dualModeGauges[0][0], 1, 0);
+    lcd.print(dualModeGauges[dualIndex][0]->currentValue, dualModeGauges[dualIndex][0]->decimalPlaces);
+    draw_bar(*dualModeGauges[dualIndex][0], 1, 0);
   //}
   //if(dualModeGauges[0][1]->currentValue != dualModeGauges[0][1]->previousValue) {
     lcd.setCursor(4, 2);
-    if(is_current_value_shorter(*dualModeGauges[0][1])) {
+    if(is_current_value_shorter(*dualModeGauges[dualIndex][1])) {
       lcd.print(F("     "));
       lcd.setCursor(4, 2);
     }
-    lcd.print(dualModeGauges[0][1]->currentValue, dualModeGauges[0][1]->decimalPlaces);
-    draw_bar(*dualModeGauges[0][1], 3, 0);
+    lcd.print(dualModeGauges[dualIndex][1]->currentValue, dualModeGauges[dualIndex][1]->decimalPlaces);
+    draw_bar(*dualModeGauges[dualIndex][1], 3, 0);
   //}
 }

@@ -352,47 +404,47 @@
   if(!quadModeReady) {
     clear_mode();
     lcd.setCursor(0, 0);
-    lcd.print(quadModeGauges[0][0]->shortLabel);
+    lcd.print(quadModeGauges[quadIndex][0]->shortLabel);
     lcd.setCursor(0, 1);
-    lcd.print(quadModeGauges[0][1]->shortLabel);
+    lcd.print(quadModeGauges[quadIndex][1]->shortLabel);
     lcd.setCursor(0, 2);
-    lcd.print(quadModeGauges[0][2]->shortLabel);
+    lcd.print(quadModeGauges[quadIndex][2]->shortLabel);
     lcd.setCursor(0, 3);
-    lcd.print(quadModeGauges[0][3]->shortLabel);
+    lcd.print(quadModeGauges[quadIndex][3]->shortLabel);
     quadModeReady = true;
   }

   lcd.setCursor(4, 0);
-  if(is_current_value_shorter(*quadModeGauges[0][0])) {
+  if(is_current_value_shorter(*quadModeGauges[quadIndex][0])) {
     lcd.print(F("     "));
     lcd.setCursor(4, 0);
   }
-  lcd.print(quadModeGauges[0][0]->currentValue, quadModeGauges[0][0]->decimalPlaces);
-  draw_bar(*quadModeGauges[0][0], 0, 9);
+  lcd.print(quadModeGauges[quadIndex][0]->currentValue, quadModeGauges[quadIndex][0]->decimalPlaces);
+  draw_bar(*quadModeGauges[quadIndex][0], 0, 9);

   lcd.setCursor(4, 1);
-  if(is_current_value_shorter(*quadModeGauges[0][1])) {
+  if(is_current_value_shorter(*quadModeGauges[quadIndex][1])) {
     lcd.print(F("     "));
     lcd.setCursor(4, 1);
   }
-  lcd.print(quadModeGauges[0][1]->currentValue, quadModeGauges[0][1]->decimalPlaces);
-  draw_bar(*quadModeGauges[0][1], 1, 9);
+  lcd.print(quadModeGauges[quadIndex][1]->currentValue, quadModeGauges[quadIndex][1]->decimalPlaces);
+  draw_bar(*quadModeGauges[quadIndex][1], 1, 9);

   lcd.setCursor(4, 2);
-  if(is_current_value_shorter(*quadModeGauges[0][2])) {
+  if(is_current_value_shorter(*quadModeGauges[quadIndex][2])) {
     lcd.print(F("     "));
     lcd.setCursor(4, 2);
   }
-  lcd.print(quadModeGauges[0][2]->currentValue, quadModeGauges[0][2]->decimalPlaces);
-  draw_bar(*quadModeGauges[0][2], 2, 9);
+  lcd.print(quadModeGauges[quadIndex][2]->currentValue, quadModeGauges[quadIndex][2]->decimalPlaces);
+  draw_bar(*quadModeGauges[quadIndex][2], 2, 9);

   lcd.setCursor(4, 3);
-  if(is_current_value_shorter(*quadModeGauges[0][3])) {
+  if(is_current_value_shorter(*quadModeGauges[quadIndex][3])) {
     lcd.print(F("     "));
     lcd.setCursor(4, 3);
   }
-  lcd.print(quadModeGauges[0][3]->currentValue, quadModeGauges[0][3]->decimalPlaces);
-  draw_bar(*quadModeGauges[0][3], 3, 9);
+  lcd.print(quadModeGauges[quadIndex][3]->currentValue, quadModeGauges[quadIndex][3]->decimalPlaces);
+  draw_bar(*quadModeGauges[quadIndex][3], 3, 9);
 }

 void draw_octo_gauges() {
@@ -401,13 +453,13 @@
     clear_mode();
     //left column of labels
     lcd.setCursor(0, 0);
-    lcd.print(octoModeGauges[0][0]->shortLabel);
+    lcd.print(octoModeGauges[octoIndex][0]->shortLabel);
     lcd.setCursor(0, 1);
-    lcd.print(octoModeGauges[0][1]->shortLabel);
+    lcd.print(octoModeGauges[octoIndex][1]->shortLabel);
     lcd.setCursor(0, 2);
-    lcd.print(octoModeGauges[0][2]->shortLabel);
+    lcd.print(octoModeGauges[octoIndex][2]->shortLabel);
     lcd.setCursor(0, 3);
-    lcd.print(octoModeGauges[0][3]->shortLabel);
+    lcd.print(octoModeGauges[octoIndex][3]->shortLabel);

     //draw dividing line
     lcd.setCursor(9, 0);
@@ -421,72 +473,72 @@

     //right column of labels
     lcd.setCursor(11, 0);
-    lcd.print(octoModeGauges[0][4]->shortLabel);
+    lcd.print(octoModeGauges[octoIndex][4]->shortLabel);
     lcd.setCursor(11, 1);
-    lcd.print(octoModeGauges[0][5]->shortLabel);
+    lcd.print(octoModeGauges[octoIndex][5]->shortLabel);
     lcd.setCursor(11, 2);
-    lcd.print(octoModeGauges[0][6]->shortLabel);
+    lcd.print(octoModeGauges[octoIndex][6]->shortLabel);
     lcd.setCursor(11, 3);
-    lcd.print(octoModeGauges[0][7]->shortLabel);
+    lcd.print(octoModeGauges[octoIndex][7]->shortLabel);

     octoModeReady = true;
   }

   lcd.setCursor(4, 0);
-  if(is_current_value_shorter(*octoModeGauges[0][0])) {
+  if(is_current_value_shorter(*octoModeGauges[octoIndex][0])) {
     lcd.print(F("     "));
     lcd.setCursor(4, 0);
   }
-  lcd.print(octoModeGauges[0][0]->currentValue, octoModeGauges[0][0]->decimalPlaces);
+  lcd.print(octoModeGauges[octoIndex][0]->currentValue, octoModeGauges[octoIndex][0]->decimalPlaces);

   lcd.setCursor(4, 1);
-  if(is_current_value_shorter(*octoModeGauges[0][1])) {
+  if(is_current_value_shorter(*octoModeGauges[octoIndex][1])) {
     lcd.print(F("     "));
     lcd.setCursor(4, 1);
   }
-  lcd.print(octoModeGauges[0][1]->currentValue, octoModeGauges[0][1]->decimalPlaces);
+  lcd.print(octoModeGauges[octoIndex][1]->currentValue, octoModeGauges[octoIndex][1]->decimalPlaces);

   lcd.setCursor(4, 2);
-  if(is_current_value_shorter(*octoModeGauges[0][2])) {
+  if(is_current_value_shorter(*octoModeGauges[octoIndex][2])) {
     lcd.print(F("     "));
     lcd.setCursor(4, 2);
   }
-  lcd.print(octoModeGauges[0][2]->currentValue, octoModeGauges[0][2]->decimalPlaces);
+  lcd.print(octoModeGauges[octoIndex][2]->currentValue, octoModeGauges[octoIndex][2]->decimalPlaces);

   lcd.setCursor(4, 3);
-  if(is_current_value_shorter(*octoModeGauges[0][3])) {
+  if(is_current_value_shorter(*octoModeGauges[octoIndex][3])) {
     lcd.print(F("     "));
     lcd.setCursor(4, 3);
   }
-  lcd.print(octoModeGauges[0][3]->currentValue, octoModeGauges[0][3]->decimalPlaces);
+  lcd.print(octoModeGauges[octoIndex][3]->currentValue, octoModeGauges[octoIndex][3]->decimalPlaces);

   lcd.setCursor(15, 0);
-  if(is_current_value_shorter(*octoModeGauges[0][4])) {
+  if(is_current_value_shorter(*octoModeGauges[octoIndex][4])) {
     lcd.print(F("     "));
     lcd.setCursor(15, 0);
   }
-  lcd.print(octoModeGauges[0][4]->currentValue, octoModeGauges[0][4]->decimalPlaces);
+  lcd.print(octoModeGauges[octoIndex][4]->currentValue, octoModeGauges[octoIndex][4]->decimalPlaces);

   lcd.setCursor(15, 1);
-  if(is_current_value_shorter(*octoModeGauges[0][5])) {
+  if(is_current_value_shorter(*octoModeGauges[octoIndex][5])) {
     lcd.print(F("     "));
     lcd.setCursor(15, 1);
   }
-  lcd.print(octoModeGauges[0][5]->currentValue, octoModeGauges[0][5]->decimalPlaces);
+  lcd.print(octoModeGauges[octoIndex][5]->currentValue, octoModeGauges[octoIndex][5]->decimalPlaces);

   lcd.setCursor(15, 2);
-  if(is_current_value_shorter(*octoModeGauges[0][6])) {
+  if(is_current_value_shorter(*octoModeGauges[octoIndex][6])) {
     lcd.print(F("     "));
     lcd.setCursor(15, 2);
   }
-  lcd.print(octoModeGauges[0][6]->currentValue, octoModeGauges[0][6]->decimalPlaces);
+  lcd.print(octoModeGauges[octoIndex][6]->currentValue, octoModeGauges[octoIndex][6]->decimalPlaces);

   lcd.setCursor(15, 3);
-  if(is_current_value_shorter(*octoModeGauges[0][7])) {
+  if(is_current_value_shorter(*octoModeGauges[octoIndex][7])) {
     lcd.print(F("     "));
     lcd.setCursor(15, 3);
   }
-  lcd.print(octoModeGauges[0][7]->currentValue, octoModeGauges[0][7]->decimalPlaces);
+  lcd.print(octoModeGauges[octoIndex][7]->currentValue, octoModeGauges[octoIndex][7]->decimalPlaces);
 }

 void load_from_can() {


Update mech.ino

Update mech.ino

--- mech/mech.ino
+++ mech/mech.ino
@@ -157,7 +157,7 @@
   while (step != 0) {
     chanel->move(step);
     yeld();
-    if (prevSetepPwr < (rflPwrVal - hysteresis)) {
+    if (prevSetepPwr < (rflPwrVal + hysteresis)) {
       step = -step;
       if (!isFirstStep) {
         step = step >> 1;
@@ -178,9 +178,9 @@
   isAutoTune = 1;
   stepperC1.moveTo(10);
   stepperC2.moveTo(10);
-  optimize(&stepperL, 2000, 32);
-  optimize(&stepperC1, 20, 32);
-  optimize(&stepperC2, 20, 32);
+  optimize(&stepperL, 2000, 0);
+  optimize(&stepperC1, 20, 0);
+  optimize(&stepperC2, 20, 0);
   isAutoTune = 0;
 }


Update example

Update example

--- examples/Boards_USB_Serial/Blue_Pill_STM32F103C8/Blue_Pill_STM32F103C8.ino
+++ examples/Boards_USB_Serial/Blue_Pill_STM32F103C8/Blue_Pill_STM32F103C8.ino
@@ -17,13 +17,14 @@
  * to connect your project to Blynk.
  * Feel free to apply it to any other example. It's simple!
  *
- * Requires STM32duino: https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki/Installation
+ * Requires STM32duino core:
+ *   https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki/Installation
  *
  **************************************************************
  *            USB HOWTO: http://tiny.cc/BlynkUSB
  **************************************************************/

-#define BLYNK_PRINT Serial2
+#define BLYNK_PRINT Serial1
 #include <BlynkSimpleStream.h>

 // You should get Auth Token in the Blynk App.
@@ -33,7 +34,7 @@
 void setup()
 {
   // Debug console
-  Serial2.begin(9600);
+  Serial1.begin(9600);

   // Blynk will work through Serial
   Serial.begin(9600);


changed some commands

changed some commands

MS -> SM; D -> SD; L -> SL

--- jenny5-firmware/jenny5-firmware.ino
+++ jenny5-firmware/jenny5-firmware.ino
@@ -39,7 +39,7 @@
 void setup()
 {
   first_start = 0;
-  strcpy(firmware_version, "2016.07.16.0");
+  strcpy(firmware_version, "2016.07.27.0");

   current_buffer[0] = 0;

@@ -116,23 +116,56 @@
     // can be more than 1 command in a string, so I have to check again for a letter
     if ((tmp_str[i] >= 'A' && tmp_str[i] <= 'Z') || (tmp_str[i] >= 'a' && tmp_str[i] <= 'z')) {

-      if (tmp_str[i] == 'M' || tmp_str[i] == 'm') { // moves motor
-        if (tmp_str[i + 1] == 'S' || tmp_str[i + 1] == 's') { // stepper motor
-          int motor_index, num_steps;
-          int num_read = sscanf(tmp_str + i + 2, "%d%d", &motor_index, &num_steps);
-        //  Serial.print(motor_index);
-        //  Serial.write(' ');
-        //  Serial.println(num_steps);
-          if (num_read == 2) {
-            stepper_motors_controller.move_motor(motor_index, num_steps);
-            is_command_running = 1;
-            i += 5;
-          }
-          else
-            i++;// error on incomplete string (does nothing)
-        }
-        else if (tmp_str[i + 1] == 'D' || tmp_str[i + 1] == 'd') { // DC motor
-          int motor_index, num_miliseconds;
+		if (tmp_str[i] == 'S' || tmp_str[i] == 's') { // stepper motor
+			if (tmp_str[i + 1] == 'M' || tmp_str[i + 1] == 'm') { // move motor
+				int motor_index, num_steps;
+       int num_consumed;
+				int num_read = sscanf(tmp_str + i + 2, "%d%d%n", &motor_index, &num_steps, &num_consumed);
+				if (num_read == 2) {
+					stepper_motors_controller.move_motor(motor_index, num_steps);
+					is_command_running = 1;
+					i += 2 + num_consumed;
+				}
+				else
+					i++;// error on incomplete string (does nothing)
+			}
+			else
+			if (tmp_str[i + 1] == 'D' || tmp_str[i + 1] == 'd') { // disable motor
+				int motor_index;
+					sscanf(tmp_str + i + 2, "%d", &motor_index);
+					stepper_motors_controller.disable(motor_index);
+					sprintf(tmp_serial_out, "SD%d#", motor_index);
+					strcat(serial_out, tmp_serial_out);
+					i += 4;
+			}
+			// locks motor
+			else
+			if (tmp_str[i + 1] == 'L' || tmp_str[i + 1] == 'l') {
+				int motor_index;
+				sscanf(tmp_str + i + 2, "%d", &motor_index);
+				stepper_motors_controller.lock(motor_index);
+				sprintf(tmp_serial_out, "SL%d#", motor_index);
+				strcat(serial_out, tmp_serial_out);
+				i += 4;
+			}
+     else
+        if (tmp_str[i + 1] == 'S' || tmp_str[i + 1] == 's') { // stepper motor speed and acceleration
+          int motor_index;
+          int motor_speed, motor_acceleration;
+          int num_consumed;
+          sscanf(tmp_str + i + 2, "%d%d%d%n", &motor_index, &motor_speed, &motor_acceleration, &num_consumed);
+          stepper_motors_controller.set_speed_and_acceleration(motor_index, motor_speed, motor_acceleration);
+          i += 2 + num_consumed;
+        }
+			else
+				i++;
+			continue;
+		}
+
+        // dc motor
+		if (tmp_str[i + 1] == 'D' || tmp_str[i + 1] == 'd') { // DC motor
+			if (tmp_str[i + 1] == 'M' || tmp_str[i + 1] == 'm') { // stepper motor
+				int motor_index, num_miliseconds;
           int num_read = sscanf(tmp_str + i + 2, "%d%d", &motor_index, &num_miliseconds);
           if (num_read == 2) {
             dc_motors_controller_TB6612FNG.move_motor(motor_index, num_miliseconds);
@@ -142,6 +175,16 @@
           else
             i++;// error on incomplete string (does nothing)
         }
+			// disables motor
+			else if (tmp_str[i + 1] == 'D' || tmp_str[i + 1] == 'd') { // disables DC motor
+				int motor_index;
+				sscanf(tmp_str + i + 2, "%d", &motor_index);
+				dc_motors_controller_TB6612FNG.disable(motor_index);
+				sprintf(tmp_serial_out, "DD%d#", motor_index);
+				strcat(serial_out, tmp_serial_out);
+				i += 4;
+			}
+
         else
           i++; // incomplete string
         continue;
@@ -189,35 +232,12 @@
         continue;
       }

-      // disables motor
-      if (tmp_str[i] == 'D' || tmp_str[i] == 'd') {
-        int motor_index;
-        if (tmp_str[i + 1] == 'S' || tmp_str[i + 1] == 's') { // disables stepper motor
-          sscanf(tmp_str + i + 2, "%d", &motor_index);
-          stepper_motors_controller.disable(motor_index);
-          sprintf(tmp_serial_out, "DS%d#", motor_index);
-          strcat(serial_out, tmp_serial_out);
-        }
-        else if (tmp_str[i + 1] == 'D' || tmp_str[i + 1] == 'd') { // disables DC motor
-          sscanf(tmp_str + i + 2, "%d", &motor_index);
-          dc_motors_controller_TB6612FNG.disable(motor_index);
-          sprintf(tmp_serial_out, "DD%d#", motor_index);
-          strcat(serial_out, tmp_serial_out);
-        }
-        i += 4;
-        continue;
-      }
-
-      // locks motor
-      if (tmp_str[i] == 'L' || tmp_str[i] == 'l') {
-        int motor_index;
-        sscanf(tmp_str + i + 1, "%d", &motor_index);
-        stepper_motors_controller.lock(motor_index);
-        sprintf(tmp_serial_out, "L%d#", motor_index);
-        strcat(serial_out, tmp_serial_out);
-        i += 2;
-        continue;
-      }
+	  // LIDAR
+	  if (tmp_str[i] == 'L' || tmp_str[i] == 'l') {
+		  tera_ranger_one_lidar->start();
+		  i +=2;
+		  continue;
+	  }

       // go home
       if (tmp_str[i] == 'H' || tmp_str[i] == 'h') {
@@ -236,14 +256,8 @@
       }

       // sets something
+/*
       if (tmp_str[i] == 'S' || tmp_str[i] == 's') {
-        if (tmp_str[i + 1] == 'S' || tmp_str[i + 1] == 's') { // stepper motor speed and acceleration
-          int motor_index;
-          int motor_speed, motor_acceleration;
-          sscanf(tmp_str + i + 2, "%d%d%d", &motor_index, &motor_speed, &motor_acceleration);
-          stepper_motors_controller.set_speed_and_acceleration(motor_index, motor_speed, motor_acceleration);
-          i += 5;
-        }
         else if (tmp_str[i + 1] == 'P' || tmp_str[i + 1] == 'p') { // potentiometer min max home
           int pot_index, pot_min, pot_max, pot_home, pot_pin, pot_dir;
           sscanf(tmp_str + i + 2, "%d%d%d%d%d%d", &pot_index, &pot_pin, &pot_min, &pot_max, &pot_home, &pot_dir);
@@ -259,7 +273,7 @@
         }
         continue;
       }
-
+*/
       if (tmp_str[i] == 'A' || tmp_str[i] == 'a') { // attach sensors to motors
         int motor_index, num_sensors;
         char motor_type = tmp_str[i + 1];
@@ -526,22 +540,19 @@
           i += 3;
         }
         else
-            if (tmp_str[i + 1] == 'L' || tmp_str[i + 1] == 'l') { // create a LIDAR
+            if (tmp_str[i + 1] == 'L' || tmp_str[i + 1] == 'l') { // creates a LIDAR

-            int num_consumed = 0;
+              int num_consumed = 0;
               int _dir_pin, _step_pin, _enable_pin, _infrared_pin;
-              sscanf(tmp_str + i, "%d%d%d%d%n", &_dir_pin, &_step_pin, &_enable_pin, &_infrared_pin, &num_consumed);
-			  tera_ranger_one_lidar = new t_tera_ranger_one_lidar(_dir_pin, _step_pin, _enable_pin, _infrared_pin);
-			  //tera_ranger_one_lidar.set_pins(_dir_pin, _step_pin, _enable_pin, _infrared_pin);
-
+              sscanf(tmp_str + i + 2, "%d%d%d%d%n", &_dir_pin, &_step_pin, &_enable_pin, &_infrared_pin, &num_consumed);
+			        tera_ranger_one_lidar = new t_tera_ranger_one_lidar(_dir_pin, _step_pin, _enable_pin, _infrared_pin);

-			  //tera_ranger_one_lidar.disable_all();
-            sprintf(tmp_serial_out, "CL#");
-            strcat(serial_out, tmp_serial_out);
-            i += num_consumed;
-        }
-        else
-          i++; // incomplete string
+              sprintf(tmp_serial_out, "CL#");
+              strcat(serial_out, tmp_serial_out);
+              i += num_consumed + 2;
+            }
+            else
+              i++; // incomplete string
         continue;
       }
       else
@@ -642,9 +653,12 @@
      serial_out[0] = 0;
   }

-  //   Serial.print("freeMemory()=");
-  // Serial.println(freeMemory());
-
-  //delay(1000);
+  if (tera_ranger_one_lidar) {
+	  tera_ranger_one_lidar->run_motor(serial_out);
+	  if (serial_out[0]) {
+		  Serial.write(serial_out);
+		  serial_out[0] = 0;
+	  }
+  }
 }
 //------------------------------------------------------------------------------


score display bugfix in duino says

score display bugfix in duino says

--- arduino/duinosays/duinosays.ino
+++ arduino/duinosays/duinosays.ino
@@ -455,7 +455,7 @@
             if (tag == 0) break;
             uint16_t score = scores.getScore(i);
             buffer.drawText(stringBuffer.start().putDec(i).put(')').get(),10,15 + i * 8,buffer.rgb(255,255,255), &virtualDJ_5ptFontInfo);
-            buffer.drawText(stringBuffer.start().put(tag).get(),38,15 + i * 8,buffer.rgb(255,255,255), &virtualDJ_5ptFontInfo);
+            buffer.drawText(stringBuffer.start().put(tag[0]).put(tag[1]).put(tag[2]).get(),38,15 + i * 8,buffer.rgb(255,255,255), &virtualDJ_5ptFontInfo);
             buffer.drawText(stringBuffer.start().putDec(score).get(),81 - score / 10 * 5,15 + i * 8,buffer.rgb(255,255,255), &virtualDJ_5ptFontInfo);
         }


better delay on start and rotate based on L/R data

--- testing/arduino/self-driving-v5.ino
+++ testing/arduino/self-driving-v5.ino
@@ -262,24 +262,15 @@

     CalculateAverageRange();

-    /*
-    average_Left
-    average_Center
-    average_Right
-    */
+    // Wait for initial scans before performing any actions
+    if(millis() < initialDelay)
+    {
+        return;
+    }

     long range = average_Center;

     SetLightByRange(range);
-
-    if(millis() < initialDelay)
-    {
-        return;
-    }
-
-    // maybe wait for x seconds before starting so a full
-    // left center right scan can be performed first
-

     // obstacle is further away than X cm
     if(wheelSpinCompleted && range > rangeLimit_Stop)
@@ -292,12 +283,16 @@
     }
     else
     {
-
-        // TODO
-
-        // rotate
-        SetMotor(motorPin1_1, motorPin1_2, -255);
-        SetMotor(motorPin2_1, motorPin2_2, 255);
+        if(average_Left > average_Right)
+        {
+            SetMotor(motorPin1_1, motorPin1_2, 255);
+            SetMotor(motorPin2_1, motorPin2_2, -255);
+        }
+        else
+        {
+            SetMotor(motorPin1_1, motorPin1_2, -255);
+            SetMotor(motorPin2_1, motorPin2_2, 255);
+        }

         wheelSpinCompleted = false;


Fix array

Fix array

--- mouse_rat.ino
+++ mouse_rat.ino
@@ -29,8 +29,23 @@

 /* Assign a unique base ID for this sensor */
 Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(1000);  // Use I2C, ID #1000
+
+/* Or, use Hardware SPI:
+  SCK -> SPI CLK
+  SDA -> SPI MOSI
+  G_SDO + XM_SDO -> tied together to SPI MISO
+  then select any two pins for the two CS lines:
+*/
+
 #define LSM9DS0_XM_CS 10
 #define LSM9DS0_GYRO_CS 9
+
+//Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(LSM9DS0_XM_CS, LSM9DS0_GYRO_CS, 1000);
+/* Or, use Software SPI:
+  G_SDO + XM_SDO -> tied together to the MISO pin!
+  then select any pins for the SPI lines, and the two CS pins above
+*/
+
 #define LSM9DS0_SCLK 13
 #define LSM9DS0_MISO 12
 #define LSM9DS0_MOSI 11
@@ -38,8 +53,8 @@
 float xNormal = -3.0;
 float yNormal = 1;

-float xRange[2] = [0,0]
-float yRange[2] = [0,0]
+float xRange[] = {0,0};
+float yRange[] = {0,0};

 void displaySensorDetails(void) {
   sensor_t accel, mag, gyro, temp;
@@ -147,10 +162,9 @@
   }

   calibrate(accel.acceleration.x, accel.acceleration.y);
-
   Mouse.move(mx, my, 0);

-  // print out accelleration data
+//  print out accelleration data
 //  Serial.print("Accel X: "); Serial.print(accel.acceleration.x); Serial.print(" ");
 //  Serial.print("  \tY: "); Serial.print(accel.acceleration.y);   Serial.print(" ");
 //  Serial.print("  \tZ: "); Serial.print(accel.acceleration.z);   Serial.println("  \tm/s^2");


format fix

format fix

--- KSPboard.ino
+++ KSPboard.ino
@@ -131,7 +131,7 @@
 uint8_t requestDevice(uint8_t address) // ping the device / send start command
 {
   Wire.beginTransmission(IO_ADDR_BASE | address);
-  return (Wire.endTransmission());
+  return (Wire.endTransmission()); // returns success fail
 }

 boolean requestData(uint8_t address) // returns success fail
@@ -255,7 +255,7 @@
 void updateControl()
 {
   uint8_t roter = 0; // setup space
-
+
   noInterrupts(); // shutdown interrupts for this volatile operation
   roter = _vol_rotaryControl; // copy the volatile control variable
   interrupts(); // reenable interrupts immediately
@@ -269,16 +269,16 @@
     // do hiligting stuff //
   }

-  if (controlDebounce > 0)
+  if (controlDebounce > 0)
   {
     controlDebounce--; // do dat sweet digi debounce
   }
-  else
+  else
   {
     if (digitalRead(PIN_ROT_CTRL_SW)) // if you press dis switch lock the sas control state
     {
       controlLocked = controlState; // update local variable
-
+
       Serial.println("this is where the good stuff goes, fuck yeah");

       controlDebounce = DELAY_CTRL; // reset delay
@@ -324,7 +324,7 @@
     if (requestData(IO_DEV_OPS)) // ask for data, skip if failure
     {
       uint16_t data = readData(); // finally get the 2 byte data packet
-
+
       for (index = 0; index < OPS; index++) // scan through ops 1-16 (everything but sas)
       {
         if (opState[index] > 0) // check for debounce on current pin
@@ -380,8 +380,8 @@
   if (state)
   {
     updateControl();
-   updateHelm();
-   updateOps();
+    updateHelm();
+    updateOps();
   }

   delay(DELAY_LOOP);


Tweek board tester to work better with new led's

--- Tools/FH_Tbot_Board_Tester/FH_Tbot_Board_Tester.ino
+++ Tools/FH_Tbot_Board_Tester/FH_Tbot_Board_Tester.ino
@@ -104,6 +104,7 @@
 		setColor(RgbColor(80, 0, 80));
 		delay(55);
 		setColor(RgbColor(0, 0, 0));
+		delay(1);
   }
 	if(digitalRead(leftBumper) == LOW || digitalRead(rightBumper) == LOW){
 		setColor(RgbColor(0, 80, 80));


Improved controller logic. Major variable renaming.

--- musicbox.ino
+++ musicbox.ino
@@ -1,49 +1,91 @@
-int encoderPin1 = 2;
-int encoderPin2 = 3;

-int enc1LastValue;
-int counter = 0;
+//Rotary pins
+int encPinA = 2;
+int encPinB = 3;

-char* streams[] = {"primero", "segundo", "tercero",
-                    "cuarto", "quinto", "sexto",
-                    "septimo", "octavo", "noveno"};
+//Delay for unsupervised stream change
+int strChangeDelay = 3000;

-int streamsSize = sizeof(streams)/sizeof(char*);
+//Stream names
+char* streams[] = {"primero", "segundo", "tercero",
+                   "cuarto", "quinto", "sexto",
+                   "septimo", "octavo", "noveno"
+                  };
+
+//Utility
+int strSize = sizeof(streams) / sizeof(char*);
+
+//Array offset
+int strIndex = 0;
+int lastStrIndex = 0;
+int playingStrIndex = 0;
+
+int lastEncPinAVal;
+unsigned long countdownTime;
+boolean countdown = false;
+
+

 void setup() {

   Serial.begin (9600);
-  Serial.println(streamsSize);

-  pinMode(encoderPin1, INPUT);
-  digitalWrite(encoderPin1, HIGH);
-  enc1LastValue = digitalRead(encoderPin1);
+  pinMode(encPinA, INPUT);
+  digitalWrite(encPinA, HIGH);
+  lastEncPinAVal = digitalRead(encPinA);

-  pinMode(encoderPin2, INPUT);
-  digitalWrite(encoderPin2, HIGH);
+  pinMode(encPinB, INPUT);
+  digitalWrite(encPinB, HIGH);

 }

+
+
 void loop() {

-  int enc1Value = digitalRead(encoderPin1);
-  int enc2Value = digitalRead(encoderPin2);
+  if(countdown) {
+    if (countdownTime <= millis()){
+      countdown = false;
+      //We want to change the stream when the timer expires,
+      //unles the rotary is in the same position we started
+      if (strIndex != playingStrIndex) {
+        Serial.println("***");
+        playingStrIndex = strIndex;
+      }
+    }
+  }

-  if (enc1Value != enc1LastValue) {
+  int encPinAVal = digitalRead(encPinA);
+
+  //Something changed
+  if (encPinAVal != lastEncPinAVal) {
+
+    //Software debouncing. Good enough.
     delay(1);
-    if (enc1Value == LOW) {
-      (enc2Value == enc1Value) ? counter++ : counter--;
-      if (counter<0) {
-        counter = 0;
+
+    if (encPinAVal == LOW) {
+
+      (digitalRead(encPinB) == encPinAVal) ? strIndex++ : strIndex--;
+
+      if (strIndex < 0) {
+        strIndex = 0;
       }
-      if (counter>=streamsSize) {
-        counter = streamsSize-1;
+      if (strIndex >= strSize) {
+        strIndex = strSize - 1;
       }
-      Serial.print(counter);
-      Serial.print(": ");
-      Serial.println(streams[counter]);
+
+      //We change the stream only if the strIndex changes
+      if (strIndex != lastStrIndex) {
+        Serial.print(strIndex);
+        Serial.print(": ");
+        Serial.println(streams[strIndex]);
+        lastStrIndex = strIndex;
+        countdownTime = millis() + strChangeDelay;
+        countdown = true;
+      }
+
     }
-    enc1LastValue = enc1Value;
+    lastEncPinAVal = encPinAVal;
   }
 }


Remove unused define

Remove unused define

--- alarm.ino
+++ alarm.ino
@@ -8,6 +8,7 @@
 #include <Adafruit_GFX.h>
 #include <Adafruit_LEDBackpack.h>

+#define DEFAULT_TIME 1420070400UL // 1/1/2015 00:00:00 GMT
 #define BUTTON_PULLUP true
 #define BUTTON_INVERT true
 #define BUTTON_DEBOUNCE 1
@@ -19,8 +20,6 @@
 #define JOYSTICK_Y_PIN A0
 #define SELECT_PIN A2
 #define MENU_MAX 3
-#define TIME_HEADER "T"   // Header tag for serial time sync message
-#define DEFAULT_TIME 1420070400UL // 1/1/2015 00:00:00 GMT
 #define MENU_NONE 0
 #define MENU_TIME 1
 #define MENU_ALARM 2


Rewrite to actually use the calibrated joint positions

--- otto/otto.ino
+++ otto/otto.ino
@@ -1,31 +1,32 @@
+#include <limits.h>
 #include <Servo.h>

-#define DELAY 3
+#define DELAY 2

 struct Joint
 {
-    const unsigned int pin;
-    const unsigned int posMin;
-    const unsigned int posMiddle;
-    const unsigned int posMax;
-    const unsigned int distMinToMiddle;
-    const unsigned int distMaxToMiddle;
+    enum Position
+    {
+        POS_MIN,
+        POS_MIDDLE,
+        POS_MAX
+    };
+
+    const int pin;
+    const int posMin;
+    const int posMiddle;
+    const int posMax;
     Servo servo;

-    unsigned int currentPos;
-
     Joint(
-        const unsigned int pin,
-        const unsigned int posMin,
-        const unsigned int posMiddle,
-        const unsigned int posMax) :
+        const int pin,
+        const int posMin,
+        const int posMiddle,
+        const int posMax) :
         pin(pin),
         posMin(posMin),
         posMiddle(posMiddle),
-        posMax(posMax),
-        distMinToMiddle(posMiddle-posMin),
-        distMaxToMiddle(posMax-posMiddle),
-        currentPos(0)
+        posMax(posMax)
     {
     }

@@ -33,35 +34,143 @@
     {
         this->servo.attach(this->pin);
         this->servo.writeMicroseconds(this->posMiddle);
-        this->currentPos = this->posMiddle;
-    }
-
-    void dec(unsigned int steps = 1)
-    {
-        this->currentPos -= steps;
-        this->servo.writeMicroseconds(this->currentPos);
-    }
-
-    void inc(unsigned int steps = 1)
-    {
-        this->currentPos += steps;
-        this->servo.writeMicroseconds(this->currentPos);
+    }
+
+    const int getValue(Joint::Position pos) const
+    {
+        switch (pos)
+        {
+            case POS_MIN: return this->posMin;
+            case POS_MIDDLE: return this->posMiddle;
+            case POS_MAX: return this->posMax;
+            default: return 0;
+        }
+    }
+
+    void setPosition(const int pos) const
+    {
+        this->servo.writeMicroseconds(pos);
     }
 };

-Joint rightAnkle(5, 810, 1510, 1860);
-Joint leftAnkle(4, 1140, 1490, 2190);
-Joint rightHip(3, 950, 1300, 1650);
-Joint leftHip(2, 1150, 1500, 1850);
-
-/*
+struct Move
+{
+    Joint* joint;
+    Joint::Position from;
+    Joint::Position to;
+
+    int direction = 0;
+    int distance = 0;
+    float increment = 0.0;
+
+    Move(Joint* joint, Joint::Position from, Joint::Position to):
+        joint(joint), from(from), to(to)
+    {}
+};
+
+void moveJoints(const int numMoves, Move* moves)
+{
+    int i = 0, j = 0;
+    int minDistance = INT_MAX;
+
+    for (i = 0; i < numMoves; ++i)
+    {
+        Move* move = &moves[i];
+        const Joint* joint = move->joint;
+        const int from = joint->getValue(move->from);
+        const int to = joint->getValue(move->to);
+
+        // determine move direction and distance
+        if (from > to)
+        {
+            move->direction = -1;
+            move->distance = from - to;
+        }
+        else
+        {
+            move->direction = 1;
+            move->distance = to - from;
+        }
+
+        // determine minimum move distance of all joints
+        if (move->distance < minDistance)
+        {
+            minDistance = move->distance;
+        }
+    }
+
+    // determine increment for each position update
+    for (i = 0; i < numMoves; ++i)
+    {
+        Move* move = &moves[i];
+        const Joint* joint = move->joint;
+
+        move->increment = static_cast<float>(move->distance) / static_cast<float>(minDistance);
+    }
+
+    // move servos
+    for (i = 0; i < minDistance; ++i)
+    {
+        for (j = 0; j < numMoves; ++j)
+        {
+            Move* move = &moves[j];
+            const Joint* joint = move->joint;
+            int pos = joint->getValue(move->from) + move->direction * i * move->increment;
+
+            joint->setPosition(static_cast<float>(pos));
+        }
+
+        delay(DELAY);
+    }
+}
+
 Joint rightAnkle(5, 950, 1510, 1860);
 Joint leftAnkle(4, 1140, 1490, 2190);
 Joint rightHip(3, 950, 1290, 1650);
 Joint leftHip(2, 1100, 1500, 1930);
-*/
-
-void stepForward();
+
+void stepForward() {
+    Move stepLeft[] = {
+        Move(&rightAnkle, Joint::POS_MIN, Joint::POS_MIDDLE),
+        Move(&leftAnkle, Joint::POS_MIN, Joint::POS_MIDDLE),
+        Move(&rightHip, Joint::POS_MIDDLE, Joint::POS_MAX),
+        Move(&leftHip, Joint::POS_MIDDLE, Joint::POS_MAX)
+    };
+
+    Move leanRight[] = {
+        Move(&rightAnkle, Joint::POS_MIDDLE, Joint::POS_MAX),
+        Move(&leftAnkle, Joint::POS_MIDDLE, Joint::POS_MAX)
+    };
+
+    Move rotateFromLeftToCenter[] = {
+        Move(&rightHip, Joint::POS_MAX, Joint::POS_MIDDLE),
+        Move(&leftHip, Joint::POS_MAX, Joint::POS_MIDDLE)
+    };
+
+    Move stepRight[] = {
+        Move(&rightAnkle, Joint::POS_MAX, Joint::POS_MIDDLE),
+        Move(&leftAnkle, Joint::POS_MAX, Joint::POS_MIDDLE),
+        Move(&rightHip, Joint::POS_MIDDLE, Joint::POS_MIN),
+        Move(&leftHip, Joint::POS_MIDDLE, Joint::POS_MIN)
+    };
+
+    Move leanLeft[] = {
+        Move(&rightAnkle, Joint::POS_MIDDLE, Joint::POS_MIN),
+        Move(&leftAnkle, Joint::POS_MIDDLE, Joint::POS_MIN)
+    };
+
+    Move rotateFromRightToCenter[] = {
+        Move(&rightHip, Joint::POS_MIN, Joint::POS_MIDDLE),
+        Move(&leftHip, Joint::POS_MIN, Joint::POS_MIDDLE)
+    };
+
+    moveJoints(4, stepLeft);
+    moveJoints(2, leanRight);
+    moveJoints(2, rotateFromLeftToCenter);
+    moveJoints(4, stepRight);
+    moveJoints(2, leanLeft);
+    moveJoints(2, rotateFromRightToCenter);
+}

 void setup() {
     rightAnkle.init();
@@ -70,86 +179,26 @@
     leftHip.init();
 }

-bool running = false;
+bool started = false;

 void loop()
 {
     int i = 0;

-    if (!running)
-    {
+    if (!started)
+    {
+        Move startLeanLeft[] = {
+            Move(&rightAnkle, Joint::POS_MIDDLE, Joint::POS_MIN),
+            Move(&leftAnkle, Joint::POS_MIDDLE, Joint::POS_MIN)
+        };
+
         delay(5000);

-        for (i = 0; i < leftAnkle.distMinToMiddle; ++i)
-        {
-            rightAnkle.dec(2);
-            leftAnkle.dec();
-
-            delay(DELAY);
-        }
-
-        running = true;
+        moveJoints(2, startLeanLeft);
+
+        started = true;
     }

     stepForward();
 }

-void stepForward() {
-    int i = 0;
-
-    // left step
-    for (i = 0; i < leftAnkle.distMinToMiddle; ++i)
-    {
-        rightAnkle.inc(2);
-        leftAnkle.inc();
-        rightHip.inc();
-        leftHip.inc();
-
-        delay(DELAY);
-    }
-
-    // lean right
-    for (i = 0; i < rightAnkle.distMaxToMiddle; ++i)
-    {
-        rightAnkle.inc();
-        leftAnkle.inc(2);
-
-        delay(DELAY);
-    }
-
-    // rotate from left to center
-    for (i = 0; i < rightHip.distMaxToMiddle; ++i)
-    {
-        rightHip.dec();
-        leftHip.dec();
-
-        delay(DELAY);
-    }
-
-    // right step
-    for (i = 0; i < rightAnkle.distMaxToMiddle; ++i) {
-        rightAnkle.dec();
-        leftAnkle.dec(2);
-        rightHip.dec();
-        leftHip.dec();
-
-        delay(DELAY);
-    }
-
-    // lean left
-    for (i = 0; i < leftAnkle.distMinToMiddle; ++i) {
-        rightAnkle.dec(2);
-        leftAnkle.dec();
-
-        delay(DELAY);
-    }
-
-    // rotate from right to center
-    for (i = 0; i < rightHip.distMinToMiddle; ++i) {
-        rightHip.inc();
-        leftHip.inc();
-
-        delay(DELAY);
-    }
-}
-


use map function

use map function

--- ptw-wheel.ino
+++ ptw-wheel.ino
@@ -230,7 +230,14 @@
 // limitation of brightness
 // 0-255の値を0-MAX_VALの範囲に
 uint32_t constrainValue(int input) {
-  return float(input) / 255.0 * float(MAX_VAL);
+  return map(input, 0, 255, 0, MAX_VAL);
+}
+
+// in_min～in_max内のxをout_min〜out_max内の値に変換して返す
+uint32_t map(int x, int in_min, int in_max, int out_min, int out_max) {
+  // restrict 'x' in 'in' range
+  int x_in_range = in_min < in_max ? max(min(x, in_max), in_min) : max(min(x, in_min), in_max);
+  return (x_in_range - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
 }

 String getValue(String data, char separator, int index) {


Now with Error Handling

Now with Error Handling


Minor Edit

Minor Edit

Minor Edit

--- rusk-r002.ino
+++ rusk-r002.ino
@@ -366,7 +366,7 @@
     // Initialize custom cloud API variables here
     // or edit above to monitor specific values for
     // services like IFTTT (last free of 10)
-    Spark.variable("IF3T_UVIndex", &Si1132UVIndex, DOUBLE);
+    Spark.variable("IF3T_Visible", &Si1132Visible, DOUBLE);

     // Initialize cloud API functions
     Spark.function("sleepDelay", setSleepDelay);


Nameoftherose patch for Issue #2435 (#4256)

* WiFiTelnetToSerial Example - Minor Issues #2435

* WiFiTelnetToSerial Example - Minor Issues #2435

Patch to rectify issue #2435

--- libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino
+++ libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino
@@ -59,12 +59,15 @@
         if(serverClients[i]) serverClients[i].stop();
         serverClients[i] = server.available();
         Serial1.print("New client: "); Serial1.print(i);
-        continue;
+        break;
       }
     }
     //no free/disconnected spot so reject
-    WiFiClient serverClient = server.available();
-    serverClient.stop();
+    if ( i == MAX_SRV_CLIENTS) {
+       WiFiClient serverClient = server.available();
+       serverClient.stop();
+        Serial1.println("Connection rejected ");
+    }
   }
   //check clients for data
   for(i = 0; i < MAX_SRV_CLIENTS; i++){


Update OTTO_ultrasound.ino

Update OTTO_ultrasound.ino

--- OTTO_ultrasound/OTTO_ultrasound.ino
+++ OTTO_ultrasound/OTTO_ultrasound.ino
@@ -188,11 +188,17 @@

       //-- MODE 2 - Obstacle detector mode
        if(obstacleDetected){
-              Otto.jump(1,700);
+              Otto.playGesture(OttoHappy);
               Otto.sing(S_superHappy);
               Otto.walk(1,1300,-1);
-
-
+                  Otto.playGesture(OttoSad);
+                  Otto.swing(2,800,20);
+                  Otto.playGesture(OttoAngry);
+                  Otto.playGesture(OttoLove);
+                  Otto.shakeLeg(1,T,1);
+                  Otto.playGesture(OttoVictory);
+                  Otto.crusaito(1,T,moveSize,1);
+                  Otto.sing(S_mode1);
             delay(100);
             obstacleDetector();
             delay(100);
@@ -693,7 +699,6 @@
     Serial.flush();
 }

-
 //-- Function to send noise sensor measure
 void requestNoise(){

@@ -707,7 +712,6 @@
     Serial.flush();
 }

-
 //-- Function to send battery voltage percent
 void requestBattery(){

@@ -723,7 +727,6 @@
     Serial.flush();
 }

-
 //-- Function to send program ID
 void requestProgramId(){

@@ -735,7 +738,6 @@
     Serial.println(F("%%"));
     Serial.flush();
 }
-

 //-- Function to send Ack comand (A)
 void sendAck(){


bug fixed for the GPS (clean up)

bug fixed for the GPS (clean up)

--- mwsLRWHFv2/mwsLRWHFv2.ino
+++ mwsLRWHFv2/mwsLRWHFv2.ino
@@ -260,12 +260,7 @@
   digitalWrite(STAT2, HIGH); //Blink stat LED 1 second
   delay(1000);
   digitalWrite(STAT2, LOW); //Blink stat LED
-  smartdelay(30000); //Wait 60 seconds, and gather GPS data
-  Serial.println("");
-  Serial.print("LAT=");  Serial.println(gps.location.lat(), 6);
-  Serial.print("LONG="); Serial.println(gps.location.lng(), 6);
-  Serial.print("TIME="); Serial.print(gps.time.hour(), 6);
-  Serial.print(":");Serial.println(gps.time.minute(), 6);
+  smartdelay(60000); //Wait 60 seconds, and gather GPS data
   minutes = gps.time.minute();
   minutes_10m = gps.time.minute();
   seconds = gps.time.second();


Update Pegasus_vehicle.ino

Update Pegasus_vehicle.ino

--- Pegasus_vehicle/Pegasus_vehicle.ino
+++ Pegasus_vehicle/Pegasus_vehicle.ino
@@ -43,15 +43,7 @@
 GyroAngle gyro;
 AccelAngle accel;
 // raw sensor readings
-short ax;
-short ay;
-short az;
-short gx;
-short gy;
-short gz;
-short mx;
-short my;
-short mz;
+short ax, ay, az, gx, gy, gz, mx, my, mz;

 // Logging
 Pegasus_Log logger;
@@ -69,31 +61,24 @@
 pPID PID_pitch;
 pPID PID_roll;
 // PID output
-long op_roll;
-long op_pitch;
-long op_yaw;
-long op_throttle;
+long op_roll, op_pitch, op_yaw, op_throttle;
 // motor power output
-long power_FL;
-long power_FR;
-long power_BR;
-long power_BL;
+long power_FL, power_FR, power_BR, power_BL;

 // throttle-thrust correction
 CurveRemap tt;
-
 #define FLTTLENGTH 2
 unsigned short FL_tt_x[FLTTLENGTH] = {0,65535};
-unsigned short FL_tt_y[FLTTLENGTH] = {3195,65535};
+unsigned short FL_tt_y[FLTTLENGTH] = {0,65535};
 #define FRTTLENGTH 2
 unsigned short FR_tt_x[FRTTLENGTH] = {0,65535};
-unsigned short FR_tt_y[FRTTLENGTH] = {3195,65535};
+unsigned short FR_tt_y[FRTTLENGTH] = {0,65535};
 #define BRTTLENGTH 2
 unsigned short BR_tt_x[BRTTLENGTH] = {0,65535};
-unsigned short BR_tt_y[BRTTLENGTH] = {3195,65535};
+unsigned short BR_tt_y[BRTTLENGTH] = {0,65535};
 #define BLTTLENGTH 2
 unsigned short BL_tt_x[BLTTLENGTH] = {0,65535};
-unsigned short BL_tt_y[BLTTLENGTH] = {3195,65535};
+unsigned short BL_tt_y[BLTTLENGTH] = {0,65535};
 /*
 #define FLTTLENGTH 14
 unsigned short FL_tt_x[FLTTLENGTH] = {0,1843,25384,25465,26711,32691,37411,44993,45244,47404,53389,60687,62966,65535};


Fixed FFT graph out of bounds

Fixed FFT graph out of bounds

Signed-off-by: Irmo van den Berge <0370dce6b07866a7132582d46388cf81833cb900@home.nl>

--- examples/AnalogFFT/AnalogFFT.ino
+++ examples/AnalogFFT/AnalogFFT.ino
@@ -21,7 +21,7 @@

 /* Time-domain graph settings */
 #define TD_GRAPH_X     6
-#define TD_GRAPH_Y     22
+#define TD_GRAPH_Y     21
 #define TD_GRAPH_W     306
 #define TD_GRAPH_H     90

@@ -115,7 +115,7 @@
   // Increment time position, wipe when fully filled up
   if (++timePos >= (TD_GRAPH_X+TD_GRAPH_W)) {
     timePos = TD_GRAPH_X;
-    display.fillRect(TD_GRAPH_X, TD_GRAPH_Y, TD_GRAPH_W+2, TD_GRAPH_H, BLACK);
+    display.fillRect(TD_GRAPH_X, TD_GRAPH_Y+1, TD_GRAPH_W+2, TD_GRAPH_H, BLACK);
   }
 }


add onData() to BasicMQTT.ino

add onData() to BasicMQTT.ino

--- examples/BasicMQTT/BasicMQTT.ino
+++ examples/BasicMQTT/BasicMQTT.ino
@@ -44,6 +44,7 @@
   while (!anto.mqtt.connect(user, token, true));
   Serial.println("\nConnected");

+  anto.mqtt.onData(messageReceived);
   anto.mqtt.sub("channel");
 }


Dot only in one direction changing color.

--- ws2812b-control.ino
+++ ws2812b-control.ino
@@ -52,17 +52,7 @@

   pixels.setPixelColor(index, pixels.Color(color[RED],color[GREEN],color[BLUE]));

-  if (increase) {
-    ++index;
-    if (index == LED_01_NUM-1) {
-      increase = false;
-    }
-  } else {
-    --index;
-    if (index == 0) {
-      increase = true;
-    }
-  }
+  index = (index + 1) % LED_01_NUM;

   pixels.show();
   delay(delayval);


Add Cylon, fix Pulse (which wasn't put into program set).

--- examples/StockPlus/StockPlus.ino
+++ examples/StockPlus/StockPlus.ino
@@ -102,7 +102,7 @@
     sequence_(0) {}

   uint32_t Do() {
-    g35_.fill_sequence(0, count_, sequence_, 1, rainbow_pulse);
+    g35_.fill_sequence(0, count_, sequence_, 1, pulser);
     if (count_ < light_count_) {
       ++count_;
     } else {
@@ -111,10 +111,9 @@
     return 1;
   }

-  static bool rainbow_pulse(uint16_t sequence, color_t& color,
-			    uint8_t& intensity) {
+  static bool pulser(uint16_t sequence, color_t& color, uint8_t& intensity) {
     const int PHASE = 32;
-    color = G35::rainbow_color((sequence + PHASE) / (PHASE * 2));
+    color = G35::max_color((sequence + PHASE) / (PHASE * 2));
     intensity = abs(PHASE - (int)(sequence) % (PHASE + PHASE));
     return true;
   }
@@ -124,6 +123,50 @@
   uint16_t sequence_;
 };

+class Cylon : public LightProgram {
+ public:
+ Cylon(G35& g35)
+   : LightProgram(g35),
+    last_light_shifted_((light_count_ << 8) - 1), x_(0), d2x_(-2),
+    color_(G35::max_color(rand())) {}
+
+  uint32_t Do() {
+    uint8_t old_x_pix = x_ >> 8;
+    dx_ += d2x_;
+    x_ += dx_;
+
+    bool moving_right = d2x_ > 0;
+    bool past_right = old_x_pix >= g35_.get_halfway_point();
+    if (moving_right == past_right) {
+      d2x_ = -d2x_;
+    }
+
+    if (x_ <= 0) {
+      x_ = 0;
+      dx_ = 0;
+    }
+    if (x_ > last_light_shifted_) {
+      x_ = last_light_shifted_;
+      dx_ = 0;
+    }
+
+    uint8_t x_pix = x_ >> 8;
+    if (old_x_pix != x_pix) {
+      g35_.set_color(old_x_pix, G35::MAX_INTENSITY, COLOR_BLACK);
+    }
+    g35_.set_color(x_pix, G35::MAX_INTENSITY, color_);
+
+    return bulb_frame_ >> 1;
+  }
+
+ private:
+  int16_t last_light_shifted_;
+  int16_t x_;
+  int16_t dx_;
+  int16_t d2x_;
+  color_t color_;
+};
+
 // How long each program should run.
 #define PROGRAM_DURATION_SECONDS (30)

@@ -134,7 +177,7 @@

 G35 lights(OUT_PIN, LIGHT_COUNT);

-#define PROGRAM_COUNT (16)
+#define PROGRAM_COUNT (17)
 LightProgram* CreateProgram(uint8_t program_index) {
   switch (program_index) {
   case 0: return new SteadyWhite(lights);
@@ -153,6 +196,7 @@
   case 13: return new Twinkle(lights);
   case 14: return new RedGreenChase(lights);
   case 15: return new Pulse(lights);
+  case 16: return new Cylon(lights);
   case PROGRAM_COUNT:
   default:
     // PROBLEM! PROGRAM_COUNT is wrong.
@@ -160,7 +204,7 @@
   }
 }

-ProgramRunner runner(CreateProgram, 15, PROGRAM_DURATION_SECONDS);
+ProgramRunner runner(CreateProgram, PROGRAM_COUNT, PROGRAM_DURATION_SECONDS);

 void setup() {
   randomSeed(analogRead(0));


Update TB6612FNG.ino

Update TB6612FNG.ino


Cleaned up code. Added some comments.

Cleaned up code. Added some comments.

--- examples/Ticon2011/Ticon2011.ino
+++ examples/Ticon2011/Ticon2011.ino
@@ -1,24 +1,27 @@
 /* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*-

-  G35: An Arduino library for GE Color Effects G-35 holiday lights.
-  Copyright © 2011 The G35 Authors. Use, modification, and distribution are
-  subject to the BSD license as described in the accompanying LICENSE file.
+   G35: An Arduino library for GE Color Effects G-35 holiday lights.
+   Copyright © 2011 The G35 Authors. Use, modification, and distribution are
+   subject to the BSD license as described in the accompanying LICENSE file.

-  Ticon2011.ino is the code that I used for Christmas 2011 at my home. It's yet
-  another demonstration of working code.
+   Ticon2011.ino is the code that I used for Christmas 2011 at my home. It's yet
+   another demonstration of working code.

-  By Mike Tsao <github.com/sowbug>. See README for complete attributions.
+   By Mike Tsao <github.com/sowbug>. See README for complete attributions.
 */

 // If defined, then a 38KHz IR receiver is supplying data on pin 11. I didn't
 // really use this much; if it detects any recognized remote code, it skips to
 // the next program. So in theory people driving by my house who happen to have
 // a TV remote in their car could stop and change the program.
+//
+// Pretty much any of these IR receivers will work. I used a Vishay Semi
+// TSOP58038 (http://octopart.com/partsearch#search/requestData&q=TSOP58038).
 #define USE_REMOTE 1

 // If defined, then the hardware is an Arduino. If not, then it's a Teensy.
-// More described below. I used this because I had an Arduino in the house
-// when I was writing new programs, then ran outside in the cold with my
+// More described below. I used this switch because I had an Arduino in the
+// house when I was writing new programs, then ran outside in the cold with my
 // laptop to reprogram the Teensy that was running the real lights.
 #define ARDUINO 1

@@ -28,6 +31,7 @@
 #include <StockPrograms.h>
 #include <PlusPrograms.h>
 #ifdef USE_REMOTE
+// Get at https://github.com/shirriff/Arduino-IRremote
 #include <IRremote.h>
 #endif

@@ -35,14 +39,16 @@
 // A regular Arduino. First string on pin 13, second on 12.
 G35String lights_1(13, 50, 50, 0, false);
 G35String lights_2(12, 41);
+
 #ifdef USE_REMOTE
-IRrecv ir(11);
+IRrecv ir(11);  // IR receiver on pin 11.
 decode_results ir_results;
 #endif
+
 #else
 // A Teensy 2.0 that's been flashed with the Arduino Leonardo bootloader (thus
 // permanently destroying the HalfKay bootloader that ships with the Teensy).
-// The first string is connected to D6, and the second to B4.
+// The first string is connected to D6, and the second to B4.
 G35String lights_1(12, 50, 50, 0, false);
 G35String lights_2(8, 41);
 #endif
@@ -55,13 +61,12 @@
 G35StringGroup string_group;

 LightProgram* CreateProgram(uint8_t program_index) {
-  randomSeed(rand() + analogRead(0));
-  program_index = rand() % PROGRAM_COUNT;
+  program_index = random() % PROGRAM_COUNT;

-  if (program_index < StockProgramGroup::ProgramCount) {
-    return stock_programs.CreateProgram(string_group, program_index);
-  }
-  program_index -= StockProgramGroup::ProgramCount;
+  if (program_index < StockProgramGroup::ProgramCount) {
+    return stock_programs.CreateProgram(string_group, program_index);
+  }
+  program_index -= StockProgramGroup::ProgramCount;

   if (program_index < PlusProgramGroup::ProgramCount) {
     return plus_programs.CreateProgram(string_group, program_index);
@@ -76,9 +81,31 @@

 ProgramRunner runner(CreateProgram, PROGRAM_COUNT, PROGRAM_DURATION_SECONDS);

+// http://www.utopiamechanicus.com/77/better-arduino-random-numbers/
+// We assume A0 and A1 are disconnected.
+uint32_t seedOut(unsigned int noOfBits) {
+  uint32_t seed = 0, limit = 99;
+  int bit0 = 0, bit1 = 0;
+  while (noOfBits--) {
+    for (int i = 0; i < limit; ++i) {
+      bit0 = analogRead(0) & 1;
+      bit1 = analogRead(1) & 1;
+      if (bit1 != bit0)
+        break;
+    }
+    seed = (seed << 1) | bit1;
+  }
+  return seed;
+}
+
 void setup() {
-  randomSeed(analogRead(0));
-  Serial.begin(57600);
+  uint32_t seed = seedOut(32);
+  randomSeed(seed);
+  seed &= 0xff;
+  // random() isn't very random. But this seed generator works quite well.
+  while (seed--) {
+    random();
+  }

 #ifdef USE_REMOTE
   ir.enableIRIn();
@@ -87,7 +114,6 @@
   delay(50);
   lights_1.enumerate();
   lights_2.enumerate();
-  delay(50);

   lights_1.do_test_patterns();
   lights_2.do_test_patterns();
@@ -101,7 +127,6 @@

 #ifdef USE_REMOTE
   if (ir.decode(&ir_results)) {
-    Serial.println(ir_results.value, HEX);
     runner.switch_program();
     ir.resume();
   }


Updates example for DUE, now without additional wires.

Configuring the pins in the set_port method eliminates the ncessity for
an additional pin.

--- examples/readerDUE/readerDUE.ino
+++ examples/readerDUE/readerDUE.ino
@@ -1,17 +1,5 @@
 #include "Arduino.h"
 #include "OBD9141.h"
-
-/*
-  On the Arduino DUE (version 1.6.8) using the Serial port pins as digital IO
-  pins is problematic. In particular, it seems you cannot use the port as a
-  serial port after using pinMode() on the pins.
-
-  We fix this by using an extra pin; we use this extra pin to create the slow
-  5 baud init pattern while the Serial pins remain in use for the serial port.
-
-  So connect any digital pin to the Tx pin of the serial port and update the
-  number accordingly.
-*/

 // In this example, Serial port 'Serial1' is used. The native USB port is used
 // to provide information.
@@ -20,7 +8,7 @@
 #define RX_PIN 19

 // An extra pin connected to the Tx pin of the Serial port used.
-#define TX_PIN 5
+#define TX_PIN 18
 // So this pin has a direct connection to pin 18 (TX1)

 // The ENable pin for my SN65HVDA195 breakout is connected to pin 2.
@@ -53,8 +41,8 @@
     // succesful before trying to request PID's.

     if (init_success){
-        bool res;
-        while(1){
+        bool res = true;
+        while(res){
             res = obd.getCurrentPID(0x11, 1);
             if (res){
                 SerialUSB.print("Result 0x11 (throttle): ");


Added system status helper

Added system status helper

--- examples/sensorapi/sensorapi.ino
+++ examples/sensorapi/sensorapi.ino
@@ -5,7 +5,7 @@

 /* This driver uses the Adafruit unified sensor library (Adafruit_Sensor),
    which provides a common 'type' for sensor data and some helper functions.
-
+
    To use this driver you will also need to download the Adafruit_Sensor
    library and include it in your libraries folder.

@@ -14,14 +14,14 @@
    sensor in any data logs, etc.  To assign a unique ID, simply
    provide an appropriate value in the constructor below (12345
    is used by default in this example).
-
+
    Connections
    ===========
    Connect SCL to analog 5
    Connect SDA to analog 4
    Connect VDD to 3-5V DC
    Connect GROUND to common ground
-
+
    History
    =======
    2015/MAR/03  - First release (KTOWN)
@@ -29,7 +29,7 @@

 /* Set the delay between fresh samples */
 #define BNO055_SAMPLERATE_DELAY_MS (100)
-
+
 Adafruit_BNO055 bno = Adafruit_BNO055(55);

 /**************************************************************************/
@@ -48,8 +48,31 @@
   Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
   Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" xxx");
   Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" xxx");
-  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" xxx");
+  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" xxx");
   Serial.println("------------------------------------");
+  Serial.println("");
+  delay(500);
+}
+
+/**************************************************************************/
+/*
+    Display some basic info about the sensor status
+*/
+/**************************************************************************/
+void displaySensorStatus(void)
+{
+  /* Get the system status values (mostly for debugging purposes) */
+  uint8_t system_status, self_test_results, system_error;
+  system_status = self_test_results = system_error = 0;
+  bno.getSystemStatus(&system_status, &self_test_results, &system_error);
+
+  /* Display the results in the Serial Monitor */
+  Serial.print("System Status: 0x");
+  Serial.println(system_status, HEX);
+  Serial.print("Self Test:     0x");
+  Serial.println(self_test_results, HEX);
+  Serial.print("System Error:  0x");
+  Serial.println(system_error, HEX);
   Serial.println("");
   delay(500);
 }
@@ -59,11 +82,11 @@
     Arduino setup function (automatically called at startup)
 */
 /**************************************************************************/
-void setup(void)
+void setup(void)
 {
   Serial.begin(9600);
   Serial.println("Orientation Sensor Test"); Serial.println("");
-
+
   /* Initialise the sensor */
   if(!bno.begin())
   {
@@ -71,11 +94,14 @@
     Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
     while(1);
   }
-
+
   delay(1000);
-
+
   /* Display some basic information on this sensor */
   displaySensorDetails();
+
+  /* Optional: Display current status */
+  // displaySensorStatus();

   bno.setExtCrystalUse(true);
 }
@@ -86,12 +112,12 @@
     should go here)
 */
 /**************************************************************************/
-void loop(void)
+void loop(void)
 {
-  /* Get a new sensor event */
-  sensors_event_t event;
+  /* Get a new sensor event */
+  sensors_event_t event;
   bno.getEvent(&event);
-
+
   /* Display the floating point data */
   Serial.print("X: ");
   Serial.print(event.orientation.x, 4);
@@ -100,6 +126,6 @@
   Serial.print("\tZ: ");
   Serial.print(event.orientation.z, 4);
   Serial.println("");
-
+
   delay(BNO055_SAMPLERATE_DELAY_MS);
 }


Correct unclosed comment

Correct unclosed comment

--- firmware/examples/basic-cwop.ino
+++ firmware/examples/basic-cwop.ino
@@ -55,7 +55,7 @@
       Particle.publish("app/debug", CWOP.createAPRS(), 60, PRIVATE);

       /* This requires a valid CWOP ID; behaviour is undefined if an invalid one is provided. */
-      /* NOTE: it is not *necessary* (but is not explicitly harmful) to call CWOP.createAPRS() before calling CWOP.writePacket().
+      /* NOTE: it is not *necessary* (but is not explicitly harmful) to call CWOP.createAPRS() before calling CWOP.writePacket(). */
       //CWOP.writePacket();
     }
 }


[LedDude] Cleanup.

[LedDude] Cleanup.

Signed-off-by: Juri Berlanda <5bfdca9e82c53adb0603ce7083f4ba4f2da5cacf@hotmail.com>

--- laundry-dude-led-sensor/laundry-dude-led-sensor.ino
+++ laundry-dude-led-sensor/laundry-dude-led-sensor.ino
@@ -38,7 +38,7 @@
 bool locked = false;
 unsigned long lastRead = 0;

-char buffer[TAG_LENGTH + 1];
+char buffer[TAG_LENGTH];
 int count = 0;

 // Software serial for XBee module
@@ -70,7 +70,6 @@
       Serial.println((int)tmp);
       if (tmp == 2) {
         count++;
-        buffer[TAG_LENGTH] = 0;
         Serial.println("Got start");
       }
     }
@@ -153,7 +152,7 @@
     return;

   // FIXME: Runs over after 50 days!
-  if (millis() - lastRead < 1000) {
+  if (millis() - lastRead < 2000) {
     lastRead = millis();
     return;
   }
@@ -175,6 +174,7 @@
 }

 void loop() {
+
   processRfid();
   readLightsensor();
   readDataFromMpu();
@@ -262,14 +262,12 @@
   // get current FIFO count
   fifoCount = mpu.getFIFOCount();

-  // check for overflow (this should never happen unless our code is too inefficient)
+  // Check for overflow
   if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
     Serial.println(F("FIFO overflow!"));
-    // reset so we can continue cleanly
     mpu.resetFIFO();
-    // otherwise, check for DMP data ready interrupt (this should happen frequently)
+  // Check for new data
   } else if (mpuIntStatus & 0x02 && fifoCount < packetSize)
-    // wait for correct available data length, should be a VERY short wait
     while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
 }


Fix crashes if the deadline >= millis()

Fix crashes if the deadline >= millis()

--- code/oakpowerboard/oakpowerboard.ino
+++ code/oakpowerboard/oakpowerboard.ino
@@ -131,10 +131,6 @@

   display.flipScreenVertically();

-  // put your setup code here, to run once:
-  // initialize the digital pin as an output.
-  pinMode(1, OUTPUT); //LED on Model A
-  //attachInterrupt(digitalPinToInterrupt(PULSE_PIN), trigger_pulse, FALLING);
 #ifdef DEBUG
   pinMode(DEBUG_LED, OUTPUT);//Debugging LED
 #endif
@@ -231,7 +227,7 @@
     digitalWrite(DEBUG_LED, millis() < deadline ? HIGH : LOW);
 #endif
     yield();
-    delay(deadline - millis());
+    if(millis() < deadline) delay(deadline - millis());
   }
 }


always enable mdns

always enable mdns

--- WifiWeatherGuy.ino
+++ WifiWeatherGuy.ino
@@ -124,32 +124,6 @@
     connected = WiFi.status() == WL_CONNECTED;
   }

-  if (!connected) {
-    WiFi.softAP(cfg.hostname);
-    tft.println(F("Connect to SSID"));
-    tft.println(cfg.hostname);
-    tft.println(F("to configure WiFi"));
-  } else {
-    DBG(println());
-    DBG(print(F("Connected to ")));
-    DBG(println(cfg.ssid));
-    DBG(println(WiFi.localIP()));
-
-    tft.println();
-    tft.print(F("http://"));
-    tft.print(WiFi.localIP());
-    tft.println('/');
-
-    if (mdns.begin(cfg.hostname, WiFi.localIP())) {
-      DBG(println(F("mDNS started")));
-      mdns.addService("http", "tcp", 80);
-    } else
-      ERR(println(F("Error starting mDNS")));
-
-    last_fetch_conditions = -cfg.conditions_interval;
-    last_fetch_forecasts = -cfg.forecasts_interval;
-  }
-
   server.on("/config", HTTP_POST, []() {
     if (server.hasArg("plain")) {
       String body = server.arg("plain");
@@ -166,6 +140,32 @@

   httpUpdater.setup(&server);
   server.begin();
+
+  if (mdns.begin(cfg.hostname, WiFi.localIP())) {
+    DBG(println(F("mDNS started")));
+    mdns.addService("http", "tcp", 80);
+  } else
+    ERR(println(F("Error starting mDNS")));
+
+  if (!connected) {
+    WiFi.softAP(cfg.hostname);
+    tft.println(F("Connect to SSID"));
+    tft.println(cfg.hostname);
+    tft.println(F("to configure WiFi"));
+  } else {
+    DBG(println());
+    DBG(print(F("Connected to ")));
+    DBG(println(cfg.ssid));
+    DBG(println(WiFi.localIP()));
+
+    tft.println();
+    tft.print(F("http://"));
+    tft.print(WiFi.localIP());
+    tft.println('/');
+
+    last_fetch_conditions = -cfg.conditions_interval;
+    last_fetch_forecasts = -cfg.forecasts_interval;
+  }
 }

 struct Conditions {


Update automatic_water_control_rev1.ino

Update automatic_water_control_rev1.ino

--- automatic_water_control_rev1/automatic_water_control_rev1.ino
+++ automatic_water_control_rev1/automatic_water_control_rev1.ino
@@ -20,10 +20,10 @@
 void setup()
 {
   Serial.begin(9600);
-  pinMode(pcinput,INPUT);  // DEEPAK, WHY ARE YOU USING AN ANALOG PIN FOR DIGITAL INPUT??? WUT BOUT THE OTHER DIGITAL PINS??
+  pinMode(pcinput,INPUT);
   pinMode(pcoutput,OUTPUT);
   pcsensor = digitalRead(pcinput); // why this line here?
-  pcstate = pcinput;    // is this correct??  pcinput is just a pin num isnt it??
+  pcstate = pcinput;    // shouldnt this be pcstate=digitalRead(pcinput); ??... or pcsensor...
 }

 void loop()


Anbindung an NeoPixel Stick

Anbindung an NeoPixel Stick

--- Node-tification/Node-tification.ino
+++ Node-tification/Node-tification.ino
@@ -1,3 +1,5 @@
+#include <Adafruit_NeoPixel.h>
+
 #include <ESP8266WiFi.h>
 #include <PubSubClient.h>

@@ -8,6 +10,7 @@
 const int buzzer2 = 15; //D8
 WiFiClient espClient;
 PubSubClient client(espClient);
+Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, 12, NEO_GRB + NEO_KHZ800);

 void setup() {
   delay(1000);
@@ -23,7 +26,8 @@
   analogWrite(led_R, 0);
   analogWrite(led_G, 0);
   analogWrite(led_B, 0);
-
+  strip.begin();
+  strip.show();
   //verbinden mit Access Point
   Serial.println();
   Serial.print("\nVerbinden");
@@ -64,28 +68,34 @@
   }
   Serial.println();
   if((char)payload[0] == 'k') {
-    led_flash(0, 0, 255, 1000);
+    led_flash(0, 0, 255, 250);
     buzz(2, 2, 512);
     Serial.println("Es hat an der Tür geklingelt!");
   } else if((char)payload[0] == 'o') {
-    led_flash(0, 255, 0, 1000);
+    led_flash(0, 255, 0, 250);
     buzz(1, 1, 1024);
     Serial.println("Zugelassen!");
   } else if((char)payload[0] == 'n') {
-    led_flash(255, 0, 0, 1000);
+    led_flash(255, 0, 0, 250);
     buzz(6, 6, 175);
     Serial.println("Abgelehnt!");
-  } else {
-    led_flash(255, 255, 255, 1000);
   }
   payload = 0;
 }

-//LED mit RGB-Wert blinken lassen
+//LEDs mit RGB-Wert blinken lassen
 void led_flash(byte red, byte green, byte blue, int ms) {
   analogWrite(led_R, red);
   analogWrite(led_G, green);
   analogWrite(led_B, blue);
+  for (int i = 0; i < 8; i++) {
+    strip.setPixelColor(i, red, green, blue);
+    strip.show();
+    delay(50);
+    strip.setPixelColor(i, 0, 0, 0);
+    strip.show();
+    delay(50);
+  }
   delay(ms);
   analogWrite(led_R, 0);
   analogWrite(led_G, 0);


reconnect

reconnect

--- _06-power_meter/_06-power_meter.ino
+++ _06-power_meter/_06-power_meter.ino
@@ -108,16 +108,18 @@
 }

 boolean reconnect() {
-  if (client.connect((char*) clientName.c_str(), willTopic, 0, true, willMessage)) {
-    client.publish(willTopic, "1", true);
-    client.publish(hellotopic, "hello again 1 from ESP8266 s07");
-    if (DEBUG_PRINT) {
-      Serial.println("---------------> connected");
-    }
-  } else {
-    if (DEBUG_PRINT) {
-      Serial.print("----------------> failed, rc=");
-      Serial.println(client.state());
+  if (!client.connected()) {
+    if (client.connect((char*) clientName.c_str(), willTopic, 0, true, willMessage)) {
+      client.publish(willTopic, "1", true);
+      client.publish(hellotopic, "hello again 1 from ESP8266 s07");
+      if (DEBUG_PRINT) {
+        Serial.println("---------------> connected");
+      }
+    } else {
+      if (DEBUG_PRINT) {
+        Serial.print("----------------> failed, rc=");
+        Serial.println(client.state());
+      }
     }
   }
   //timemillis = millis();
@@ -197,9 +199,7 @@
   attachInterrupt(4, IRCHECKING_START, RISING);
   attachInterrupt(5, DOORCHECKING, CHANGE);

-
   emon1.current(A0, 75);
-
   oldirStatus = LOW ;

 }
@@ -230,9 +230,7 @@
           lastReconnectAttempt = 0;
         }
       }
-    } /* else {
-      client.loop();
-    } */
+    }
   } else {
     wifi_connect();
   }
@@ -240,6 +238,8 @@
   VIrms = emon1.calcIrms(1480) * 220.0;
   ave.push(VIrms);
   average = ave.mean();
+
+  client.loop();

   if ( revMills > 600 ) {
     revValue = (float(( 3600  * 1000 ) / ( 600 * float(revMills) ) ) * 1000);
@@ -300,7 +300,7 @@
     sentMills = millis();
   }
   client.loop();
-  delay(50);
+  //delay(50);

 }


Changed the speaker function to take different tone patterns. Created a tone pattern for a device communication failure. Wrote EEPROM initialization for new chips. Created a function that puts a time delay on sounding the alarm so that false readings won't cause a false alarm. Also slows down the alarm send rate so that the alarm beacon isn't overwhelmed.

--- Alarm_Tone/Alarm_Tone.ino
+++ Alarm_Tone/Alarm_Tone.ino
@@ -49,11 +49,12 @@
 const int speakerOut = 9;
 const byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
 const int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
-const byte melody[] = "3b3d3b3d"; //"3b3d3b3d3b3d3b3d";
+const byte alarmTone[] = "3b3d3b3d"; //Takes speaker 1211ms to execute this tone
+const byte heartDeath[] = "2a1p2a3p";
 // count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
 //                                10                  20                  30
 bool alarmSounding = false;
-void speaker();
+void speaker(const byte melody[], unsigned int arraySize);

 //Bluetooth/Serial global variables
 const int receivePin = 10;
@@ -62,6 +63,11 @@
 const int serialBaud = 9600;
 SoftwareSerial bluetooth(receivePin, transmitPin);

+//Water readings global variables
+const unsigned int timeTillOff = 100;
+const int delayTillAlarm = 100;
+void waterReadings();
+
 void setup() {

   //Setup LED
@@ -83,6 +89,9 @@
     opMode = alarm;
     blinkRate = alarmBlinkRate;
   }
+  else {
+    EEPROM.write(eepromModeAddress, opMode);
+  }

   //Setup Bluetooth/serial
   //Even though they might not be used (based on mode), activate them anyways so that the
@@ -93,14 +102,18 @@

 void loop() {
   //Sensor has been triggered or serial has been triggered
-  //Communications dictionary: '1' = alarm, '5' = reconfiguration
+  //Communications dictionary: '1' = alarm, '2' = heartbeat, '5' = reconfiguration
   //Reconfiguration protocol: "5 *mode*" ('5' signals that the next command is a reconfiguration, then a space, then the mode (0=sensor, 1=alarm, 2=query))
+  //Todo: in laptop relay, program it to only forward the communications dictionary commands, need a way to signal groups of communications
   //Todo: include fluctuation tolerance (e.g. 10 activations required before alarm)
   //Todo: heartbeat communications
   //Todo: communications on the serial interfaces may have varying length. Account for it
-  if (digitalRead (sensorPin) == LOW && opMode == sensor) {
-    bluetooth.write('1');
-  }
+  //DONE Todo: slow down bluetooth send rate. It's too fast and will leave an alarm on forever.
+
+  if (opMode == sensor) {
+    waterReadings();
+  }
+
   if (Serial.available()) { //DO NOT allow mode reconfiguration via bluetooth. Security hazard.

     if (opMode == alarm) { //What if the Serial command was triggered to reconfigure? (CHECK WITH EUGEN THAT POWER AND USB COMBINED WON'T FRY THE BOARD!)
@@ -110,7 +123,7 @@
         reconfiguration(); //Start reconfiguration code
       }
       else if (input == '1') { //alarm has been rung
-        speaker();
+        speaker(alarmTone, sizeof(alarmTone));
       }

     }
@@ -127,11 +140,57 @@
       blinkRate = 0;
     }
   }
+
   //oscillate light
   if (millis() - time >= blinkRate) {
     statePin = !statePin;
     digitalWrite(ledPin, statePin);
     time = millis();
+  }
+}
+
+void waterReadings() {
+  static bool noticed = false; //has it been noticed that a high reading was made recently?
+  static unsigned long timeNoticed = 0; //time the initial high reading was noticed
+  static unsigned int timeSinceLastHigh = 0; //time since the last high reading
+  static bool activated = false; //has the high readings been around long enough that it warranted an alarm
+  static unsigned long lastSignal = 0; //time the last warning signal was sent
+
+  // if a water reading is made
+  if (digitalRead (sensorPin) == LOW) {
+    timeSinceLastHigh = millis(); //a high water reading was made, reset the counter
+
+    //if there has been one seen previously
+    if (noticed) {
+
+      //and it's been around for a while without getting turned off, activate
+      if (millis() - timeNoticed >= delayTillAlarm && activated == false) {
+        bluetooth.write('1');
+        activated = true;
+        lastSignal = millis();
+      }
+
+      //if the alarm has already been activated, wait for the first alarm to play so you don't flood the alarm beacon
+      if (activated && millis() - lastSignal >= 1200) {
+        bluetooth.write('1');
+        lastSignal = millis();
+      }
+
+    }
+    else { //this is the first time it's been seen, make note of it
+      noticed = true;
+      timeNoticed = millis();
+    }
+
+  }
+  else { //there is no more high water readings
+
+    //if the high water readings have been away for a while, kill the alarm
+    if (noticed && millis() - timeSinceLastHigh > timeTillOff) {
+      noticed = false;
+      activated = false;
+    }
+
   }
 }

@@ -188,10 +247,10 @@
   return retVal;
 }

-void speaker() {
+void speaker(const byte melody[], unsigned int arraySize) {
   alarmSounding = true;
   analogWrite(speakerOut, 0); //Ensure speaker starts off
-  for (int count = 0; count < (sizeof(melody) - 1) / 2; count++) { //Iterates through the notes requested
+  for (int count = 0; count < (arraySize - 1) / 2; count++) { //Iterates through the notes requested
     statePin = !statePin;
     digitalWrite(ledPin, statePin);
     for (int count2 = 0; count2 < 8; count2++) { //Iterate through tones


fixing travis

fixing travis

--- Arduino/hardware/REV10/REV10MessagePathTest/REV10SecureBHR/REV10SecureBHR.ino
+++ Arduino/hardware/REV10/REV10MessagePathTest/REV10SecureBHR/REV10SecureBHR.ino
@@ -498,13 +498,6 @@
 #if 1
                 // Show stack headroom.
                 OTV0P2BASE::serialPrintAndFlush(F("SH ")); OTV0P2BASE::serialPrintAndFlush(OTV0P2BASE::MemoryChecks::getMinSPSpaceBelowStackToEnd()); OTV0P2BASE::serialPrintlnAndFlush();
-                OTV0P2BASE::serialPrintAndFlush(F("oldSP: "));
-                OTV0P2BASE::serialPrintAndFlush(oldSP);
-                OTV0P2BASE::serialPrintAndFlush(F(" oldLoc: "));
-                OTV0P2BASE::serialPrintAndFlush(oldLoc);
-                OTV0P2BASE::serialPrintAndFlush(F(" oldPC: "));
-                OTV0P2BASE::serialPrintAndFlush(oldPC, HEX);
-                OTV0P2BASE::serialPrintlnAndFlush();
 #endif
                 // Default light-weight print and TX of stats.
                 bareStatsTX();


Move sampling variables into a struct

Move sampling variables into a struct

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -27,13 +27,22 @@
 #define CALIBRATE_BTN           D4

 ReadingSync rs (INTERVAL_MINS, PRE_HEAT_SECS, Time.now());
-
 SimpleEeprom flash;

+struct reading {
+    int    reading_time = 0;
+    double temperature = 0;
+    double humidity = 0;
+    int    tgs2602_sewer = 0;
+    int    mq131_ozone = 0;
+    int    mq131_chlorine = 0;
+    float  dust_concentration = 0;
+};
+
+reading sample;
 union float2bytes {float f; char b[sizeof(float)]; };
 int unix_time = 0;
 int delay_ms = 0;
-int reading_time = 0;
 int heating_count=0;
 int calibration_count=0;
 int stage=0;
@@ -47,26 +56,20 @@
 #define DUST_SAMPLE_INTERVAL_MS 30000
 void dht22_wrapper();
 idDHT22 DHT22(D2, dht22_wrapper);
-double temperature = 0;
-double humidity = 0;

 // --------------------------------------------------------------------- Shinyei PPD42NS
 ShinyeiPPD42NS dust(DUST_SAMPLE_INTERVAL_MS);
-float dust_concentration = 0;

 // --------------------------------------------------------------------- TGS2602
 TGS2602 tgs2602(SAMPLING_FREQUENCY, SAMPLING_INTERVAL_MS);
 float tgs2602_Ro = 2.511;
 int   tgs2602_sample_avg = 0;
-int   tgs2602_sewer = 0;
 char  tgs2602_display[10];

 // --------------------------------------------------------------------- MQ131
 MQ131 mq131(SAMPLING_FREQUENCY, SAMPLING_INTERVAL_MS);
 float mq131_Ro = 2.501;
 int   mq131_sample_avg = 0;
-int   mq131_ozone = 0;
-int   mq131_chlorine = 0;
 char  mq131_display[10];

 // --------------------------------------------------------------------- HTTP
@@ -81,8 +84,8 @@
   mq131_Ro = flash.readFloat(0);
   tgs2602_Ro = flash.readFloat(4);
   // Register a Spark variable here
-  Spark.variable("temperature", &temperature, DOUBLE);
-  Spark.variable("humidity", &humidity, DOUBLE);
+  Spark.variable("temperature", &sample.temperature, DOUBLE);
+  Spark.variable("humidity", &sample.humidity, DOUBLE);
   Spark.variable("unix_time", &unix_time, INT);
   Spark.variable("stage", &stage, INT);
   //Spark.variable("tgs2602", &tgs2602_sample_avg, INT);
@@ -123,7 +126,7 @@
           tgs2602.startSampling(current_ms);
           mq131.startSampling(current_ms);
           dust.startSampling(current_ms);
-          reading_time = unix_time;
+          sample.reading_time = unix_time;
         }
         if(!tgs2602.isSamplingComplete()) {
           tgs2602_sample_avg = tgs2602.getResistanceCalculationAverage(analogRead(SENSOR_TGS2602), current_ms);
@@ -133,12 +136,12 @@
         }
         if(!dust.isSamplingComplete()) {
           unsigned long duration = pulseIn(DUST_PIN, LOW);
-          dust_concentration = dust.getConcentration(duration, current_ms);
+          sample.dust_concentration = dust.getConcentration(duration, current_ms);
         }
         if(mq131.isSamplingComplete() && dust.isSamplingComplete() && tgs2602.isSamplingComplete()) {
-          tgs2602_sewer = tgs2602.getSewerGasPercentage(tgs2602_sample_avg, tgs2602_Ro);
-          mq131_ozone = mq131.getOzoneGasPercentage(mq131_sample_avg, mq131_Ro);
-          mq131_chlorine = mq131.getChlorineGasPercentage(mq131_sample_avg, mq131_Ro);
+          sample.tgs2602_sewer = tgs2602.getSewerGasPercentage(tgs2602_sample_avg, tgs2602_Ro);
+          sample.mq131_ozone = mq131.getOzoneGasPercentage(mq131_sample_avg, mq131_Ro);
+          sample.mq131_chlorine = mq131.getChlorineGasPercentage(mq131_sample_avg, mq131_Ro);
           rs.setSamplingComplete();
         }
         delay_ms=0;
@@ -146,7 +149,7 @@
       break;
     case rs.SEND_READING:
       {
-        sprintf(url, "/iaq/get_reading.php?core_id=%s&temp=%2f&hum=%2f&ozone=%i&chlorine=%i&sewer=%i&dust=%2f&unix_time=%i", Spark.deviceID().c_str(), temperature, humidity, mq131_ozone, mq131_chlorine, tgs2602_sewer, dust_concentration, reading_time);
+        sprintf(url, "/iaq/get_reading.php?core_id=%s&temp=%2f&hum=%2f&ozone=%i&chlorine=%i&sewer=%i&dust=%2f&unix_time=%i", Spark.deviceID().c_str(), sample.temperature, sample.humidity, sample.mq131_ozone, sample.mq131_chlorine, sample.tgs2602_sewer, sample.dust_concentration, sample.reading_time);
         request.path = url;
         http.get(request, response);
         rs.setReadingSent();
@@ -207,8 +210,8 @@
   DHT22.acquire();
   while (DHT22.acquiring());

-  humidity = DHT22.getHumidity();
-  temperature = DHT22.getCelsius();
+  sample.humidity = DHT22.getHumidity();
+  sample.temperature = DHT22.getCelsius();
 }

 void beep(int delay_ms) {


added button code

added button code

--- BaselineReading/BaselineReading.ino
+++ BaselineReading/BaselineReading.ino
@@ -19,6 +19,16 @@
 unsigned long microsPerReading, microsPrevious;
 float accelScale, gyroScale;

+// BUTTON
+// set pin numbers:
+const int buttonPin = 2;     // the number of the pushbutton pin
+const int ledPin =  13;      // the number of the LED pin
+
+int buttonState = 0;         // variable for reading the pushbutton status
+
+// BASELINE
+const int readyPin = 3;
+
 // SETUP
 void setup() {
   Serial.begin(9600);
@@ -37,46 +47,64 @@
   // initialize variables to pace updates to correct rate
   microsPerReading = 1000000 / 25;
   microsPrevious = micros();
+
+  // initialize the LED pin as an output:
+  pinMode(ledPin, OUTPUT);
+  // initialize the pushbutton pin as an input:
+  pinMode(buttonPin, INPUT);
 }

 void loop() {
-  int aix, aiy, aiz;
-  int gix, giy, giz;
-  float ax, ay, az;
-  float gx, gy, gz;
-  float doorAngle;
-  int ping_1, ping_2;
-  unsigned long microsNow;
+  // read the state of the pushbutton value:
+  buttonState = digitalRead(buttonPin);

-  // check if it's time to read data and update the filter
-  microsNow = micros();
-  if (microsNow - microsPrevious >= microsPerReading) {
-
-    // read raw data from CurieIMU
-    CurieIMU.readMotionSensor(aix, aiy, aiz, gix, giy, giz);
-
-    // convert from raw data to gravity and degrees/second units
-    ax = convertRawAcceleration(aix);
-    ay = convertRawAcceleration(aiy);
-    az = convertRawAcceleration(aiz);
-    gx = convertRawGyro(gix);
-    gy = convertRawGyro(giy);
-    gz = convertRawGyro(giz);
-
-    // update the filter, which computes orientation
-    filter.updateIMU(gx, gy, gz, ax, ay, az);
-
-    // print the heading, pitch and roll
-    doorAngle = filter.getYaw();
-    Serial.print("Door Angle: ");
-    Serial.println(doorAngle);
-
-    ping_1 = sonar_1.ping_cm();
-    ping_2 = sonar_2.ping_cm();
-    printpings(ping_1, ping_2);
-
-    // increment previous time, so we keep proper pace
-    microsPrevious = microsPrevious + microsPerReading;
+  // check if the pushbutton is pressed.
+  // if it is, the buttonState is HIGH:
+  if (buttonState == HIGH) {
+    // turn LED on:
+    digitalWrite(ledPin, HIGH);
+    digitalWrite(readyPin, HIGH);
+  } else {
+    // turn LED off:
+    digitalWrite(ledPin, LOW);
+    int aix, aiy, aiz;
+    int gix, giy, giz;
+    float ax, ay, az;
+    float gx, gy, gz;
+    float doorAngle;
+    int ping_1, ping_2;
+    unsigned long microsNow;
+
+    // check if it's time to read data and update the filter
+    microsNow = micros();
+    if (microsNow - microsPrevious >= microsPerReading) {
+
+      // read raw data from CurieIMU
+      CurieIMU.readMotionSensor(aix, aiy, aiz, gix, giy, giz);
+
+      // convert from raw data to gravity and degrees/second units
+      ax = convertRawAcceleration(aix);
+      ay = convertRawAcceleration(aiy);
+      az = convertRawAcceleration(aiz);
+      gx = convertRawGyro(gix);
+      gy = convertRawGyro(giy);
+      gz = convertRawGyro(giz);
+
+      // update the filter, which computes orientation
+      filter.updateIMU(gx, gy, gz, ax, ay, az);
+
+      // print the heading, pitch and roll
+      doorAngle = filter.getYaw();
+      Serial.print("Door Angle: ");
+      Serial.println(doorAngle);
+
+      ping_1 = sonar_1.ping_cm();
+      ping_2 = sonar_2.ping_cm();
+      printpings(ping_1, ping_2);
+
+      // increment previous time, so we keep proper pace
+      microsPrevious = microsPrevious + microsPerReading;
+    }
   }
 }