Edited build/shared/examples/4.Communication/SerialEvent/SerialEvent.ino via GitHub

--- build/shared/examples/4.Communication/SerialEvent/SerialEvent.ino
+++ build/shared/examples/4.Communication/SerialEvent/SerialEvent.ino
@@ -39,7 +39,7 @@

 /*
   SerialEvent occurs whenever a new byte comes in the
- hardware serial RX.  Don't do complex things here, as thge
+ hardware serial RX.  Don't do complex things here, as the
  processor halts the regular program to run this routine:
  */
 void serialEvent() {


Revert "Dodano odczyty temperatury"

Revert "Dodano odczyty temperatury"

This reverts commit 9f5d083cc7a6864edb1523989b53dd1d2bd39115.

--- Odczyty.ino
+++ Odczyty.ino
@@ -1,17 +0,0 @@
-const int pinTermometru = 0;
-void setup() {
-Serial.begin(9600);
-
-}
-
-float odczyt_temperatury(){
-float temperatura;
-temperatura = (analogRead(pinTermometru)/1024.0)*500;
-temperatura = temperatura - 276;
-return temperatura;
-}
-
-void loop() {
-Serial.println(odczyt_temperatury());
-delay(1000);
-}


Fix build

Fix build

--- examples/More/ArduinoClient/Arduino_Ethernet/Arduino_Ethernet.ino
+++ examples/More/ArduinoClient/Arduino_Ethernet/Arduino_Ethernet.ino
@@ -27,6 +27,8 @@
 /* Comment this out to disable prints and save space */
 #define BLYNK_PRINT Serial

+
+#include <SPI.h>
 #include <Ethernet.h>
 #include <BlynkSimpleStream.h>


Determine sensor thresholds based upon sampling ambient light prior to start.

--- PinewoodDerbyPracticeTrackTimer/PinewoodDerbyPracticeTrackTimer.ino
+++ PinewoodDerbyPracticeTrackTimer/PinewoodDerbyPracticeTrackTimer.ino
@@ -3,18 +3,35 @@
 #define END_SENSOR A1
 #define START_SENSOR A2
 #define SENSOR_LOW 0
-#define SENSOR_HIGH 250
+#define SENSOR_HIGH 150 //250
+// sensor % is used
+// as a multiplier against the ambient
+// light
+#define SENSOR_PCT 0.8
+#define SENSOR_SAMPLES 1000

 LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
 int LastKeyPressed = -1;
 bool DebugMode = false;
+int ambient_light_value_start = 0;
+int ambient_light_value_end = 0;
+int sensor_high_start = 0;
+int sensor_high_end = 0;

 void setup() {
   lcd.begin(16, 2);
   lcd.clear();
   pinMode(START_SENSOR, INPUT);
   pinMode(END_SENSOR, INPUT);
-  Serial.begin(9600);      // open the serial port at 9600 bps:
+  Serial.begin(9600);      // open the serial port at 9600 bps:
+  ambient_light_value_start = guess_ambient_light(START_SENSOR);
+  ambient_light_value_end = guess_ambient_light(END_SENSOR);
+  sensor_high_start = int(ambient_light_value_start * SENSOR_PCT);
+  sensor_high_end = int(ambient_light_value_end * SENSOR_PCT);
+  Serial.print("Detected ambient light value for start to be ");
+  Serial.println(ambient_light_value_start);
+  Serial.print("Detected ambient light value for end to be ");
+  Serial.println(ambient_light_value_end);
 }

 int sensor_tripped(int sensor_id, int low_value, int high_value) {
@@ -25,6 +42,14 @@
     return true;
   }
   return false;
+}
+
+int guess_ambient_light(int sensor_id) {
+  unsigned long sensor_data = 0;
+  for(int i=0;i<SENSOR_SAMPLES;i++) {
+    sensor_data += analogRead(sensor_id);
+  }
+  return int(sensor_data / SENSOR_SAMPLES);
 }

 void loop() {
@@ -42,13 +67,16 @@
     starttime = 0;
     endtime = 0;
     elapsed_time = 0;
-
+
     ClearLine(0);
-    DisplayText(0, 0, "Ready");
-    Serial.print("Ready\n");
-
+    DisplayText(0, 0, "Ready           ");
+    Serial.println("Ready");
+
+    // blinkdisplay
+    BlinkDisplay(500);
+
     while (!started) {
-      started = sensor_tripped(START_SENSOR, SENSOR_LOW, SENSOR_HIGH);
+      started = sensor_tripped(START_SENSOR, SENSOR_LOW, sensor_high_start);
     }
     starttime = millis();
     Serial.print("sense start at ");
@@ -60,32 +88,37 @@
     // when testing with buttons, however a legal
     // car must past start before finishing
     while (started) {
-      started = sensor_tripped(START_SENSOR, SENSOR_LOW, SENSOR_HIGH);
+      started = sensor_tripped(START_SENSOR, SENSOR_LOW, sensor_high_start);
     }
-
-    ClearLine(1);
-    DisplayText(0, 0, "Start");
+
+    lcd.clear();
+    DisplayText(0, 0, "Car started   ");
     while (!finished) {
-      finished = sensor_tripped(END_SENSOR, SENSOR_LOW, SENSOR_HIGH);
+      finished = sensor_tripped(END_SENSOR, SENSOR_LOW, sensor_high_end);
     }
     endtime = millis();
     elapsed_time = endtime - starttime;

     // debounce finished sensor
     while (finished) {
-      finished = sensor_tripped(END_SENSOR, SENSOR_LOW, SENSOR_HIGH);
+      finished = sensor_tripped(END_SENSOR, SENSOR_LOW, sensor_high_end);
     }
     sprintf(DisplayString, "Elapsed %lu ms", elapsed_time);
     Serial.print(DisplayString);
     Serial.print("\n");
-    ClearLine(0);
-    ClearLine(1);
-    DisplayText(0, 0, "Finished:");
+    lcd.clear();
+    DisplayText(0, 0, "Finished:       ");
     DisplayText(1, 0, DisplayString);
     delay(2500);
   }
 }

+
+void BlinkDisplay(int blink_delay) {
+    lcd.noDisplay();
+    delay(blink_delay);
+    lcd.display();
+}
 void ClearLine(int LineToClear) {
   lcd.setCursor(0, LineToClear); //0 is the first and 1 is the second line, x=0
   lcd.print("                "); //Add 16 spaces to clear the line (there may be better ways to do this)
@@ -94,4 +127,3 @@
   lcd.setCursor(CursorPos, Line); //0 is the first line and 1 is the second line
   lcd.print(TextToDisplay);
 }
-


Restructure to avoid the heap memory

Restructure to avoid the heap memory

--- RightpointLabs.Pourcast.Arduino/RightpointLabs.Pourcast.Arduino.ino
+++ RightpointLabs.Pourcast.Arduino/RightpointLabs.Pourcast.Arduino.ino
@@ -57,6 +57,12 @@
 // Newer Ethernet shields have a MAC address printed on a sticker on the shield
 byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x84, 0xC2 };

+void dumpWatchdogHistory() {
+  NetworkPrint np(http);
+  ApplicationMonitor.Dump(np);
+  ApplicationMonitor.Dump(Serial);
+}
+
 // prep - initialize serial (TX on pin 1) and wire up the interrupts for pulses from the taps (pins 2 and 3)
 void setup() {
   ApplicationMonitor.DisableWatchdog();
@@ -77,9 +83,7 @@
   http = new NetworkRequester("pourcast.labs.rightpoint.com", 9, new NullPrint());
   http->LogMessage(F("Initializing"));

-  NetworkPrint* np = new NetworkPrint(http);
-  ApplicationMonitor.Dump(*np);
-  delete np;
+  dumpWatchdogHistory();

   NetworkReporter* tap1Reporter = new NetworkReporter(http, "535c61a951aa0405287989ec");
   NetworkReporter* tap2Reporter = new NetworkReporter(http, "537d28db51aa04289027cde5");


Fixing tilt to different pin of the cape

--- arduino/OpenROV/OpenROV.ino
+++ arduino/OpenROV/OpenROV.ino
@@ -24,7 +24,7 @@

   pinMode(13, OUTPUT);

-  tilt.attach(12);
+  tilt.attach(3);
   light.attach(6);

   motors.reset();


Removed Angle Restrictions

Removed Angle Restrictions

We can tell the servo to point anywhere now.

--- embedded/SerialCommander/SerialCommander.ino
+++ embedded/SerialCommander/SerialCommander.ino
@@ -52,10 +52,7 @@

 #define commsTimeout 200 //The maximum time that a received serial command can take, in mS

-#define ballReleaseTime 500 //The time that the solenoid needs to be activated for to release a ball, in mS
-
-#define angleLowest 1 //The minimum allowable angle
-#define angleHighest 180 //The maximum allowable angle
+#define ballReleaseTime 20 //The time that the solenoid needs to be activated for to release a ball, in mS

 #define motorLevel1 255 //PWM levls for the motors
 #define motorLevel2 255
@@ -129,7 +126,7 @@

   //Attach the servo objects
-  servo1.attach(pinServo1,545,2455); //Include the maximum and minimum pulse widths.
+  servo1.attach(pinServo1,530,2470); //Include the maximum and minimum pulse widths.
   servo2.attach(pinServo2,545,2455);
   servo3.attach(pinServo3,545,2455);

@@ -256,29 +253,23 @@

   //Set the servo output.  Use a switch statement to use the correct servo object.
-  if (angle<angleLowest || angle>angleHighest) {
-    //The angle is invalid! Don't move the shooter
-    Serial.print("Invalid angle: ");
-    Serial.println(angle);
-  }
-  else{
+
     //Apply the angle offset
-    angle += offset[shooterNum];
+    int out = angle + offset[shooterNum];
     switch (shooterNum) {
     case 1:
-      servo1.write(angle);
+      servo1.write(out);
       break;
     case 2:
-      servo2.write(angle);
+      servo2.write(out);
       break;
     case 3:
-      servo1.write(angle);
+      servo3.write(out);
       break;
     default:

       Serial.print("Unrecognized shooter Num: ");
       Serial.println(shooterNum);
-    }
   }
 }


#18 Support for more than one shift register chained together (up to 4 in, 4 out)

--- examples/exampleShiftReg/exampleShiftReg.ino
+++ examples/exampleShiftReg/exampleShiftReg.ino
@@ -3,21 +3,21 @@
 #define READ_CLOCK_PIN 28
 #define READ_DATA_PIN 26
 #define READ_LATCH_PIN 25
-#define READ_CLK_ENA_PIN 27

 #define WRITE_CLOCK_PIN 22
 #define WRITE_DATA_PIN 23
 #define WRITE_LATCH_PIN 24

-IoAbstractionRef shiftRegister = inputOutputFromShiftRegister(READ_CLOCK_PIN, READ_DATA_PIN, READ_LATCH_PIN, WRITE_CLOCK_PIN, WRITE_DATA_PIN, WRITE_LATCH_PIN);
+// here we create a shift register abstraction that has 1 input and 1 output shift register.
+IoAbstractionRef shiftRegister = inputOutputFromShiftRegister(READ_CLOCK_PIN, READ_DATA_PIN, READ_LATCH_PIN, 1, WRITE_CLOCK_PIN, WRITE_DATA_PIN, WRITE_LATCH_PIN, 1);

 void setup() {
 	// although not technically needed for the shift register we should always call pinDirection
 	// as it makes it possible to switch in future to either arduino direct or IO expander.

-	// 0-7 are always input and 24 onwards are always output with the shift register abstraction
-	// this allows for a future improvement where more than one register could be easily supported.
-	for (int i = 24; i < 32; ++i) {
+	// 0-7 are always input and 32 onwards are always output with the shift register abstraction
+	// this allows for up to 4 input and 4 output devices to be chained together.
+	for (int i = 32; i < 40; ++i) {
 		ioDevicePinMode(shiftRegister, i, OUTPUT);
 	}
 	for (int i = 0; i < 8; ++i) {
@@ -30,9 +30,9 @@
 void loop() {
 	delay(1);
 	ioDeviceSync(shiftRegister);
-	ioDeviceDigitalWrite(shiftRegister, 24, ioDeviceDigitalRead(shiftRegister, 1));
-	ioDeviceDigitalWrite(shiftRegister, 25, ioDeviceDigitalRead(shiftRegister, 2));
-	ioDeviceDigitalWrite(shiftRegister, 26, ioDeviceDigitalRead(shiftRegister, 3));
+	ioDeviceDigitalWrite(shiftRegister, 32, ioDeviceDigitalRead(shiftRegister, 1));
+	ioDeviceDigitalWrite(shiftRegister, 33, ioDeviceDigitalRead(shiftRegister, 2));
+	ioDeviceDigitalWrite(shiftRegister, 34, ioDeviceDigitalRead(shiftRegister, 3));
 	counter++;
-	ioDeviceDigitalWrite(shiftRegister, 27, (counter > 128));
+	ioDeviceDigitalWrite(shiftRegister, 35, (counter > 128));
 }


more idle mode

more idle mode

--- main/main.ino
+++ main/main.ino
@@ -100,6 +100,13 @@
 const int SPI_CS_PIN = 10;

 EngineVariable* idleGauges[8];
+bool idleModeReady = false;
+
+enum gaugeMode {
+  idle,
+  two,
+  four
+};

 MCP_CAN CAN(SPI_CS_PIN);

@@ -112,12 +119,18 @@
   lcd.createChar(4, fill5);

   idleGauges[0] = &engine_rpm;
-
+  idleGauges[1] = &engine_map;
+  idleGauges[2] = &engine_afr;
+  idleGauges[3] = &engine_adv;
+  idleGauges[4] = &engine_clt;
+  idleGauges[5] = &engine_iat;
+  idleGauges[6] = &engine_pw1;
+  idleGauges[7] = &engine_bat;

   lcd.begin(20, 4);
-  lcd.print(engine_rpm.shortLabel);
-  lcd.setCursor(0, 2);
-  lcd.print(engine_afr.shortLabel);
+  //lcd.print(engine_rpm.shortLabel);
+  //lcd.setCursor(0, 2);
+  //lcd.print(engine_afr.shortLabel);

   Serial.begin(115200);
   while (CAN_OK != CAN.begin(CAN_500KBPS))              // init can bus : baudrate = 500k
@@ -139,6 +152,10 @@
       draw_idle_gauges();
     }
     else {
+      if(idleModeReady) {
+        lcd.clear();
+        idleModeReady = false;
+      }
       if(engine_rpm.currentValue != engine_rpm.previousValue) {
         lcd.setCursor(4, 0);
         if(is_current_value_shorter(engine_rpm)) {
@@ -157,20 +174,20 @@
   }
 }

-void draw_idle_gauges() {
-
-  //todo only draw this the first time we enter idle mode
-  if(true) {
+void start_idle_mode() {
     lcd.clear();
+
+    //left column of labels
     lcd.setCursor(0, 0);
-    lcd.print(engine_rpm.shortLabel);
+    lcd.print(idleGauges[0]->shortLabel);
     lcd.setCursor(0, 1);
-    lcd.print(engine_map.shortLabel);
+    lcd.print(idleGauges[1]->shortLabel);
     lcd.setCursor(0, 2);
-    lcd.print(engine_afr.shortLabel);
+    lcd.print(idleGauges[2]->shortLabel);
     lcd.setCursor(0, 3);
-    lcd.print(engine_bat.shortLabel);
-
+    lcd.print(idleGauges[3]->shortLabel);
+
+    //draw dividing line
     lcd.setCursor(9, 0);
     lcd.write(byte(4));
     lcd.setCursor(9, 1);
@@ -180,46 +197,48 @@
     lcd.setCursor(9, 3);
     lcd.write(byte(4));

+    //right column of labels
     lcd.setCursor(11, 0);
-    lcd.print(engine_clt.shortLabel);
+    lcd.print(idleGauges[4]->shortLabel);
     lcd.setCursor(11, 1);
-    lcd.print(engine_iat.shortLabel);
+    lcd.print(idleGauges[5]->shortLabel);
     lcd.setCursor(11, 2);
-    lcd.print(engine_adv.shortLabel);
+    lcd.print(idleGauges[6]->shortLabel);
     lcd.setCursor(11, 3);
-    lcd.print(engine_pw1.shortLabel);
+    lcd.print(idleGauges[7]->shortLabel);
+
+    idleModeReady = true;
+}
+
+void draw_idle_gauges() {
+
+  if(!idleModeReady) {
+    start_idle_mode();
   }

-  for(int i = 0; i < 1; i++) {
-    lcd.setCursor(4, i);
-    lcd.print(idleGauges[i]->currentValue, idleGauges[i]->decimalPlaces);
-  }
-
-  //lcd.setCursor(4, 0);
-  //lcd.print(engine_rpm.currentValue, engine_rpm.decimalPlaces);
+  lcd.setCursor(4, 0);
+  lcd.print(idleGauges[0]->currentValue, idleGauges[0]->decimalPlaces);

   lcd.setCursor(4, 1);
-  lcd.print(engine_map.currentValue, engine_map.decimalPlaces);
+  lcd.print(idleGauges[1]->currentValue, idleGauges[1]->decimalPlaces);

   lcd.setCursor(4, 2);
-  lcd.print(engine_afr.currentValue, engine_afr.decimalPlaces);
+  lcd.print(idleGauges[2]->currentValue, idleGauges[2]->decimalPlaces);

   lcd.setCursor(4, 3);
-  lcd.print(engine_bat.currentValue, engine_bat.decimalPlaces);
+  lcd.print(idleGauges[3]->currentValue, idleGauges[3]->decimalPlaces);

   lcd.setCursor(15, 0);
-  lcd.print(engine_clt.currentValue, engine_clt.decimalPlaces);
+  lcd.print(idleGauges[4]->currentValue, idleGauges[4]->decimalPlaces);

   lcd.setCursor(15, 1);
-  lcd.print(engine_iat.currentValue, engine_iat.decimalPlaces);
+  lcd.print(idleGauges[5]->currentValue, idleGauges[5]->decimalPlaces);

   lcd.setCursor(15, 2);
-  lcd.print(engine_adv.currentValue, engine_adv.decimalPlaces);
+  lcd.print(idleGauges[6]->currentValue, idleGauges[6]->decimalPlaces);

   lcd.setCursor(15, 3);
-  lcd.print(engine_pw1.currentValue, engine_pw1.decimalPlaces);
-
-
+  lcd.print(idleGauges[7]->currentValue, idleGauges[7]->decimalPlaces);
 }

 void load_from_can() {


start diagnostics functionality

start diagnostics functionality

--- main/main.ino
+++ main/main.ino
@@ -64,28 +64,31 @@
   float minimum;
   float maximum;
   byte decimalPlaces;
+  unsigned long goodCount;
+  unsigned long lowCount;
+  unsigned long highCount;
 };

-EngineVariable engine_map   = {"MAP", 0.0, 0.0, 15.0, 250.0, 1};    //manifold absolute pressure
-EngineVariable engine_rpm   = {"RPM", 0.0, 0.0, 0.0, 6500.0, 0};    //engine rpm
-EngineVariable engine_clt   = {"CLT", 0.0, 0.0, 20.0, 240.0, 0};   //coolant temp
-EngineVariable engine_tps   = {"TPS", 0.0, 0.0, 0.0, 100.0, 0};     //throttle position
-EngineVariable engine_pw1   = {"PW1", 0.0, 0.0, 0.0, 20.0, 3};      //injector pulse width bank 1
-EngineVariable engine_pw2   = {"PW2", 0.0, 0.0, 0.0, 20.0, 3};      //injector pulse width bank 2
-EngineVariable engine_iat   = {"IAT", 0.0, 0.0, 40.0, 150.0, 0};    //intake air temp aka 'mat'
-EngineVariable engine_adv   = {"ADV", 0.0, 0.0, 10.0, 40.0, 1};     //ignition advance
-EngineVariable engine_tgt   = {"TGT", 0.0, 0.0, 10.0, 20.0, 1};     //afr target
-EngineVariable engine_afr   = {"AFR", 0.0, 0.0, 10.0, 20.0, 1};     //air fuel ratio
-EngineVariable engine_ego   = {"EGO", 0.0, 0.0, 70.0, 130.0, 0};    //ego correction %
-EngineVariable engine_egt   = {"EGT", 0.0, 0.0, 100.0, 2000.0, 0};  //exhaust gas temp
-EngineVariable engine_pws   = {"PWS", 0.0, 0.0, 0.0, 20.0, 3};      //injector pulse width sequential
-EngineVariable engine_bat   = {"BAT", 0.0, 0.0, 8.0, 18.0, 1};      //battery voltage
-EngineVariable engine_sr1   = {"SR1", 0.0, 0.0, 0.0, 999.0, 1};     //generic sensor 1
-EngineVariable engine_sr2   = {"SR2", 0.0, 0.0, 0.0, 999.0, 1};     //generic sensor 2
-EngineVariable engine_knk   = {"KNK", 0.0, 0.0, 0.0, 50.0, 1};      //knock ignition retard
-EngineVariable engine_vss   = {"VSS", 0.0, 0.0, 0.0, 160.0, 0};     //vehicle speed
-EngineVariable engine_tcr   = {"TCR", 0.0, 0.0, 0.0, 50.0, 1};      //traction control ignition retard
-EngineVariable engine_lct   = {"LCT", 0.0, 0.0, 0.0, 50.0, 1};     //launch control timing
+EngineVariable engine_map   = {"MAP", 0.0, 0.0, 15.0, 250.0, 1, 0, 0};    //manifold absolute pressure
+EngineVariable engine_rpm   = {"RPM", 0.0, 0.0, 0.0, 6500.0, 0, 0, 0};    //engine rpm
+EngineVariable engine_clt   = {"CLT", 0.0, 0.0, 20.0, 240.0, 0, 0, 0};    //coolant temp
+EngineVariable engine_tps   = {"TPS", 0.0, 0.0, 0.0, 100.0, 0, 0, 0};     //throttle position
+EngineVariable engine_pw1   = {"PW1", 0.0, 0.0, 0.0, 20.0, 3, 0, 0};      //injector pulse width bank 1
+EngineVariable engine_pw2   = {"PW2", 0.0, 0.0, 0.0, 20.0, 3, 0, 0};      //injector pulse width bank 2
+EngineVariable engine_iat   = {"IAT", 0.0, 0.0, 40.0, 150.0, 0, 0, 0};    //intake air temp aka 'mat'
+EngineVariable engine_adv   = {"ADV", 0.0, 0.0, 10.0, 40.0, 1, 0, 0};     //ignition advance
+EngineVariable engine_tgt   = {"TGT", 0.0, 0.0, 10.0, 20.0, 1, 0, 0};     //afr target
+EngineVariable engine_afr   = {"AFR", 0.0, 0.0, 10.0, 20.0, 1, 0, 0};     //air fuel ratio
+EngineVariable engine_ego   = {"EGO", 0.0, 0.0, 70.0, 130.0, 0, 0, 0};    //ego correction %
+EngineVariable engine_egt   = {"EGT", 0.0, 0.0, 100.0, 2000.0, 0, 0, 0};  //exhaust gas temp
+EngineVariable engine_pws   = {"PWS", 0.0, 0.0, 0.0, 20.0, 3, 0, 0};      //injector pulse width sequential
+EngineVariable engine_bat   = {"BAT", 0.0, 0.0, 8.0, 18.0, 1, 0, 0};      //battery voltage
+EngineVariable engine_sr1   = {"SR1", 0.0, 0.0, 0.0, 999.0, 1, 0, 0};     //generic sensor 1
+EngineVariable engine_sr2   = {"SR2", 0.0, 0.0, 0.0, 999.0, 1, 0, 0};     //generic sensor 2
+EngineVariable engine_knk   = {"KNK", 0.0, 0.0, 0.0, 50.0, 1, 0, 0};      //knock ignition retard
+EngineVariable engine_vss   = {"VSS", 0.0, 0.0, 0.0, 160.0, 0, 0, 0};     //vehicle speed
+EngineVariable engine_tcr   = {"TCR", 0.0, 0.0, 0.0, 50.0, 1, 0, 0};      //traction control ignition retard
+EngineVariable engine_lct   = {"LCT", 0.0, 0.0, 0.0, 50.0, 1, 0, 0};      //launch control timing

 byte interval = 100;
 unsigned long lastMillis = 0;
@@ -156,7 +159,11 @@
       //draw_octo_gauges();
       //draw_dual_gauges();
       draw_quad_gauges();
-
+
+      //unsigned long badCount = engine_rpm.lowCount + engine_rpm.highCount;
+      //unsigned long totalCount = badCount + engine_rpm.goodCount;
+      //byte percent = badCount * 100 / totalCount;
+      //Serial.println(percent);
   }
 }

@@ -351,78 +358,98 @@
       case 1512:
         engine_map.previousValue = engine_map.currentValue;
         engine_map.currentValue = ((buf[0] * 256) + buf[1]) / 10.0;
+        increment_counter(&engine_map);

         engine_rpm.previousValue = engine_rpm.currentValue;
         //engine_rpm.currentValue = buf[2] * 256 + buf[3];
         //round rpm to nearest 10
         engine_rpm.currentValue = round((buf[2] * 256 + buf[3]) / 10.0) * 10.0;
-
+        increment_counter(&engine_rpm);
+
         engine_clt.previousValue = engine_clt.currentValue;
         engine_clt.currentValue = (buf[4] * 256 + buf[5]) / 10.0;
-
+        increment_counter(&engine_clt);
+
         engine_tps.previousValue = engine_tps.currentValue;
         engine_tps.currentValue = (buf[6] * 256 + buf[7]) / 10.0;
+        increment_counter(&engine_tps);

         break;
       case 1513:
         engine_pw1.previousValue = engine_pw1.currentValue;
         engine_pw1.currentValue = (buf[0] * 256 + buf[1]) / 1000.0;
+        increment_counter(&engine_pw1);

         engine_pw2.previousValue = engine_pw2.currentValue;
         engine_pw2.currentValue = (buf[2] * 256 + buf[3]) / 1000.0;
+        increment_counter(&engine_pw2);

         engine_iat.previousValue = engine_iat.currentValue;
         engine_iat.currentValue = (buf[4] * 256 + buf[5]) / 10.0;
+        increment_counter(&engine_iat);

         engine_adv.previousValue = engine_adv.currentValue;
         engine_adv.currentValue = (buf[6] * 256 + buf[7]) / 10.0;
+        increment_counter(&engine_adv);

         break;
       case 1514:
         engine_tgt.previousValue = engine_tgt.currentValue;
         engine_tgt.currentValue = (double)buf[0] / 10.0;
+        increment_counter(&engine_tgt);

         engine_afr.previousValue = engine_afr.currentValue;
         engine_afr.currentValue = (double)buf[1] / 10.0;
+        increment_counter(&engine_afr);

         engine_ego.previousValue = engine_ego.currentValue;
         engine_ego.currentValue = (buf[2] * 256 + buf[3]) / 10.0;
+        increment_counter(&engine_ego);

         engine_egt.previousValue = engine_egt.currentValue;
         engine_egt.currentValue = (buf[4] * 256 + buf[5]) / 10.0;
+        increment_counter(&engine_egt);

         engine_pws.previousValue = engine_pws.currentValue;
         engine_pws.currentValue = (buf[6] * 256 + buf[7]) / 1000.0;
+        increment_counter(&engine_pws);

         break;
       case 1515:
         engine_bat.previousValue = engine_bat.currentValue;
         engine_bat.currentValue = (buf[0] * 256 + buf[1]) / 10.0;
+        increment_counter(&engine_bat);

         //not tested
         engine_sr1.previousValue = engine_sr1.currentValue;
         engine_sr1.currentValue = (buf[2] * 256 + buf[3]) / 10.0;
+        increment_counter(&engine_sr1);

         //not tested
         engine_sr2.previousValue = engine_sr2.currentValue;
         engine_sr2.currentValue = (buf[4] * 256 + buf[5]) / 10.0;
+        increment_counter(&engine_sr2);

         //not tested
         engine_knk.previousValue = engine_knk.currentValue;
         engine_knk.currentValue = (buf[6] * 256) / 10.0;
+        increment_counter(&engine_knk);

         break;
       case 1516:
         //not tested
         engine_vss.previousValue = engine_vss.currentValue;
         engine_vss.currentValue = (buf[0] * 256 + buf[1]) / 10.0;
+        increment_counter(&engine_vss);

         //not tested
         engine_tcr.previousValue = engine_tcr.currentValue;
         engine_tcr.currentValue = (buf[2] * 256 + buf[3]) / 10.0;
+        increment_counter(&engine_tcr);

         engine_lct.previousValue = engine_lct.currentValue;
         engine_lct.previousValue = (buf[4] * 256 + buf[5]) / 10.0;
+        increment_counter(&engine_lct);

         break;
       default:
@@ -430,6 +457,18 @@
         break;
     }
   }
+}
+
+void increment_counter(EngineVariable* engine) {
+  if(engine->currentValue > engine->maximum) {
+    engine->highCount++;
+  }
+  else if(engine->currentValue < engine->minimum) {
+    engine->lowCount++;
+  }
+  else {
+    engine->goodCount++;
+  }
 }

 //note: using log10 would work but this is faster


Fix issue #2

Fix issue #2

Disable the software watchdog timer while reading the sensor

--- homie-dht.ino
+++ homie-dht.ino
@@ -19,6 +19,8 @@

   if (millis() - lastPublish >= (publishInterval * 1000UL) || lastPublish == 0 || sensor.force()) {
     lastPublish = millis();
+    ESP.wdtDisable(); // disabling the software watchdog timer will cause the
+                      // the HW watchdog to trigger after 6 seconds.
     if (!sensor.publish()) {
       lastPublish -= (publishInterval * 1000UL); // reading failed, give it another try in 2 seconds
       lastPublish += 2000UL;
@@ -31,6 +33,7 @@
 #endif
       }
     }
+    ESP.wdtEnable(1000);
   }
 }

@@ -51,7 +54,7 @@
   Serial.begin(115200);
   Serial << endl << endl;

-  Homie_setFirmware("homie-dht", "0.0.2");
+  Homie_setFirmware("homie-dht", "0.0.3");
   Homie_setBrand("homie-dht");
   Homie.setSetupFunction(setupHandler).setLoopFunction(loopHandler).onEvent(onHomieEvent);
   Homie.disableLedFeedback();


Detailed instructions in serial console for first time users.

--- Arduino/McLighting/McLighting.ino
+++ Arduino/McLighting/McLighting.ino
@@ -152,9 +152,18 @@
   // ***************************************************************************
   MDNS.begin(HOSTNAME);
   DBG_OUTPUT_PORT.print("Open http://");
+  DBG_OUTPUT_PORT.print(WiFi.localIP());
+  DBG_OUTPUT_PORT.println("/ to open McLighting.");
+
+  DBG_OUTPUT_PORT.print("Use http://");
   DBG_OUTPUT_PORT.print(HOSTNAME);
-  DBG_OUTPUT_PORT.println(".local/edit to see the file browser");
-
+  DBG_OUTPUT_PORT.println(".local/ when you have Bobjour installed.");
+
+  DBG_OUTPUT_PORT.print("New users: Open http://");
+  DBG_OUTPUT_PORT.print(WiFi.localIP());
+  DBG_OUTPUT_PORT.println("/upload to upload the webpages first.");
+
+  DBG_OUTPUT_PORT.println("");

   // ***************************************************************************
   // Setup: WebSocket server


[FW] Missing firmware changes for v. 0.2.

--- firmware/MultiRomVC4000/MultiRomVC4000.ino
+++ firmware/MultiRomVC4000/MultiRomVC4000.ino
@@ -23,12 +23,12 @@
 File romFile;

 void setup() {
+  pinMode(SD_CS, OUTPUT);
   pinMode(CLOCK, OUTPUT);
   pinMode(LATCH, OUTPUT);
   pinMode(DATA, OUTPUT);
   pinMode(WESRAM, OUTPUT);
-  pinMode(OEDATA, OUTPUT);
-  pinMode(OEADDRESS, OUTPUT);
+  pinMode(OESHIFT, OUTPUT);
   pinMode(OEVCBUS, OUTPUT);
   pinMode(LED, OUTPUT);

@@ -51,7 +51,7 @@

   // Write ROM file to SRAM
   if (romFile) {
-    enableSRAM();
+    //enableSRAM();
     unsigned romSize = static_cast<unsigned>(romFile.size());
     if (romSize <= MAX_ROM_SIZE) {
       for (unsigned i = 0; i < romSize; i++) {
@@ -81,24 +81,22 @@
   delay(blinkTimeLow);
 }

-void enableSRAM() {
+/*void enableSRAM() {
   pinMode(CE1SRAM, OUTPUT);
   pinMode(CE2SRAM, OUTPUT);
   digitalWrite(CE1SRAM, LOW);
   digitalWrite(CE2SRAM, HIGH);
-}
+}*/

 void disableVCBus() {
   digitalWrite(WESRAM, HIGH);
-  digitalWrite(OEDATA, LOW);
-  digitalWrite(OEADDRESS, LOW);
+  digitalWrite(OESHIFT, LOW);
   digitalWrite(OEVCBUS, HIGH);
 }

 void enableVCBus() {
   digitalWrite(WESRAM, HIGH);
-  digitalWrite(OEDATA, HIGH);
-  digitalWrite(OEADDRESS, HIGH);
+  digitalWrite(OESHIFT, HIGH);
   digitalWrite(OEVCBUS, LOW);
   delay(100);
   // handover R/W control to VC4000
@@ -106,8 +104,7 @@
 }

 void write2RAM(unsigned int address, byte data) {
-  digitalWrite(OEDATA, LOW);
-  digitalWrite(OEADDRESS, LOW);
+  digitalWrite(OESHIFT, LOW);
   digitalWrite(WESRAM, HIGH);
   shiftout(address, data);
   digitalWrite(WESRAM, LOW);


Updates humidty route

Updates humidty route

Updates the humidty route to return an object instead of an array.

--- njmakerday_20160318/route_humidity.ino
+++ njmakerday_20160318/route_humidity.ino
@@ -3,8 +3,8 @@

 void handleHumidity() {
   String out = "";
-  out += "[{\"currentHumidity\":";
+  out += "{\"humidity\":{\"relative\":";
   out += hdc.readHumidity();
-  out += "}]";
+  out += "}}";
   server.send ( 200, "application/json", out );
 }


minor refactoring

minor refactoring

--- esp-rfid.ino
+++ esp-rfid.ino
@@ -691,8 +691,7 @@
   autoRestartIntervalSeconds = json["auto_restart_interval_seconds"].as<int>();
   wifiTimeout = json["disable_wifi_after_seconds"].as<int>();

-  if (deviceHostname != 0)
-    free(deviceHostname);
+  free(deviceHostname);
   deviceHostname = strdup(l_hostname);

   const char * bssidmac = json["bssid"];


commit

commit

--- watermeter/watermeter.ino
+++ watermeter/watermeter.ino
@@ -229,6 +229,7 @@
             staModeNow = true;
             wmConfig.apMode = false;
             responseNTP = false;
+            ntpReconnectTime = 0;
           }
           break;
         }


logging for a pressed button /BB

logging for a pressed button /BB

--- datasafe.ino
+++ datasafe.ino
@@ -190,7 +190,6 @@
     return;
   }

-
   // actions
   actOnButtonPress(x, y);

@@ -224,12 +223,13 @@
 }

 void actOnButtonPress(uint16_t x, uint16_t y) {
-  Serial.print(x);
-  Serial.print(" / ");
-  Serial.print(y);
-  Serial.println("");
   if (SCREEN_BUTTON_MINY + SCREEN_TEXT_PADDING*2.7 >= y && y <= SCREEN_BUTTON_MINY + SCREEN_TEXT_PADDING*2.7 + SCREEN_BUTTON_SIZE * 2) {
     if (SCREEN_TEXT_PADDING*3 >= x && x <= SCREEN_TEXT_PADDING*3 + SCREEN_BUTTON_SIZE * 2) {
+	  Serial.print("Button pressed: ");
+	  Serial.print(x);
+	  Serial.print(" / ");
+	  Serial.print(y);
+	  Serial.println("");
       reset();
     }
   }


added option to send values. saving to eeprom.

--- sketches/LaundryMeasure/LaundryMeasure.ino
+++ sketches/LaundryMeasure/LaundryMeasure.ino
@@ -5,6 +5,8 @@

 #include <Time.h>
 #include <Timezone.h>
+
+#include <EEPROM.h>

 // Include the UI lib
 #include "OLEDDisplayUi.h"
@@ -64,6 +66,8 @@
 bool NTPupdated = false;
 bool MessageSentBooted = false;

+#define SendValues EEPROM.read(0)==1
+
 // Initialize the OLED display using Wire library
 SSD1306  display(0x3c, D1, D2);
 OLEDDisplayUi ui( &display );
@@ -126,8 +130,28 @@
 }

 void drawFrame3(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
-    display->drawXbm(x + 34, y + 14, checkbox_width, checkbox_height, checkbox_bits);
-    display->drawXbm(x + 34, y + 34, checkedbox_width, checkedbox_height, checkedbox_bits);
+    if(triggeredClick && ((millis()-lastClick)>clickInterval))
+    {
+        triggeredClick = false;
+    }
+    if(!triggeredClick)
+    {
+        if(digitalRead(D5)==0)
+        {
+            EEPROM.write(0,SendValues?0:1);
+            EEPROM.commit();
+            triggeredClick = true;
+            lastClick = millis();
+        }
+    }
+    if(SendValues)
+    {
+        display->drawXbm(x + 34, y + 34, checkedbox_width, checkedbox_height, checkedbox_bits);
+    }
+    else
+    {
+        display->drawXbm(x + 34, y + 14, checkbox_width, checkbox_height, checkbox_bits);
+    }
 }

 String urlencode(String str)
@@ -215,6 +239,9 @@
     Serial.println();
     // put your setup code here, to run once:

+    pinMode(D5, INPUT_PULLUP);
+    EEPROM.begin(4);
+
     // The ESP is capable of rendering 60fps in 80Mhz mode
     // but that won't give you much time for anything else
     // run it in 160Mhz mode or just set it to 30 fps
@@ -298,7 +325,10 @@
         Serial.printf("%d Irms: ", millis());
         Serial.print(rmsValue);
         Serial.println("");
-        sendUDPBroadcast(rmsValue);
+        if(SendValues)
+        {
+            sendUDPBroadcast(rmsValue);
+        }
         rmsLastUpdate = millis();
     }
     int remainingTimeBudget = ui.update();


used #defined constants to specify reverse and turn delays

--- ZumoExamples/examples/BorderDetect/BorderDetect.ino
+++ ZumoExamples/examples/BorderDetect/BorderDetect.ino
@@ -14,7 +14,7 @@
 #define TURN_SPEED        200
 #define FORWARD_SPEED     200
 #define REVERSE_DURATION  200 // ms
-#define TURN_DURATION     400 // ms
+#define TURN_DURATION     300 // ms

 ZumoBuzzer buzzer;
 ZumoMotors motors;
@@ -70,18 +70,18 @@
   {
     // if leftmost sensor detects line, reverse and turn to the right
     motors.setSpeeds(-REVERSE_SPEED, -REVERSE_SPEED);
-    delay(200);
+    delay(REVERSE_DURATION);
     motors.setSpeeds(TURN_SPEED, -TURN_SPEED);
-    delay(300);
+    delay(TURN_DURATION);
     motors.setSpeeds(FORWARD_SPEED, FORWARD_SPEED);
   }
   else if (sensor_values[5] < QTR_THRESHOLD)
   {
     // if rightmost sensor detects line, reverse and turn to the left
     motors.setSpeeds(-REVERSE_SPEED, -REVERSE_SPEED);
-    delay(200);
+    delay(REVERSE_DURATION);
     motors.setSpeeds(-TURN_SPEED, TURN_SPEED);
-    delay(300);
+    delay(TURN_DURATION);
     motors.setSpeeds(FORWARD_SPEED, FORWARD_SPEED);
   }
   else


some initial comment

some initial comment

--- src/motor_control_XYZ/motor_control_XYZ.ino
+++ src/motor_control_XYZ/motor_control_XYZ.ino
@@ -55,7 +55,7 @@
   return (X_factor*value_x + Y_factor*value_y*sign(value_x));
 }

-float compute_Up_Motor_Raw_Speed(float value_Z){
+float compute_Up_Motor_Raw_Speed(float value_z){
   return (Z_factor*value_z);
 }

@@ -113,8 +113,9 @@
 }

 void serialEvent(){
+  //function used to change the pwm motors command when receiving events from serial
   if (Serial.available() > 0) {
-    // read the speed commandqs for each wheel
+    // read the velocity commands for each wheel
     incomingByte_X = Serial.read();
     incomingByte_X= constrain(incomingByte_X, -100,100);
     incomingByte_Y = Serial.read();
@@ -153,9 +154,10 @@
         digitalWrite(motor_up_forward, LOW);
         digitalWrite(motor_up_backward, HIGH);
     }
-    Serial.write(motor_right_pwm);
-    Serial.write(motor_left_pwm);
-    Serial.write(motor_up_pwm);
+    //some debugging info
+    //Serial.write(motor_right_pwm);
+    //Serial.write(motor_left_pwm);
+    //Serial.write(motor_up_pwm);
     Serial.flush();
   }
 }


tuned timing of msp432 remote

tuned timing of msp432 remote

--- VisSynthRemote/VisSynthRemote.ino
+++ VisSynthRemote/VisSynthRemote.ino
@@ -18,7 +18,11 @@
 {
   int j;
   for(j=0;!Serial1.available() && j<ms; j++) delay(1);
-  if(j==ms) return false;
+  if(j==ms)
+  {
+    Serial.print("RedFly Timeout!");
+    return false;
+  }
   else      return true;
 }

@@ -40,24 +44,24 @@
   digitalWrite(redFlyReset,HIGH);
   delay(110);

+//  Serial1.begin(9600);
   Serial1.begin(9600);
-//  Serial1.begin(19200);

   //auto baud rate detection
   for(int i=4; i!=0; i--) //try 4 times
   {
     Serial1.write(0x1C); //transmit 0x1C
-    if(!redFlyTimeout(200)) continue;
+    if(!redFlyTimeout(50)) continue;
     if(Serial1.read() == 0x55) //wait for 0x55
     {
       Serial1.write(0x55); //transmit 0x55
-      redFlyTimeout(100);
+      redFlyTimeout(10);
       redFlyFlush();
       //skip firmware upgrade question at power on
       Serial1.write('n');
       Serial1.write('\n');

-      redFlyTimeout(1000);  // "Loading..."
+      redFlyTimeout(3000);  // "Loading..."
       redFlyFlush();
       redFlyTimeout(2000);  // "Loaded"
       redFlyFlush();
@@ -151,9 +155,9 @@
   digitalWrite(63,LOW);  // CS
   pinMode(62,OUTPUT);
   digitalWrite(62,LOW); // RESET
-  delay(100);
+  delay(10);
   digitalWrite(62,HIGH); // RESET
-  delay(100);
+  delay(10);

   lcd.begin(20, 4);

@@ -172,7 +176,7 @@

-  Serial.begin(9600);
+  Serial.begin(115200);

   lcd.home();
   lcd.print("INIT ");
@@ -270,7 +274,7 @@

 void encoder_callback(int id, int d)
 {
-  redFlySend("AT+RSI_PWMODE=0");
+  // redFlySend("AT+RSI_PWMODE=0");

   String msg="{\"k\":";
   msg+=String(id)+",\"d\":"+String(d)+"}\n";
@@ -280,7 +284,7 @@
   cmd+=msg;

   redFlySend(cmd.c_str());
-  redFlySend("AT+RSI_PWMODE=2");
+  // redFlySend("AT+RSI_PWMODE=2");

   last_tx=millis();
 }
@@ -301,7 +305,7 @@

 void loop() {
-  if(millis()-last_tx>10)
+  if(millis()-last_tx>200)
   {
     enc0.check(encoder_callback);
     enc1.check(encoder_callback);


Update config.ino

Update config.ino

--- Arduino/nodeMCU/plant/config.ino
+++ Arduino/nodeMCU/plant/config.ino
@@ -2,8 +2,8 @@

 // visit io.adafruit.com if you need to create an account,
 // or if you need your Adafruit IO key.
-#define IO_USERNAME    "diomede"
-#define IO_KEY         "30e0f9943a9243768e5c6af82fbbc16a"
+#define IO_USERNAME    "XXXX"
+#define IO_KEY         "XXXX"

 #define MQTT_SERVER "io.adafruit.com"
 #define MQTT_PORT 1883


código com lcd, porem sem funcionamento

código com lcd, porem sem funcionamento

--- communication_firmware/lcd_module_firmware/lcd_module_firmware.ino
+++ communication_firmware/lcd_module_firmware/lcd_module_firmware.ino
@@ -1,9 +1,11 @@
 #include <SPI.h>
 #include "RF24.h"
+#include <Wire.h>
+#include <LiquidCrystal_I2C.h>

 struct DataStruct{
-    int Robot=0;
-    int Message=0;
+    int Robot;
+    int Message;
 };

 DataStruct Report;
@@ -12,21 +14,46 @@
 int CS = 10; //pro micro

 RF24 radio(CE,CS);
+LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
+

 const uint64_t Channels[4] = { 0xABCDABCD71LL, 0x544d52687CLL , 0x644d52687CLL, 0x744d52687CLL};
 uint64_t ChannelEnvia = Channels[0];
-uint64_t ChannelRecebe = Channel[3];
+uint64_t ChannelRecebe = Channels[3];

 void setup() {
   // put your setup code here, to run once:
+  Serial.begin (9600);
   RadioSetup();
+  Report.Robot = 1;
+  Report.Message = 1;
+  lcd.begin(16,2);
+  lcd.setBacklight (HIGH);

 }

 void loop() {
   // put your main code here, to run repeatedly:
-  ReceiveReport(&Report);
-
+  //ReceiveReport();
+  Serial.println(Report.Robot);
+  if (Report.Robot == 0){
+    lcd.setCursor (5,0);
+    lcd.print ("UNBALL");
+  }
+  if (Report.Robot == 1){
+    lcd.setCursor (5,0);
+    lcd.print ("ROBOT 0");
+  }
+  if (Report.Robot == 2){
+    lcd.setCursor (5,0);
+    lcd.print ("ROBOT 1");
+  }
+  if (Report.Robot == 3){
+    lcd.setCursor (5,0);
+    lcd.print ("ROBOT 2");
+  }
+ // lcd_print (Report.Robot, Report.Message);
+ delay(1000);
 }

 void RadioSetup(){
@@ -45,14 +72,31 @@
     radio.startListening();                 // Start listening
 }

-void ReceiveReport(DataStruct *data){       //Function to receive data
+void ReceiveReport(){       //Function to receive data
   if(radio.available()){
-    radio.read(data, sizeof(DataStruct));
+    radio.read(&Report, sizeof(DataStruct));
   }
 }
+
+/*void lcd_print (int a, int b){
+  if (Report.Robot == 0){
+    lcd.setCursor (5,0);
+    lcd.print ("UNBALL");
+  }
+  if (Report.Robot == 1){
+    lcd.setCursor (5,0);
+    lcd.print ("ROBOT 0");
+  }
+  if (a == 2){
+    lcd.setCursor (5,0);
+    lcd.print ("ROBOT 1");
+  }
+   if (a == 3){
+    lcd.setCursor (5,0);
+    lcd.print ("ROBOT 2");
+  }
+}*/

-
-


tidyup

tidyup


Cleanup and improved uptime printout.

Cleanup and improved uptime printout.

--- examples/Ethernet/CosaWebServer/CosaWebServer.ino
+++ examples/Ethernet/CosaWebServer/CosaWebServer.ino
@@ -82,6 +82,12 @@
   // Wait for incoming connection requests
   while (sock->accept() != 0) Watchdog::delay(32);

+  // Uptime in seconds
+  uint32_t uptime =  Watchdog::millis() / 1000;
+  uint16_t h = uptime / 3600;
+  uint8_t m = (uptime / 60) % 60;
+  uint8_t s = uptime % 60;
+
   // Bind the socket to an iostream
   IOStream page(sock);
   uint8_t mac[6];
@@ -90,16 +96,16 @@
   uint16_t port;
   int res;

-  // Get connection information
-  sock->get_dest(mac, ip, port);
+  // Get client connection information; MAC, IP address and port
+  sock->get_src(mac, ip, port);

   // Wait for the HTTP request
   while ((res = sock->available()) == 0);
   if (res < 0) goto error;
   TRACE(sock->available());

+#ifndef NDEBUG
   // Read request and print in debug mode. Ignore contents
-#ifndef NDEBUG
   trace << PSTR("Request#") << nr << endl;
   while ((res = sock->recv(buf, sizeof(buf) - 1)) > 0) {
     buf[res] = 0;
@@ -133,7 +139,7 @@
   page << PSTR("Vcc (mV): ") << AnalogPin::bandgap() << BR;
   page << PSTR("Memory (byte): ") << free_memory();
   page << PSTR("(") << setup_free_memory << PSTR(")") << BR;
-  page << PSTR("Uptime (s): ") << Watchdog::millis() / 1000 << BR;
+  page << PSTR("Uptime (h:m:s): ") << h << ':' << m << ':' << s << BR;
   page << PSTR("Requests: ") << nr++ << BR;
   page << PSTR("MAC: ") << mac[0];
   for (uint8_t i = 1; i < 6; i++) page << PSTR(".") << mac[i];


Revert "Give the xbee a bit more time to reconnect."

This reverts commit e0897c24a514b9d63e6364a3e507a3ffb138cb12.

--- arduino/monitor/monitor.ino
+++ arduino/monitor/monitor.ino
@@ -82,7 +82,7 @@

   // wake radio
   digitalWrite(DIO_XBEE_SLEEP, LOW);
-  delay(200);
+  delay(100);

   // send message
   sendWeatherUpdate(xbeeSerial);


droplets

droplets

--- steinstein/steinstein.ino
+++ steinstein/steinstein.ino
@@ -4,12 +4,14 @@
 #define LED_TYPE WS2812B      // Don't forget to change LEDS.addLeds
 #define DOTS_PER_LOOP 8
 #define DISTANCE_BETWEEN_DOTS 200
-#define DISTANCE_BETWEEN_LOOPS 100
-#define MAX_EFFECTIVE_DISTANCE_SQUARED 400 * 400
+#define DISTANCE_BETWEEN_LOOPS 200
+#define MAX_EFFECTIVE_DISTANCE_SQUARED 300 * 300
 #define NUM_LEDS 1500
+#define MAX_DELTA 16
+#define MAX_BRIGHTNESS 48
+#define MIN_BRIGHTNESS 2
+#define MAX_DROPS 6
 struct CRGB leds[NUM_LEDS];   // Initialize our LED array.
-
-struct CRGB last[NUM_LEDS];
 struct CRGB stein_next[NUM_LEDS];

@@ -22,65 +24,72 @@
   randomSeed(analogRead(0));

   for (int i = 0; i < NUM_LEDS; i++) {
-    last[i] = CRGB(0, 0, 0);
+    leds[i] = CRGB(0, 0, 0);
   }
 }

 int counter;
-
+int GAIN_NUM [3] = {10, 10, 10};
+
 void loop() {
-
   counter++;
-  int GAIN_NUM [3] = { random(6) + 9, random(6) + 9, random(6) + 9 };
-
+  if (counter % 5 == 0){
+    int hue_target = random(270);
+    for (int rgb_idx = 0; rgb_idx < 3; rgb_idx++)
+       GAIN_NUM[rgb_idx] = 8 + ((hue_target + 90 * rgb_idx) % 270) / 58;
+//    int gain_seed = random(6);
+//    for (int rgb_idx = 0; rgb_idx < 3; rgb_idx++)
+//       GAIN_NUM[rgb_idx] = 8 + gain_seed;
+  }
   for (int i = 0; i < NUM_LEDS; i++) {
-    stein_next[i] = CRGB(last[i].red, last[i].g, last[i].b);
+    stein_next[i] = CRGB(leds[i].red, leds[i].g, leds[i].b);
   }

   for (int pixel_k=0; pixel_k<NUM_LEDS; pixel_k++){
-    int pixel_ks_next_step [3] = { last[pixel_k][0], last[pixel_k][1], last[pixel_k][2] };
+    int pixel_ks_next_step [3] = { leds[pixel_k].r, leds[pixel_k].g, leds[pixel_k].b };
+    int pixel_ks_last_step [3] = { leds[pixel_k].r, leds[pixel_k].g, leds[pixel_k].b };
     int pixel_ks_weight = 0;
     for (int pixel_m=max(pixel_k-10, 0); pixel_m<min(pixel_k+10, NUM_LEDS); pixel_m++){
       // how far apart are k and m?
-      int x_distance = (DISTANCE_BETWEEN_DOTS * (abs(pixel_k-pixel_m) % DOTS_PER_LOOP));
-      int y_distance = (DISTANCE_BETWEEN_LOOPS * (floor(abs(pixel_k-pixel_m) / DOTS_PER_LOOP)));
+      int x_distance = (DISTANCE_BETWEEN_DOTS * (max(pixel_k-pixel_m, pixel_m-pixel_k) % DOTS_PER_LOOP));
+      int y_distance = (DISTANCE_BETWEEN_LOOPS * (max(pixel_k-pixel_m, pixel_m-pixel_k) / DOTS_PER_LOOP));
       int distance_squared = x_distance * x_distance + y_distance * y_distance;
       // are they close?
       if (distance_squared < MAX_EFFECTIVE_DISTANCE_SQUARED && pixel_k != pixel_m){
         // this pixel changes my next value
-        int pixel_m_color [3] = { last[pixel_m][0], last[pixel_m][1], last[pixel_m][2] };
-        for (int rgb_idx = 0; rgb_idx < 3; rgb_idx++)
+        int pixel_m_color [3] = { leds[pixel_m].r, leds[pixel_m].g, leds[pixel_m].b };
+        for (int rgb_idx = 0; rgb_idx < 3; rgb_idx++){
           pixel_ks_next_step[rgb_idx] = GAIN_NUM[rgb_idx] * (pixel_ks_weight * pixel_ks_next_step[rgb_idx] + distance_squared * pixel_m_color[rgb_idx]) / (10 * (pixel_ks_weight + distance_squared));
+        }
         pixel_ks_weight += distance_squared;
       }
     }
-    for (int rgb_idx = 0; rgb_idx < 3; rgb_idx++)
-      stein_next[pixel_k][rgb_idx] = pixel_ks_next_step[rgb_idx];
-  }
-
-  for (int k = DOTS_PER_LOOP+1; k<NUM_LEDS; k++){
-    last[k] = stein_next[k];
-    if (random(10000) > 9995){
-      last[k-DOTS_PER_LOOP-1] = CRGB(random(255), random(255), random(255));
-      last[k-DOTS_PER_LOOP] = CRGB(random(255), random(255), random(255));
-      last[k-1] = CRGB(random(255), random(255), random(255));
-      last[k] = CRGB(random(255), random(255), random(255));
-    }
-    if (random(255) > 230){
-      for (int rgb_idx = 0; rgb_idx < 3; rgb_idx++){
-        last[k-DOTS_PER_LOOP-1][rgb_idx] = 0;
-        last[k-DOTS_PER_LOOP][rgb_idx] = 0;
-        last[k-1][rgb_idx] = 0;
-        last[k][rgb_idx] = 0;
+    for (int rgb_idx = 0; rgb_idx < 3; rgb_idx++){
+      if (pixel_ks_last_step[rgb_idx] - pixel_ks_next_step[rgb_idx] > MAX_DELTA){
+        stein_next[pixel_k][rgb_idx] = pixel_ks_last_step[rgb_idx] - MAX_DELTA;
+      } else if (pixel_ks_last_step[rgb_idx] - pixel_ks_next_step[rgb_idx] < 0-MAX_DELTA) {
+        stein_next[pixel_k][rgb_idx] = pixel_ks_last_step[rgb_idx] + MAX_DELTA;
+      } else {
+        stein_next[pixel_k][rgb_idx] = pixel_ks_next_step[rgb_idx];
       }
+      stein_next[pixel_k][rgb_idx] = max(MIN_BRIGHTNESS, min(stein_next[pixel_k][rgb_idx], MAX_BRIGHTNESS));
     }
   }

-  for (int i = 0; i < NUM_LEDS; i++) {
-    leds[i] = CRGB(min(last[i][0], 64), min(last[i][1], 64), min(last[i][2], 64));
+  for (int k = 0; k<NUM_LEDS; k++){
+    leds[k] = stein_next[k];
+  }
+  for (int i = 0; i<random(MAX_DROPS); i++){
+    int k = random(NUM_LEDS);
+    if (k > DOTS_PER_LOOP + 1)
+      leds[k-DOTS_PER_LOOP-1] = CRGB(random(MAX_BRIGHTNESS), random(MAX_BRIGHTNESS), random(MAX_BRIGHTNESS));
+    if (k > DOTS_PER_LOOP)
+      leds[k-DOTS_PER_LOOP] = CRGB(random(MAX_BRIGHTNESS), random(MAX_BRIGHTNESS), random(MAX_BRIGHTNESS));
+    if (k > 1)
+      leds[k-1] = CRGB(random(MAX_BRIGHTNESS), random(MAX_BRIGHTNESS), random(MAX_BRIGHTNESS));
+    leds[k] = CRGB(random(MAX_BRIGHTNESS), random(MAX_BRIGHTNESS), random(MAX_BRIGHTNESS));
   }

-    show_at_max_brightness_for_power();
-//      set_leds(dither(0, 64, 4, stein_next));
+  show_at_max_brightness_for_power();
 }


test function added. It outputs stuff :)

--- system_monitor/system_monitor.ino
+++ system_monitor/system_monitor.ino
@@ -23,7 +23,7 @@
 #define GREEN_LED_PIN 4

 // Global variable containing the current filename
-char filename[25] = "Poop.csv";
+char *filename = malloc(NAME_LENGTH);

 const char NUM_SOURCES = 4; //number of voltage/current sources
 // System Order: Batt, Solar, Hydro, Load
@@ -51,52 +51,67 @@
 // the logging file
 File TGC_logfile;

-void readVoltage(float *voltages[]){
-    #if TEST
-    for(int i=0; i++; i<NUM_SOURCES){
-        *voltages[i] = 13.8+i;
-    }
-        return;
-    #endif
-
-    for(int i=0; i++; i<NUM_SOURCES){
-        *voltages[i] =  analogRead(VOLT_PIN[i]) * VOLT_MULTI[i];
-    }
-    return;
+float* readVoltage(){
+    static float voltages[4] = {0, 1, 0, 0};
+    #if TEST
+        Serial.println("readVoltage");
+        for(int i=0; i<NUM_SOURCES; i++){
+            voltages[i] = 13.8+i;
+        }
+        //return voltages;
+    #endif
+
+    for(int i=0; i<NUM_SOURCES; i++){
+        voltages[i] =  analogRead(VOLT_PIN[i]) * VOLT_MULTI[i];
+    }
+    return voltages;
 }//readVoltage

-void readAmp(float *amps[]){
-    #if TEST
-    for(int i=0; i++; i<NUM_SOURCES){
-        *amps[i] = 5.4+i;
-    }
-        return;
-    #endif
-
-    for(int i=0; i++; i<NUM_SOURCES){
-        *amps[i] =  analogRead(AMP_PIN[i]) * AMP_MULTI[i];
-    }
-    return;
+float* readAmp(){
+    static float amps[4] = {0,0,0,0};
+    #if TEST
+        Serial.println("readAmp");
+        for(int i=0; i<NUM_SOURCES; i++){
+            amps[i] = 5.4+i;
+        }
+        //return amps;
+    #endif
+
+    for(int i=0; i<NUM_SOURCES; i++){
+        amps[i] =  analogRead(AMP_PIN[i]) * AMP_MULTI[i];
+    }
+    return amps;
 }//readAmp

-void readTemp(float *temps[]){
-    #if TEST
-    for(int i=0; i++; i<NUM_SOURCES){
-        *temps[i] = 20.3+i;
-    }
-        return;
-    #endif
-
-    for(int i=0; i++; i<NUM_TEMPS){
+float* readTemp(){
+    static float temps[3] = {0,0,0};
+    #if TEST
+        Serial.println("readTemp");
+        for(int i=0; i<NUM_SOURCES; i++){
+            temps[i] = 20.3+i;
+        }
+        return temps;
+    #endif
+
+    for(int i=0; i<NUM_TEMPS; i++){
         //do something
     }
-    return;
+    return temps;
 }//readTemp

-char readTime(){
-    // TO DO
-    return "2017_09_30-12-43-33";
-}
+char* readTime(){
+    // TO DO
+    static char *time;
+    #if TEST
+        Serial.println("readTime");
+    #endif
+        int randNumber = random(10);
+        time = "2017_09_30-12-43-3";
+
+        //strcat(time, str(randNumber));
+
+    return time;
+}//readTime

 int writeSD(float volt[], float amp[], float temp[], char time[], float power){
     // TO DO
@@ -111,9 +126,17 @@

 void newFile(){

-    char newName[] = "SHIT";
-    strcat(newName, ".csv");
+    char *temp = (char*)malloc(sizeof(char)*NAME_LENGTH);
+
+    memcpy(temp, readTime(), sizeof(char)*NAME_LENGTH);
+
+    strcat(temp, ".csv");
+    filename = temp;
+#if TEST
+    return;
+#endif

+    /*
     TGC_logfile.close();
     TGC_logfile = SD.open(newName, FILE_WRITE);

@@ -122,6 +145,7 @@
         TGC_logfile.print("Created: ");
         TGC_logfile.println(newName);
     }
+    */
 }

 void standby(){
@@ -130,16 +154,57 @@
     float ampReadings[4];
     float tempReadings[3];

-    readVoltage(voltReadings[]);
+    //readVoltage(voltReadings);

 }//standby

+void error(char mess[]){
+    // TO DO
+    Serial.print("Shit");
+}//error
+
+void printArray(float array[], int arraySize){
+    for(int i=0; i<arraySize; i++){
+        Serial.println(array[i]);
+    }
+}
+
+void test(){
+
+    float *voltages, *amps, *temps;
+    char *time;
+    voltages = readVoltage();
+    amps = readAmp();
+    temps = readTemp();
+    time = readTime();
+    printArray(voltages, 4);
+    printArray(amps, 4);
+    printArray(temps, 3);
+    Serial.println(time);
+    int timeAdd = time;
+    Serial.println(timeAdd);
+    Serial.println(filename);
+    int fileAdd = filename;
+    Serial.println(fileAdd);
+    newFile();
+    Serial.println(filename);
+    fileAdd = filename;
+    Serial.println(fileAdd);
+    delay(1000);
+
+    return;
+}
+
 void setup() {

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

+    pinMode(RED_LED_PIN, OUTPUT);
+    pinMode(GREEN_LED_PIN, OUTPUT);
+
+#if !(TEST)
     // initialize the SD card
     Serial.print("Initializing SD card...");
     // make sure that the default chip select pin is set to
@@ -152,19 +217,16 @@
     }
     Serial.println("card initialized.");

+
+
     // create a new file
-    char filename[] = "LOGGER00.CSV";
-    for (uint8_t i = 0; i < 100; i++) {
-        filename[6] = i/10 + '0';
-        filename[7] = i%10 + '0';
-        if (! SD.exists(filename)) {
-            // only open a new file if it doesn't exist
-            logfile = SD.open(filename, FILE_WRITE);
-            break;  // leave the loop!
-        }
-    }
-
-    if (! logfile) {
+    if (! SD.exists(filename)) {
+        // only open a new file if it doesn't exist
+        TGC_logfile = SD.open(filename, FILE_WRITE);
+    }
+
+
+    if (! TGC_logfile) {
         error("couldnt create file");
     }

@@ -174,12 +236,14 @@
     // connect to RTC
     Wire.begin();
     if (!RTC.begin()) {
-        logfile.println("RTC failed");
+        TGC_logfile.println("RTC failed");
     Serial.println("RTC failed");
     }
+#endif

 }//setup

 void loop() {
     // TO DO
-}
+    test();
+}


major lounge update

major lounge update

--- proj/ledvo_lounge_final/Animation_Base.ino
+++ proj/ledvo_lounge_final/Animation_Base.ino
@@ -92,7 +92,7 @@
   // Fill everything with white at a user controlled rate, then fade to black to
   // get the strobe effect that we want
   EVERY_N_MILLISECONDS_I(thisTimer, 200) {
-    thisTimer.setPeriod(map(analogRead(DJ_POT), 0, 1023, 50, 800));
+    thisTimer.setPeriod(map(analogRead(DJ_POT), 0, 1023, 50, 1000));
     fill_solid(ih_leds, ih_LED_total, CHSV(255, 0, map(analogRead(VAL_POT), 0, 1023, maxBrightness - 40, maxBrightness)));
     fill_solid(oh_leds, oh_LED_total, CHSV(255, 0, map(analogRead(VAL_POT), 0, 1023, maxBrightness - 40, maxBrightness)));
     for (uint8_t dd = 0; dd < 3; dd++) {
@@ -109,10 +109,10 @@
 // animation but rather another layer.
 void strobe_black() {
   EVERY_N_MILLISECONDS_I(thisTimer, 175) {
-    thisTimer.setPeriod(map(analogRead(DJ_POT), 0, 1023, 20, 800));
+    thisTimer.setPeriod(map(analogRead(DJ_POT), 0, 1023, 10, 1000));
     reset_all();
     FastLED.show();
-    FastLED.delay(20);
+    FastLED.delay(10);
   }
 }

@@ -130,13 +130,13 @@
 // A theater chase where packets switch direction every once in a while. Lets see how
 // this looks with a saw wave
 void theater_chase_tri(CRGB *leds, uint16_t numLED, uint8_t pal_index) {
-  fill_palette(leds, numLED, triwave(pal_index), 4, gPalette, maxBrightness, gBlending);
+  fill_palette(leds, numLED, triwave(pal_index), 4, gPalette, gBrightness, gBlending);
 }

 // A glitchy style "chase". It not even really a chase, I just keep the palette static and
 // change the width of the packets. Looks kind of funky, but kind of cool too.
 void theater_chase_mod(CRGB *leds, uint16_t numLED, uint8_t col_inc) {
-  fill_palette(leds, numLED, 0, col_inc, gPalette, maxBrightness, gBlending);
+  fill_palette(leds, numLED, 0, col_inc, gPalette, gBrightness, gBlending);
 }

 // Fill the whole strip from left to right, then empty from left to right.


debug led enabled

debug led enabled

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -11,6 +11,8 @@
   Serial.begin(9600);
   // set the input pin
   pinMode(pinNumber, INPUT);
+  // initialize the LED pin as an output:
+  pinMode(led, OUTPUT);
 }

 void loop()
@@ -20,10 +22,14 @@
   // if it has not been clicked yet and it's down we can send the message
   if (tmpButtonState == HIGH && buttonClicked == false) {
     Serial.print("ciao");
+    digitalWrite(led, HIGH);
     buttonClicked = true;
     delay(500); // wait 500 ms before sending the next message
-  }
+  } else {
+    // just for debugging
+    digitalWrite(led, LOW);
+  }
   // if the button is not pressed anymore we reset the buttonClicked variable to false
   if (tmpButtonState == LOW)
     buttonClicked = false;
-}+}


fget impl

fget impl

--- indoor-firm/indoor-firm.ino
+++ indoor-firm/indoor-firm.ino
@@ -45,7 +45,6 @@

 String fget(String msg, char* f)
 {
-    //String s = msg.substring(1, s.length() - 2);// remove '(' and ')' from string begin/end
     String s = msg;
     char* p = strstr(s.c_str(), f);
     if (p) {
@@ -63,9 +62,17 @@

     String s(msg);

-    String val = fget(s, "msg");
+   //String val = fget(s, "msg");
+    //lcd.setCursor(0,0);
+    //lcd.print(val);
+
+    String sP = fget(s, "P");
     lcd.setCursor(0,0);
-    lcd.print(val);
+    lcd.print(sP);
+
+    String sTp = fget(s, "Tp");
+    lcd.setCursor(0,1);
+    lcd.print(sTp);
 }

 void loop()


Update tippingbucket.ino

Update tippingbucket.ino

--- Arduino/tippingbucket/tippingbucket.ino
+++ Arduino/tippingbucket/tippingbucket.ino
@@ -7,28 +7,20 @@
  ***************************/

 const int  switchPin = 2;    // the pin that the reed switch is attached to
-const float  mmpertip = 0.59;   // the amount of mm of rain per bucket tip, this number depends on how the system is calibrated
-

 // Variables will change:
 int tipCounter = 0;   // counter for the number of bucket tips
 int switchState = 0;         // current state of the switch
 int lastSwitchState = 0;     // previous state of the switch

-
 void setup() {
   // initialize the button pin as a input:
   pinMode(switchPin, INPUT);
 }

-
-
-
 void loop() {
   // read the switch input pin:
   switchState = digitalRead(switchPin);
-
-
   // compare the buttonState to its previous state
   if (switchState != lastSwitchState) {
     // if the state has changed, increment the counter
@@ -43,7 +35,4 @@
   // save the current state as the last state,
   //for next time through the loop
   lastSwitchState = switchState;
-
-
 }
-


Cleans inos.

Cleans inos.

--- tanduino/tanduino.ino
+++ tanduino/tanduino.ino
@@ -16,8 +16,6 @@
  *  - analyse drawn current
  */

-#include <avr/sleep.h>
-#include <avr/power.h>
 #include <SPI.h>
 #include <Wire.h>
 #include <Adafruit_Sensor.h>
@@ -28,59 +26,59 @@
 #include "structures.h"

 // Debug options
-#define VERBOSE_MODE          0               // Echo data to serial port: 0: none, 1 basic info, 2 detailed info, 3 extended info
-#define WAIT_TO_START         0               // Wait for serial input in setup()
+#define VERBOSE_MODE                  0               // Echo data to serial port: 0: none, 1 basic info, 2 detailed info, 3 extended info
+#define WAIT_TO_START                 0               // Wait for serial input in setup()

 // General
-#define MILLISEC              1000L
-#define SEC                   1L
-#define MINUTE                (unsigned int)60L*SEC
-#define HOUR                  (unsigned int)60L*MINUTE
-#define DAY                   (unsigned long)24L*HOUR
+#define MILLISEC                      1000L
+#define SEC                           1L
+#define MINUTE                        (unsigned int)60L*SEC
+#define HOUR                          (unsigned int)60L*MINUTE
+#define DAY                           (unsigned long)24L*HOUR

 // Error codes
-#define ERROR_ADXL345_INIT    1
-#define ERROR_HMC5883_INIT    2
-const char PROGMEM                            //Remember to update the buffer when adding a larger string [7]
-  errmsg_0[] =                "",             //SPARE
-  errmsg_1[] =                "Ac err",       //Accelerometer init error
-  errmsg_2[] =                "Co err";       //Compass init error
-const char* const PROGMEM
-  ERROR_MESSAGES[] =          {errmsg_0, errmsg_1, errmsg_2};
+#define ERROR_ADXL345_INIT            1
+#define ERROR_HMC5883_INIT            2
+const char PROGMEM                                    //Remember to update the buffer when adding a larger string [7]
+  errmsg_0[] =                        "",             //SPARE
+  errmsg_1[] =                        "Ac err",       //Accelerometer init error
+  errmsg_2[] =                        "Co err";       //Compass init error
+const char* const PROGMEM
+  ERROR_MESSAGES[] =                  {errmsg_0, errmsg_1, errmsg_2};

-// Pins
-#define REF_3V3               A0              // 3.3V reference sampling
-#define BATT_OUT              A1              // Battery voltage
-#define BUTTON_PIN            2               // Interrupt pin
-#define LASER_PIN             7               // Laser pointer
-#define PCD8544_DC_PIN        8               // LCD Data/Command select
-#define PCD8544_RST_PIN       9               // LCD Reset
-#define PCD8544_CE_PIN        10              // LCD Chip Select
+// Pins
+#define REF_3V3                       A0              // 3.3V reference sampling
+#define BATT_OUT                      A1              // Battery voltage
+#define BUTTON_PIN                    2               // Interrupt pin
+#define LASER_PIN                     7               // Laser pointer
+#define PCD8544_DC_PIN                8               // LCD Data/Command select
+#define PCD8544_RST_PIN               9               // LCD Reset
+#define PCD8544_CE_PIN                10              // LCD Chip Select

-// Sensors settings
-#define ADXL345               1               // Accelerometer's ID
-#define HMC5883               2               // Compass's ID
-#define ALPHA                 0.5             // Low Pass Filter constant
-#define READ_SAMPLES          8.0             // Number of samples to compute reading average
+// Sensors settings
+#define ADXL345                       1               // Accelerometer's ID
+#define HMC5883                       2               // Compass's ID
+#define ALPHA                         0.5             // Low Pass Filter constant
+#define READ_SAMPLES                  8.0             // Number of samples to compute reading average

-// Battery settings
-#define BATT_MIN              9.0             // Maximum voltage delivered by the battery (volts)
-#define BATT_MAX              8.0             // Maximum voltage delivered by the battery (volts)
-#define BATT_REFRESH_RATE     5*SEC           // how often battery measurement is refreshed (seconds)
+// Battery settings
+#define BATT_MIN                      9.0             // Maximum voltage delivered by the battery (volts)
+#define BATT_MAX                      8.0             // Maximum voltage delivered by the battery (volts)
+#define BATT_REFRESH_RATE             5*SEC           // how often battery measurement is refreshed (seconds)

-// Button settings
-#define DEBOUNCE_DELAY        200             // Delay during which we ignore the button actions (milliseconds)
+// Button settings
+#define DEBOUNCE_DELAY                200             // Delay during which we ignore the button actions (milliseconds)

-// Display settings
-#define PCD8544_TEXT_WRAP     0               // (true, false) wrap the text
-#define PCD8544_CONTRAST      0x31            // LCD Contrast value (0x00 to 0x7F) (the higher the value, the higher the contrast)
-#define PCD8544_BIAS          0x13            // LCD Bias mode for MUX rate (0x10 to 0x17) (optimum: 0x13, 1:48)
-#define PCD8544_SPI_CLOCK_DIV SPI_CLOCK_DIV2  // Max SPI clock speed for PCD8544 of 2mhz (8mhz / 4)
-#define PCD8544_REFRESH_RATE  0.175*SEC       // how often display is refreshed (seconds)
-#define PCD8544_FLIP          0               // (true, false) flip vertically the display
+// Display settings
+#define PCD8544_CONTRAST              0x31            // LCD Contrast value (0x00 to 0x7F) (the higher the value, the higher the contrast)
+#define PCD8544_BIAS                  0x13            // LCD Bias mode for MUX rate (0x10 to 0x17) (optimum: 0x13, 1:48)
+#define PCD8544_SPI_CLOCK_DIV         SPI_CLOCK_DIV2  // Max SPI clock speed for PCD8544 of 2mhz (8mhz / 4)
+#define PCD8544_REFRESH_RATE          0.175*SEC       // how often display is refreshed (seconds)
+#define PCD8544_TEXT_WRAP             0               // (true, false) wrap the text
+#define PCD8544_FLIP                  0               // (true, false) flip vertically the display

-// Device settings
-#define REVISION_NR           F("1.0")        // Revision # of the design
+// Device settings
+#define REVISION_NR                   F("1.0")        // Revision # of the design

 // Global variables
 Adafruit_PCD8544 _PCD8544 =           Adafruit_PCD8544(PCD8544_DC_PIN, PCD8544_CE_PIN, PCD8544_RST_PIN);
@@ -89,7 +87,7 @@
 static unsigned long
   _timer =                            -PCD8544_REFRESH_RATE*MILLISEC,
   _battTimer =                        -BATT_REFRESH_RATE*MILLISEC;
-int _batt = 0;
+int _batt =                           0;
 V
   _y_ADXL345 =                        {0, 0, 0, 0, 0, 0, 0},
   _y_HMC5883 =                        {0, 0, 0, 0, 0, 0, 0};


added  HTTP API condition

added  HTTP API condition

--- T0/src/AFE-Firmware-T0.ino
+++ T0/src/AFE-Firmware-T0.ino
@@ -104,8 +104,10 @@
         WebServer.listener();

         /* Checking if there was received HTTP API Command */
-        if (WebServer.httpAPIlistener()) {
-          processHTTPAPIRequest(WebServer.getHTTPCommand());
+        if (Device.isHttpAPITurnedOn()) {
+          if (WebServer.httpAPIlistener()) {
+            processHTTPAPIRequest(WebServer.getHTTPCommand());
+          }
         }

         /* Relay turn off event launched */


latest checkin

latest checkin

--- OxFloodNet_Sensor/OxFloodNet_Sensor.ino
+++ OxFloodNet_Sensor/OxFloodNet_Sensor.ino
@@ -1,14 +1,13 @@
 /**
- * LLAPDistance_Remote sketch for Ciseco RFu-328 and Maxbotix XL-EZ3 ultrasonic sensor
- * Availabe form http://www.coolcomponents.co.uk/ultrasonic-range-finder-xl-ez3.html
+ * LLAPDistance_Remote sketch for Ciseco RFu-328 and Maxbotix MB7060 XL-MaxSonar-WR1, Standard edition ultrasonic sensor
  *
- * Transmits reading every 5 minutes
+ * Transmits reading every 30s, 5, 10 or 15 minutes depending on jumpers. Default is 10 minutes
  * Data transmitted is of form aXXUnnn-----
  * Battery readings every 10th cycle  aXXBvvvv----
  *
  * Where XX is the device ID, nnn is the distance to the water in cm, vvvv is battery voltage in mV
  * Other messages sent are: aXXSTARTED upon startup
- * aXXUMax----- and aXXUErr----- if max range is reached or an error in the reading is seen.
+ * aXXUMax----- and aXXUErr----- if max range is reached or an error in the reading is seen, i.e. too close.
  *
  * Sensor is controled using a single N-Channel MOSFET, Gate to SENSOR_ENABLE,
  * Source to GND, Drain to -ve of sensor, Sensor +ve to +3V.
@@ -21,7 +20,7 @@
 #include <OneWire.h>
 #include <DallasTemperature.h>

-#define VERSION_STRING "V0.8"
+#define VERSION_STRING "V0.9"

 // Number of readings before a battery reading is taken
 #define BATTERY_READ_INTERVAL 10
@@ -55,13 +54,14 @@
 float latestTemperature = 0.0;
 uint16_t lastUncompDistance = 0;

+// Define pins that are not used and are to be made inputs
 uint8_t inPin[] = { 9, 10, 11, 12, 13 };

 int batteryCountDown = BATTERY_READ_INTERVAL;

 uint8_t enterCommandMode();
 // Node ID, default R0, set by input pins
-// Stricly speaking this should only be digits
+// Stricly speaking this should only be digits, according to the Ciseco LLAP spec.
 char nodeId[2] = { 'R', '1' };

 // Some functions to get the configured node address
@@ -156,7 +156,8 @@
   }
 }

-// Get the rance in cm. Need to enable sensor first then wait briefly for it to power up
+// Get the range in cm. Need to enable sensor first then wait briefly for it to power up
+// Also request temperture sensor, if previously detected, to take a reading.
 // Disable sensor after use.
 uint16_t getRange() {
   int16_t pulse;  // number of pulses from sensor
@@ -169,13 +170,10 @@
     0, 0, 0, 0, 0, 0, 0, 0, 0 };

   float temperature = 0.0;
-
-//  digitalWrite(TEMP_SENSOR_ENABLE, HIGH);
   digitalWrite(SENSOR_ENABLE, HIGH);
   delay(50);

-  while( i < arraysize )
-  {
+  while( i < arraysize ) {
     pulse = pulseIn(SENSOR_PIN, HIGH);  // read in time for pin to transition
     if( pulse == 0 ) return 0;
     rangevalue[i]=pulse/58;         // pulses to centimeters (use 147 for inches)
@@ -203,8 +201,6 @@
     uint16_t newDist = tof * (( 20.05 * sqrt( temperature + 273.15))/2);
     distance = newDist;
   }
-//  digitalWrite(TEMP_SENSOR_ENABLE, LOW);
-
   return distance;
 }

@@ -247,6 +243,8 @@
   {
     if (!enterCommandMode()) return 1;
   }
+  // Use D9 & D10 links to determine polling interval
+  // TODO
   //if (!sendCommand("ATSDDBBA0")) return 2;	// 15 minutes
   //if (!sendCommand("ATSD927C0")) return 2;	// 10 minutes
   if (!sendCommand("ATSD493E0")) return 2;	// 5 minutes


SR latch working proper now.

SR latch working proper now.

--- sketches/SRLatch/SRLatch.ino
+++ sketches/SRLatch/SRLatch.ino
@@ -1,91 +1,124 @@
 /*
  * /SR latch sketch.
+ *
+ * An /SR latch is active low; therefore, a 1 is represented by a LOW state,
+ * while a 0 is represented by a HIGH state. The /Q pin becomes, in essence,
+ * an active high output, and therefore can be used directly to set the LED
+ * indicating the current bit in memory.
+ *
+ * Output state table:
+ * +====+====+====+
+ * | /S | /R |  Q |
+ * +====+====+====+
+ * | 0  | 0  | -  | <- This combination is not permitted.
+ * +----+----+----+
+ * | 0  | 1  | 1  |
+ * +----+----+----+
+ * | 1  | 0  | 0  |
+ * +----+----+----+
+ * | 1  | 1  | NC | <- Q remains unchanged.
+ * +----+----+----+
  */

-const int s_pin = 8;
-const int r_pin = 9;
-const int q_pin = 10;
-const int qq_pin = 11;
-const int set_led = 2;
-const int data_led = 3;
-const int out_led = 13;
+const int s_pin = 8;     // Input for /S.
+const int r_pin = 9;     // Input for /R.
+const int q_pin = 10;    // Q output. Active-low.
+const int qq_pin = 11;   // /Q -- active-high translation.
+const int s_led = 2;     // LED indicator for current /S status.
+const int r_led = 3;     // LED indicator for current /R status.
+const int out_led = 13;  // LED indicator for current bit in memory (on
+// indicates 1, off indicates 0).

+/*
+ * An active low system represents 0 as the higher voltage, and 1 as the lower
+ * voltage. Therefore, we define an A(ctive)L(ow)0 as HIGH, and AL1 as LOW.
+ */
+#define AL0  HIGH
+#define AL1 LOW
+
+/*
+ * Set stores a 1 in the the latch.
+ */
 void
 set(void)
 {
-  int out;
-
-  Serial.println("/S->0, /R->1");
-  Serial.println("    (/Q should be 1)");
-  digitalWrite(s_pin, LOW);
-  digitalWrite(set_led, LOW);
-  digitalWrite(r_pin, HIGH);
-  digitalWrite(data_led, HIGH);
-  delay(1000);
-  out = digitalRead(q_pin);
-  digitalWrite(out_led, out);
-  digitalWrite(s_pin, HIGH);
-
-  digitalWrite(set_led, HIGH);
-  digitalWrite(s_pin, HIGH);
+  digitalWrite(s_pin, AL0);
+  setLED(s_led, AL0);
+  digitalWrite(r_pin, AL1);
+  setLED(r_led, AL1);
+  setDataLED();
 }

+/*
+ * Clear stores a 0 in the latch.
+ */
 void
-reset(void)
+clear(void)
 {
-  int out;
-
-  Serial.println("/S->0, /R->1");
-  Serial.println("    (/Q should be 0)");
-  digitalWrite(s_pin, HIGH);
-  digitalWrite(set_led, HIGH);
-  digitalWrite(r_pin, LOW);
-  digitalWrite(data_led, LOW);
-  out = digitalRead(q_pin);
-  digitalWrite(out_led, out);
-  delay(1000);
-  digitalWrite(r_pin, HIGH);
-
-  digitalWrite(data_led, HIGH);
-  digitalWrite(r_pin, HIGH);
+  digitalWrite(s_pin, AL1);
+  setLED(s_led, AL1);
+  digitalWrite(r_pin, AL0);
+  setLED(r_led, AL0);
+  setDataLED();
 }

+/*
+ * Store keeps the present state of the latch.
+ */
 void
-setup(void)
+store(void)
 {
+  digitalWrite(s_pin, AL0);
+  setLED(s_led, AL1);
+  digitalWrite(r_pin, AL0);
+  setLED(r_led, AL1);
+  setDataLED();
+}
+
+/*
+ * SetDataLED reads the current status off the /Q pin, and sets the
+ * indicator appropriately.
+ */
+void
+setDataLED(void)
+{
+  int out = digitalRead(qq_pin);
+
+  digitalWrite(out_led, out);
+}
+
+/*
+ * setLED takes a pin and its current state, and sets the appropriate indicator
+ * accordingly, accounting for the fact that the LEDs on the proto-shield are
+ * active high.
+ */
+void
+setLED(int pin, int state)
+{
+  if (AL0 == state)
+    digitalWrite(pin, LOW);
+  else
+    digitalWrite(pin, HIGH);
+}
+
+void setup() {
   pinMode(s_pin, OUTPUT);
   pinMode(r_pin, OUTPUT);
   pinMode(q_pin, INPUT);
   pinMode(qq_pin, INPUT);
-  pinMode(set_led, OUTPUT);
-  pinMode(data_led, OUTPUT);
+  pinMode(s_led, OUTPUT);
+  pinMode(r_led, OUTPUT);
   pinMode(out_led, OUTPUT);
-  digitalWrite(s_pin, HIGH);
-  digitalWrite(r_pin, HIGH);
-  digitalWrite(set_led, HIGH);
-  digitalWrite(data_led, HIGH);
   Serial.begin(9600);
-  Serial.println("0 -> ");
-  Serial.println(LOW);
-  Serial.println("1 -> ");
-  Serial.println(HIGH);
 }

-void
-loop(void)
-{
-  int out;
+void loop() {
   set();
-  out = digitalRead(q_pin);
-  Serial.print("Q->");
-  Serial.println(out);
   delay(1000);
-  reset();
-  out = digitalRead(q_pin);
-  Serial.print("Q->");
-  Serial.println(out);
+  store();
+  delay(1000);
+  clear();
+  delay(1000);
+  store();
   delay(1000);
 }
-
-
-


統計データに惑わされていました。環境変化後の応答時間も長くなるので方針変更

統計データに惑わされていました。環境変化後の応答時間も長くなるので方針変更

--- 2_example/example09m_hum/example09m_hum.ino
+++ 2_example/example09m_hum/example09m_hum.ino
@@ -19,6 +19,7 @@
 #define AmbientWriteKey "0123456789abcdef"  // ライトキー(16桁の16進数)
 #define SENDTO "192.168.0.255"              // 送信先のIPアドレス
 #define PORT 1024                           // 送信のポート番号
+#define SLEEP_P 20*60*1000000               // スリープ時間 20分(uint32_t)
 #define SLEEP_N 36                          // 最長スリープ時間 SLEEP_P×SLEEP_N
 #define DEADZONE 0.3                        // 前回値との相違に対する閾値(℃)
 #define DEVICE "humid_3,"                   // デバイス名(5文字+"_"+番号+",")
@@ -107,11 +108,12 @@
 	WAKE_COUNT	1	2	3	4	5	6	7...
 	累積時間	0	20	40	60	90	150	210...
 	測定間隔	20	20	20	30	60	60
-*/
-	uint32_t SLEEP_P;                       // スリープ時間 (uint32_t)
+
+	uint32_t SLEEP_P;
 	if(WAKE_COUNT <= 3)		SLEEP_P = 20*60*1000000;
 	else if(WAKE_COUNT==4) 	SLEEP_P = 30*60*1000000;
 	else 					SLEEP_P = 60*60*1000000;
+*/
     digitalWrite(PIN_LED,LOW);              // LEDの消灯
     ESP.deepSleep(SLEEP_P,WAKE_RF_DEFAULT); // スリープモードへ移行する
     while(1){                               // 繰り返し処理


HTML出力のタイミング変更

HTML出力のタイミング変更

--- 2_example/example16f_led/example16f_led.ino
+++ 2_example/example16f_led/example16f_led.ino
@@ -131,7 +131,6 @@
         if(t>TIMEOUT) break; else delay(1); // TIMEOUTに到達したらwhileを抜ける
     }
     if(client.connected()){                 // 当該クライアントの接続状態を確認
-        html(client,target,ledR,ledG,ledB,WiFi.localIP()); // HTMLコンテンツ出力
         t=0;
         if(target==0) t=0;
         if(target==1) t=1023;
@@ -150,16 +149,17 @@
         }else{
             switch(pin){
                 case PIN_LED_R:
-                    ledR=ledCtrl(PIN_LED_R,ledR,t,4);
+                    ledR=ledCtrl(PIN_LED_R,ledR,t,1000);
                     break;
                 case PIN_LED_G:
-                    ledG=ledCtrl(PIN_LED_G,ledG,t,4);
+                    ledG=ledCtrl(PIN_LED_G,ledG,t,1000);
                     break;
                 case PIN_LED_B:
-                    ledB=ledCtrl(PIN_LED_B,ledB,t,4);
+                    ledB=ledCtrl(PIN_LED_B,ledB,t,1000);
                     break;
             }
         }
+        html(client,target,ledR,ledG,ledB,WiFi.localIP()); // HTMLコンテンツ出力
     }                                       // 負のときは-100を掛けて出力
     client.stop();                          // クライアントの切断
     Serial.println("Disconnected");         // シリアル出力表示


incorporate PIR "eyes" into servo-turning-sine-wave

--- servo-turning-sine-wave/servo-turning-sine-wave.ino
+++ servo-turning-sine-wave/servo-turning-sine-wave.ino
@@ -3,19 +3,15 @@
 #include <Math.h>
 #include <Servo.h>

-//
-// CONSTANTS
-//
-
 // multiply by degrees to get radians
 //
 const double RADIANS_PER_DEGREE = 0.0174532925;

-const int LEFT_LIMIT = 60;
-const int RIGHT_LIMIT = 180;
+const int LEFT_LIMIT = 80;
+const int RIGHT_LIMIT = 140;

 // milliseconds to wait between servo movement: when servo is gently oscillating
-const int GENTLE_DELAY = 45;
+const int GENTLE_DELAY = 100;

 // milliseconds to wait between servo movement: when servo is shaking back & forth
 const int SHAKE_DELAY = 10;
@@ -29,6 +25,13 @@
 // number of degrees to shake servo on each side of center
 const int SHAKE_OFFSET_ANGLE = 25;

+// infra red motion detectors
+const int IR_LEFT = 3;
+const int IR_RIGHT = 5;
+
+// diagnostic LED
+const int LED_DIAG = 13;
+
 //
 // GLOBALS
 //
@@ -36,17 +39,21 @@
 Servo myservo;  // create servo object to control a servo
                 // a maximum of eight servo objects can be created

-int currAngle = 135;
+int currAngle = 100;

 void setup()
 {
   myservo.attach(9);   // attaches the servo on pin 9 to the servo object
   myservo.write(currAngle);

-  // initialize digital pin 13 as an output.
-  pinMode(13, OUTPUT);
+  // initialize diagnostic LED
+  pinMode(LED_DIAG, OUTPUT);

   Serial.begin(9600);  // open the serial port at 9600 bps:
+
+  // initialize IR detectors
+  pinMode(IR_LEFT, INPUT);
+  pinMode(IR_RIGHT, INPUT);

   delay(3000);         // wait long enough to open Serial console
 }
@@ -59,15 +66,15 @@
   Serial.println(behaviorMode);

   switch (behaviorMode) {
+
     case 0:
-    case 1:
-    case 2:
+      currAngle = shakeServo(currAngle, random(2, 4));
+      break;
+
+    default:
       currAngle = oscillateGently(currAngle, random(3, 6));
       break;

-    case 3:
-      currAngle = shakeServo(currAngle, random(2, 4));
-      break;
   }

   // wait random seconds until next loop
@@ -85,9 +92,9 @@
   int limit;

   for (int ii = 0; ii < numOscillations ; ii += 1) {
-    delay(TURN_AROUND_DELAY);
+    delay(random(1500, 3000));

-    digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
+    digitalWrite(LED_DIAG, LOW);    // turn the LED off by making the voltage LOW
     range = angle - LEFT_LIMIT;
     skew = random(random(range));
     limit = LEFT_LIMIT + skew;
@@ -103,9 +110,9 @@
     Serial.print("\tangle: ");
     Serial.println(angle);

-    delay(TURN_AROUND_DELAY);
+    delay(random(1500, 3000));

-    digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
+    digitalWrite(LED_DIAG, HIGH);   // turn the LED on (HIGH is the voltage level)
     range = RIGHT_LIMIT - angle;
     skew = random(random(range));
     limit = RIGHT_LIMIT - skew;


Update IFTTT-sketch: temperatuur versturen

--- software/arduino/iota-ifttt/iota-ifttt.ino
+++ software/arduino/iota-ifttt/iota-ifttt.ino
@@ -1,3 +1,6 @@
+#include <LM75.h>
+#include <Wire.h>
+
 #include <ESP8266HTTPClient.h>
 #include <ESP8266WiFi.h>
 #include "OneButton.h"
@@ -11,11 +14,22 @@

 #define BUTTON_PIN          0   // D3
 OneButton button(BUTTON_PIN, true);
+LM75 temp_sensor;
+
+float getTemperature() {
+  temp_sensor.shutdown(false);
+  delay(100);
+  float temperature = temp_sensor.temp();
+  temp_sensor.shutdown(true);
+  return temperature;
+}

 void setup() {
   Serial.begin(115200);
   delay(10);
   Serial.println();
+
+  Wire.begin();

   WiFi.mode(WIFI_STA);
   WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
@@ -45,6 +59,8 @@
   url += IFTTT_EVENT;
   url += "/with/key/";
   url += IFTTT_KEY;
+  url += "?value1=";
+  url += String(getTemperature());

   HTTPClient http;
   http.begin(url);


Added 6-part rotating blink, mirror, static effects

--- Arduino/linkit_duo_led5/linkit_duo_led5.ino
+++ Arduino/linkit_duo_led5/linkit_duo_led5.ino
@@ -4,12 +4,12 @@

 #define RANDOM_SEED_PIN A1

-#define LED_COUNT 72
+#define LED_COUNT 144
 #define MAX_LED (LED_COUNT)
 rgb_color colors[LED_COUNT];
 rgb_color render[LED_COUNT];

-int states[LED_COUNT];
+int effects[LED_COUNT];

 #define BRIGHTNESS_DIVISOR 20.0
 #define DEFAULT_BRIGHTNESS_PERCENT 20
@@ -68,7 +68,7 @@
 void erase(bool display = false){
   for(int i = 0; i < LED_COUNT; i++){
     colors[i] = black;
-    states[i] = 0;
+    effects[i] = 0;
   }
   if(display){
     ledStrip.write(colors, LED_COUNT);
@@ -106,25 +106,78 @@
 #define BLINK_ON 1
 #define BREATHE_ON 2

+// blink group
+#define BLINK_ON_1 11
+#define BLINK_ON_2 12
+#define BLINK_ON_3 13
+#define BLINK_ON_4 14
+#define BLINK_ON_5 15
+#define BLINK_ON_6 16
+
+#define STATIC_ON 21
+
 void push_color(rgb_color color, bool display = false){
   for(int i = MAX_LED - 1; i >= 1; i--){
     colors[i] = colors[i-1];
-    states[i] = states[i-1];
+    effects[i] = effects[i-1];
   }
   colors[0] = color;
-  states[0] = NO_STATE;
+  effects[0] = NO_STATE;

   if(display){
     ledStrip.write(colors, LED_COUNT);
   }
 }

-#define MAX_BLINK 6667
+#define MAX_BLINK 6000
+#define BLINK_0 0
+#define BLINK_1 999
+#define BLINK_2 1999
+#define BLINK_3 2999
+#define BLINK_4 3999
+#define BLINK_5 4999
+#define BLINK_6 5999
 int blink_counter = 0;
 bool blink_state = true; // false means blank

+// blink group
+bool blink_state_1 = true;
+bool blink_state_2 = true;
+bool blink_state_3 = true;
+bool blink_state_4 = true;
+bool blink_state_5 = true;
+bool blink_state_6 = true;
+
 void start_blinking(){
-  states[0] = BLINK_ON;
+  effects[0] = BLINK_ON;
+}
+
+void start_blinking_1(){
+  effects[0] = BLINK_ON_1;
+}
+
+void start_blinking_2(){
+  effects[0] = BLINK_ON_2;
+}
+
+void start_blinking_3(){
+  effects[0] = BLINK_ON_3;
+}
+
+void start_blinking_4(){
+  effects[0] = BLINK_ON_4;
+}
+
+void start_blinking_5(){
+  effects[0] = BLINK_ON_5;
+}
+
+void start_blinking_6(){
+  effects[0] = BLINK_ON_6;
+}
+
+void start_blinking_r(){
+  effects[0] = BLINK_ON_1 + random((BLINK_ON_6 - BLINK_ON_1) + 1);
 }

 #define BREATHE_TIME 500
@@ -132,7 +185,7 @@
 #define BREATHE_MAX_STEP 22
 #define BREATHE_BRIGHTNESS_MIN 0
 #define DEFAULT_BRIGHTNESS_SCALE (DEFAULT_BRIGHTNESS_PERCENT / 100.0)
-#define MINIMUM_BRIGHTNESS_SCALE 0.03
+#define MINIMUM_BRIGHTNESS_SCALE 0.02

 int breathe_counter = 0;
 int breathe_step = 0;
@@ -167,7 +220,11 @@
 };

 void start_breathing(){
-  states[0] = BREATHE_ON;
+  effects[0] = BREATHE_ON;
+}
+
+void start_static(){
+  effects[0] = STATIC_ON;
 }

 rgb_color blend_colors(rgb_color color1, rgb_color color2){
@@ -214,7 +271,7 @@
 void do_flood(){
   for(int i = 1; i < LED_COUNT; i++){
     colors[i] = colors[0];
-    states[i] = states[0];
+    effects[i] = effects[0];
   }
 }

@@ -226,16 +283,61 @@
   push_color(random_color());
 }

+int do_mirror(){
+  for(int i = 0; i < LED_COUNT / 2; i++){
+    colors[LED_COUNT - i - 1] = colors[i];
+    effects[LED_COUNT - i - 1] = effects[i];
+  }
+}
+
 void setup_buffer(){
   for(int i = 0; i < LED_COUNT; i++){
-    if(states[i] == BLINK_ON){
+    if(effects[i] == BLINK_ON){
       if(blink_state){
         render[i] = scale_color(colors[i], DEFAULT_BRIGHTNESS_SCALE);
       } else {
         render[i] = scale_color(colors[i], MINIMUM_BRIGHTNESS_SCALE);
       }
-    } else if(states[i] == BREATHE_ON){
+    } else if(effects[i] == BLINK_ON_1){
+      if(blink_state_1){
+        render[i] = scale_color(colors[i], DEFAULT_BRIGHTNESS_SCALE);
+      } else {
+        render[i] = scale_color(colors[i], MINIMUM_BRIGHTNESS_SCALE);
+      }
+    } else if(effects[i] == BLINK_ON_2){
+      if(blink_state_2){
+        render[i] = scale_color(colors[i], DEFAULT_BRIGHTNESS_SCALE);
+      } else {
+        render[i] = scale_color(colors[i], MINIMUM_BRIGHTNESS_SCALE);
+      }
+    } else if(effects[i] == BLINK_ON_3){
+      if(blink_state_3){
+        render[i] = scale_color(colors[i], DEFAULT_BRIGHTNESS_SCALE);
+      } else {
+        render[i] = scale_color(colors[i], MINIMUM_BRIGHTNESS_SCALE);
+      }
+    } else if(effects[i] == BLINK_ON_4){
+      if(blink_state_4){
+        render[i] = scale_color(colors[i], DEFAULT_BRIGHTNESS_SCALE);
+      } else {
+        render[i] = scale_color(colors[i], MINIMUM_BRIGHTNESS_SCALE);
+      }
+    } else if(effects[i] == BLINK_ON_5){
+      if(blink_state_5){
+        render[i] = scale_color(colors[i], DEFAULT_BRIGHTNESS_SCALE);
+      } else {
+        render[i] = scale_color(colors[i], MINIMUM_BRIGHTNESS_SCALE);
+      }
+    } else if(effects[i] == BLINK_ON_6){
+      if(blink_state_6){
+        render[i] = scale_color(colors[i], DEFAULT_BRIGHTNESS_SCALE);
+      } else {
+        render[i] = scale_color(colors[i], MINIMUM_BRIGHTNESS_SCALE);
+      }
+    } else if(effects[i] == BREATHE_ON){
       render[i] = scale_color(colors[i], DEFAULT_BRIGHTNESS_SCALE * breathe_steps[BREATHE_MAX_STEP - breathe_step]);
+    } else if(effects[i] == STATIC_ON){
+      render[i] = random_color();
     } else {
       render[i] = scale_color(colors[i], DEFAULT_BRIGHTNESS_SCALE);
     }
@@ -265,7 +367,7 @@
 }

 void setup() {
-  Serial.begin(115200);  // open serial connection to USB Serial
+  //Serial.begin(115200);  // open serial connection to USB Serial
                          //port(connected to your computer)
   Serial1.begin(57600);  // open internal serial connection to
                          //MT7688
@@ -290,26 +392,43 @@
     int c = Serial1.readBytesUntil('|', str, MAX_STRING_LENGTH);
     str[c] = 0;

-    // reset the states so the automatic render won't interfere
+    // reset the effects so the automatic render won't interfere
     blink_state = true;
+    blink_state_1 = false;
+    blink_state_2 = false;
+    blink_state_3 = false;
+    blink_state_4 = false;
+    blink_state_5 = false;
+    blink_state_6 = false;
     blink_counter = 0;
     breathe_step = 0;
     breathe_counter = 0;
+
+    //Serial.println(str);

 // fast blink, breathe
 // static, flame
-// flame
-// tripple blink, rotating blink cycle, cop lights
 // invert hue, swing hue, back and forth between two arbitrary colors, rgb cube
 // rainbow colors incremental, or continuously changing
 // shooting up
 // push-down animation when a new build is seen (to emphasize its adding)
 // fade based on build time
+// change refresh rate based on time of day (afterhours it doesn't need to check that often)
+// show something if the data hasn't updated in a long time
+// automatically stop and restart the script at night
+// blink a/b

     if     (is_command(str, "pause"))    paused = true;
     else if(is_command(str, "continue")) paused = false;
     else if(is_command(str, "erase"))    erase(true);
     else if(is_command(str, "blink"))    start_blinking();
+    else if(is_command(str, "blink1"))   start_blinking_1();
+    else if(is_command(str, "blink2"))   start_blinking_2();
+    else if(is_command(str, "blink3"))   start_blinking_3();
+    else if(is_command(str, "blink4"))   start_blinking_4();
+    else if(is_command(str, "blink5"))   start_blinking_5();
+    else if(is_command(str, "blink6"))   start_blinking_6();
+    else if(is_command(str, "blinkr"))   start_blinking_r();
     else if(is_command(str, "breathe"))  start_breathing();
     else if(is_command(str, "flush"))    flush();
     else if(is_command(str, "blend"))    do_blend();
@@ -319,6 +438,8 @@
     else if(is_command(str, "fade"))     do_fade();
     else if(is_command(str, "flood"))    do_flood();
     else if(is_command(str, "random"))   do_random();
+    else if(is_command(str, "mirror"))   do_mirror();
+    else if(is_command(str, "static"))   start_static();
     else if(is_command(str, "red"))      push_color(red);
     else if(is_command(str, "green"))    push_color(green);
     else if(is_command(str, "blue"))     push_color(blue);
@@ -335,12 +456,13 @@
     else if(is_command(str, "seafoam"))  push_color(seafoam);
     else if(is_command(str, "ltblue"))   push_color(ltblue);
     else if(is_command(str, "dkgray"))   push_color(dkgray);
+    else Serial.println("WTF");

   } else {
     bool should_flush = false;

     blink_counter = (blink_counter + 1) % MAX_BLINK;
-    if(blink_counter == 0){
+    if(blink_counter == BLINK_0){
       if(blink_state){
         blink_state = false;
       } else {
@@ -348,7 +470,43 @@
       }
       should_flush = true;
     }
-
+
+    if(blink_counter == BLINK_1){
+      blink_state_6 = false;
+      blink_state_1 = true;
+      should_flush = true;
+    }
+
+    if(blink_counter == BLINK_2){
+      blink_state_1 = false;
+      blink_state_2 = true;
+      should_flush = true;
+    }
+
+    if(blink_counter == BLINK_3){
+      blink_state_2 = false;
+      blink_state_3 = true;
+      should_flush = true;
+    }
+
+    if(blink_counter == BLINK_4){
+      blink_state_3 = false;
+      blink_state_4 = true;
+      should_flush = true;
+    }
+
+    if(blink_counter == BLINK_5){
+      blink_state_4 = false;
+      blink_state_5 = true;
+      should_flush = true;
+    }
+
+    if(blink_counter == BLINK_6){
+      blink_state_5 = false;
+      blink_state_6 = true;
+      should_flush = true;
+    }
+
     breathe_counter = (breathe_counter + 1) % BREATHE_TIME;
     if(breathe_counter == 0){
       int next_breathe_step = breathe_step + breathe_direction;


Updated MQTT MAX_PACKET and KEEPALIVE settings clause to include    PubSubClient.h -after- changing the values (because PSC.h uses    an #ifndef check before setting).    Updated "status 1" to return a much smaller amount of data to fix a    problem where the serial monitor would display the output, but it    wouldn't be published to MQTT.    Added "status 3" as MQTT status output.    Added "status 4" as OTA status output.    Added MAX_PACKET and KEEPALIVE out put to monitor and MQTTat start-up.

--- sonoff.ino
+++ sonoff.ino
@@ -1,5 +1,5 @@
 /*
- * $Id: sonoff.ino,v 1.1 2016/04/04 14:45:06 anoncvs Exp $
+ * $Id: sonoff.ino,v 1.2 2016/04/30 14:52:52 anoncvs Exp $
  *
  * Sonoff Arduino implementation by Theo Arends
  */
@@ -11,11 +11,13 @@
 #include <ESP8266WiFi.h>
 #include <ESP8266HTTPClient.h>
 #include <ESP8266httpUpdate.h>
-#include <PubSubClient.h>

 /*
  * Change the defined MQTT packet size and keepalive
  * to larger values, as recommended by Theo.
+ *
+ * Note that the PubSubClient library should be included
+ * -after- these redefines, not before.
  */
 #ifdef MQTT_MAX_PACKET_SIZE
 	#undef MQTT_MAX_PACKET_SIZE
@@ -25,6 +27,7 @@
 	#undef MQTT_KEEPALIVE
 #endif
 #define MQTT_KEEPALIVE 120
+#include <PubSubClient.h>

 struct SYSCFG {
   unsigned long cfg_holder;
@@ -102,7 +105,7 @@
       sprintf_P(svalue, PSTR("%s"), VERSION);
       mqtt_publish(stopic, svalue);
       sprintf_P(stopic, PSTR("%s/%s/FALLBACKTOPIC"), PUB_PREFIX, sysCfg.mqtt_topic);
-      sprintf_P(svalue, PSTR(MQTT_CLIENT_ID), ESP.getChipId());
+      sprintf_P(svalue, PSTR(MQTT_CLIENT_ID" MXPKSZ %d, KPALV %d"), ESP.getChipId(), MQTT_MAX_PACKET_SIZE, MQTT_KEEPALIVE);
       mqtt_publish(stopic, svalue);
     } else {
       DEBUG_MSG("APP MQTT connect failed, rc = %d retry in 5 seconds\n", mqttClient.state());
@@ -160,11 +163,18 @@
       sprintf_P(svalue, PSTR("%s, %s, %s, %d, %d"),
         VERSION, sysCfg.mqtt_topic, sysCfg.mqtt_subtopic, sysCfg.power, sysCfg.timezone);
       if ((data_len > 0) && (payload == 1)) {
-        sprintf_P(svalue, PSTR("%s, "MQTT_CLIENT_ID", %s, %s, %s, %s, %d, %d"),
-          sysCfg.mqtt_grptopic, ESP.getChipId(), sysCfg.otaUrl, sysCfg.sta_ssid, sysCfg.sta_pwd, sysCfg.mqtt_host, heartbeat, sysCfg.saveFlag);
+        sprintf_P(svalue, PSTR("NET: %s, "MQTT_CLIENT_ID", %s, %s, %d, %d"),
+          sysCfg.mqtt_grptopic, ESP.getChipId(), sysCfg.sta_ssid, sysCfg.sta_pwd, heartbeat, sysCfg.saveFlag);
+          // sysCfg.mqtt_grptopic, ESP.getChipId(), sysCfg.sta_ssid, sysCfg.sta_pwd, heartbeat, sysCfg.saveFlag);
       }
       if ((data_len > 0) && (payload == 2)) {
-        sprintf_P(svalue, PSTR("Version %s, Boot %d, SDK %s"), VERSION, ESP.getBootVersion(), ESP.getSdkVersion());
+        sprintf_P(svalue, PSTR("FMWR: Version %s, Boot %d, SDK %s"), VERSION, ESP.getBootVersion(), ESP.getSdkVersion());
+      }
+      if ((data_len > 0) && (payload == 3)) {
+        sprintf_P(svalue, PSTR("MQTT: %s, MQTT-MAX-PACKET: %d, MQTT-KEEPALIVE: %d"), sysCfg.mqtt_host, MQTT_MAX_PACKET_SIZE, MQTT_KEEPALIVE);
+      }
+      if ((data_len > 0) && (payload == 4)) {
+        sprintf_P(svalue, PSTR("OTA: %s"), sysCfg.otaUrl);
       }
     }
     else if (!grpflg && !strcmp(type,"UPGRADE")) {
@@ -455,6 +465,8 @@
   Serial.printf("Project %s (Topic %s, Fallback "MQTT_CLIENT_ID", GroupTopic %s) Version %s (Boot %d, SDK %s)\n",
     PROJECT, sysCfg.mqtt_topic, ESP.getChipId(), sysCfg.mqtt_grptopic, VERSION, ESP.getBootVersion(), ESP.getSdkVersion());

+  Serial.printf("\n\tMQTT-MAX-PACKET: %d\n\t MQTT-KEEPALIVE: %d\n\n", MQTT_MAX_PACKET_SIZE, MQTT_KEEPALIVE);
+
   WIFI_Connect();

   mqttClient.setServer(sysCfg.mqtt_host, MQTT_PORT);


Remove unused variables.

Remove unused variables.

--- src/CuringChamberControl.ino
+++ src/CuringChamberControl.ino
@@ -150,9 +150,6 @@

 void loop()
 {
-  // Get the time since the last actuation. Be sure to handle time wraparound!!
-  uint32_t timeSinceLastTempActuation;
-  uint32_t timeSinceLastHumidityActuation;
   uint32_t currentTime = millis();
   if (currentTime < _lastCheckTime) {
     // Happens once every 50 days or so


General cleanup

General cleanup

--- DigitalVFO.ino
+++ DigitalVFO.ino
@@ -129,7 +129,24 @@
 // define the "in use" character
 byte in_use_char[8] = {0x10,0x18,0x1c,0x1e,0x1c,0x18,0x10,0x00};

-// map select_offset to bump values
+//-----
+// battery symbols
+//-----
+
+byte battunder[8] = {0x0e,0x1b,0x11,0x11,0x11,0x11,0x11,0x11};
+byte batt00[8]    = {0x0e,0x1b,0x11,0x11,0x11,0x11,0x11,0x1f};
+byte batt20[8]    = {0x0e,0x1b,0x11,0x11,0x11,0x11,0x1f,0x1f};
+byte batt40[8]    = {0x0e,0x1b,0x11,0x11,0x11,0x1f,0x1f,0x1f};
+byte batt60[8]    = {0x0e,0x1b,0x11,0x11,0x1f,0x1f,0x1f,0x1f};
+byte batt80[8]    = {0x0e,0x1b,0x11,0x1f,0x1f,0x1f,0x1f,0x1f};
+byte batt100[8]   = {0x0e,0x1b,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
+byte battover[8]  = {0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
+byte battnone[8]  = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
+
+// array of references to the 9 'battery symbol' characters
+byte *batt_syms[] = {battunder, batt00, batt20, batt40, batt60, batt80, batt100, battover, battnone};
+
+// map select_offset to frequency bump values
 ULONG offset2bump[] = {1,           // offset = 0
                        10,          // 1
                        100,         // 2
@@ -143,28 +160,11 @@
 // string holding one entire blank row (allocated in setup())
 char *BlankRow = NULL;

-// default LCD contrast & brightness
+// default frequency plus LCD contrast & brightness
 const ULONG DefaultFrequency = MinFreq;
 const UINT DefaultSelDigit = 2;
 const UINT DefaultLcdContrast = 0;
 const UINT DefaultLcdBrightness = 150;
-
-//-----
-// battery symbols
-//-----
-
-byte battunder[8] = {0x0e,0x1b,0x11,0x11,0x11,0x11,0x11,0x11};
-byte batt00[8]    = {0x0e,0x1b,0x11,0x11,0x11,0x11,0x11,0x1f};
-byte batt20[8]    = {0x0e,0x1b,0x11,0x11,0x11,0x11,0x1f,0x1f};
-byte batt40[8]    = {0x0e,0x1b,0x11,0x11,0x11,0x1f,0x1f,0x1f};
-byte batt60[8]    = {0x0e,0x1b,0x11,0x11,0x1f,0x1f,0x1f,0x1f};
-byte batt80[8]    = {0x0e,0x1b,0x11,0x1f,0x1f,0x1f,0x1f,0x1f};
-byte batt100[8]   = {0x0e,0x1b,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
-byte battover[8]  = {0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
-byte battnone[8]  = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-
-// array of references to the 8 'battery symbol' characters
-byte *batt_syms[] = {battunder, batt00, batt20, batt40, batt60, batt80, batt100, battover, battnone};

 //-----
 // Events and the event queue.
@@ -187,10 +187,9 @@
 const int EventQueueLength = 10;

 //-----
-// VFO modes.
+// VFO modes.  Online or standby.
 //-----

-// VFO modes - online or standby
 enum Mode
 {
   vfo_Standby,
@@ -203,8 +202,9 @@

 // milliseconds delay between measuring battery voltage
 const long MeasureVoltageDelay = 1000;
-// number of measure periods before report (if wanted in DEBUG)
-const long ReportVoltageDelay = 30;
+
+// number of voltage measure periods before report (if wanted in DEBUG)
+const long ReportVoltageDelay = 60;

 // stuff for the calibrate action
 const int MinClockOffset = -32000;
@@ -212,7 +212,7 @@
 const int MaxOffsetDigits = 5;

 // battery voltage limits
-const float OverVoltage = 8.35;   // battery voltage for CHARGING FULL
+const float OverVoltage = 8.35;   // battery voltage for CHARGING & FULL
 const float MaxVoltage = 7.8;     // battery voltage for "100% full"
 const float MinVoltage = 6.48;    // battery voltage for "0% full"
                                   // BMS disconnects at around 6.40v
@@ -1173,8 +1173,14 @@
 void display_battery(void)
 {
 #if SHOW_VOLTAGE
-  // display measured voltage
-  sprintf(FreqBuffer, "%.2fv", MeasuredVoltage);
+  // display measured voltage if we have a bettery
+  strcpy(FreqBuffer, "     ");
+
+  if (MeasuredVoltage > NoBattVoltage)
+  {
+    sprintf(FreqBuffer, "%.2fv", MeasuredVoltage);
+  }
+
   lcd.setCursor(9, 1);
   lcd.print(FreqBuffer);
 #endif
@@ -2742,7 +2748,8 @@
   // measure voltage, we will get a value of 1023 for 3.3 volts
   // adjust the divider to calibrate
   // with my crappy multimeter:  (32.11/9.90)
-  MeasuredVoltage = (3.3 * analogRead(mc_BattVolts)) / 1023 * 32.11/9.90;
+  UINT measured = analogRead(mc_BattVolts);
+  MeasuredVoltage = (3.3 * measured) / 1023 * 32.11/9.90;

   int percent = (int) ((MeasuredVoltage - MinVoltage) / (MaxVoltage - MinVoltage) * 100.0);

@@ -2823,6 +2830,8 @@

     if (ch == COMMAND_END_CHAR)   // if end of command, execute it
     {
+      char answer[1024];
+
       CommandBuffer[CommandIndex] = '\0';
       Serial.printf(F("%s\n"), do_external_cmd(answer, CommandBuffer, CommandIndex-1));
       CommandIndex = 0;


Added WiFi sleep and better logging

Added WiFi sleep and better logging

--- Particle/THDweeter/src/THDweeter.ino
+++ Particle/THDweeter/src/THDweeter.ino
@@ -15,19 +15,17 @@
 // This #include statement was automatically added by the Particle IDE.
 #include "Adafruit_DHT/Adafruit_DHT.h"

-#define DHTPIN 2        // what pin we're connected to
-#define DHTTYPE DHT22		// DHT 22 (AM2302)
-
-int led = D7;           // internal LED
-int pushButton = D5;    // Push button is connected to D5
-int i = 0;              // time counter
-
 // Connect pin 1 (on the left) of the sensor to +5V
 // Connect pin 2 of the sensor to whatever your DHTPIN is
 // Connect pin 4 (on the right) of the sensor to GROUND
 // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

-DHT dht(DHTPIN, DHTTYPE);
+int dhtPin = 2;           // DHT sensor
+int ledPin = D7;          // Internal LED
+int pushButtonPin = D5;   // Push button
+int readoutTimeIntervalMin = 3;   // perform a readout every given minutes
+
+DHT dht(dhtPin, DHT22);
 HttpClient http;

 // Headers currently need to be set at init, useful for API keys etc.
@@ -39,67 +37,79 @@
 };
 http_request_t request;
 http_response_t response;
+int i = readoutTimeIntervalMin*5*60;    // time counter: force a readout at startup

 void setup() {
- 	Particle.publish("DEBUG","DHT22 veranda");
+  Time.zone(+1);
  	dht.begin();
-  pinMode(led, OUTPUT);               // D7 pin is output
-  pinMode(pushButton, INPUT_PULLUP);  // input with an internal pull-up resistor
+  pinMode(ledPin, OUTPUT);               // D7 pin is output
+  pinMode(pushButtonPin, INPUT_PULLUP);  // input with an internal pull-up resistor
 }

-void readout() {
+void readout(bool button) {
   // First wake up WiFi
-  //Wifi.on();
+  WiFi.on();
+  WiFi.connect();
   // Switch on LED to signal we're reading out the sensor data
-  digitalWrite(led, HIGH);
+  digitalWrite(ledPin, HIGH);
   // Reading temperature or humidity takes about 250 milliseconds!
   // Sensor readings may also be up to 2 seconds 'old' (its a
   // very slow sensor)
  	float h = dht.getHumidity();
   // Read temperature as Celsius
  	float t = dht.getTempCelcius();
-
   // Check if any reads failed and exit early (to try again).
  	if (isnan(h) || isnan(t)) {
-    Particle.publish("DEBUG","Failed to read from DHT sensor!");
- 	  return;
+    //Particle.publish("DEBUG", "Failed to read from DHT sensor!");
+    return;
  	}
  	//float hi = dht.getHeatIndex();
  	//float dp = dht.getDewPoint();
-
  	// cast floats to string
- 	String st(t, 2);
- 	String sh(h, 2);
-
- 	//post to dweet
+ 	String st(t, 1);
+ 	String sh(h, 1);
+  // make sure WiFi is ready
+  while(!WiFi.ready()) {
+    delay(100);
+  }
+  if(button) {
+    Particle.publish("STATE", "Button pressed, data readout");
+  }
+  else {
+    Particle.publish("STATE", "Periodic data readout");
+  }
+  // post to dweet
  	request.hostname = "dweet.io";
   request.port = 80;
-  request.path = "/dweet/for/glp_photon_vth?temp=" + st + "&humidity=" + sh + "&time=" + Time.timeStr();
- 	Particle.publish("Sensor data", request.path);
+  request.path = "/dweet/for/glp_photon_vth?temp=" + st + "&humidity=" + sh + "&time=" + Time.local();
+ 	Particle.publish("DWEET", request.path);
   http.get(request, response, headers);
   //Particle.publish("DEBUG",response.status);
-  Particle.publish("DEBUG", response.body);
-
+  Particle.publish("DWEET", response.body);
   // Done, switch off LED
-  digitalWrite(led, LOW);
-  // and turn off wifi
-  //Wifi.off()
- }
+  digitalWrite(ledPin, LOW);
+}

 void loop() {
-  int pushButtonState = digitalRead(pushButton);
+  int pushButtonState = digitalRead(pushButtonPin);
   if(pushButtonState == LOW) {
     // button was pressed, readout
-    Particle.publish("BUTTON", "Button pressed, reading data");
-    readout();
+    readout(true);
     i = 0;
   }
   else {
     i++;
-    // after 5 minutes force a readout
-    if(i == 100) {
-      readout();
+    // force a readout after the given time interval
+    if(i >= readoutTimeIntervalMin*5*60) {
+      readout(false);
+      i = 0;
+    }
+    if(i == 20*5) {
+      // turn off wifi to spare power, but allow a few seconds
+      // for upgrades/other photon activities
+      WiFi.off();
     }
   }
-  delay(100);
+  // loop at 5 Hz to catch button press events
+  delay(200);
 }