Altered PROGMEM usage due to AVR libc changes.

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

 #define ROMSIZE 2048

-prog_uchar romImage[] PROGMEM  = {
+const byte romImage[] PROGMEM = {
 0x1f, 0x00, 0x20, 0x17, 0x06, 0x20, 0x0e, 0x47, 0xa3, 0xce, 0x7f, 0x80, 0x5a, 0x78, 0x17, 0x05,
 0xf6, 0x0e, 0x26, 0xca, 0xcd, 0x7e, 0x0a, 0x0f, 0x26, 0xca, 0xcd, 0x7e, 0x1a, 0xd9, 0x72, 0x17,
 0x20, 0xc3, 0xcf, 0x5f, 0x00, 0x5b, 0x7b, 0x92, 0xcc, 0x5e, 0xc9, 0xcc, 0x1f, 0x0f, 0x04, 0x02,
@@ -168,7 +168,7 @@
  Serial.println("writing data");
  enableSRAM();
  for (int i=0;i<=ROMSIZE;i++) {
-    write2RAM(i,(byte)romImage[i]);
+    write2RAM(i,pgm_read_byte(romImage+i));
  }
  disableSRAM();

@@ -209,8 +209,8 @@

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


Put the character arrays in a struct to structure the code a little more.

Also added a High/Low/Current display in the “calibration menu” thingie.

--- code/oakpowerboard/oakpowerboard.ino
+++ code/oakpowerboard/oakpowerboard.ino
@@ -40,16 +40,31 @@
 double particle_consumption_current = 0;
 char consumption_current_str[6] = "Wait";

-char analog_value[6] = "00000";
-
 long time_since_last_pulse = millis();

 // Initialize the oled display for address 0x3c
 SSD1306   display(0x3c, 0, 2);
 SSD1306Ui ui     ( &display );

-int analogCounter = 0;
-int analogValue = 0;
+struct measurement_values {
+  int counter = 0;
+  int value = 0;
+  int hi = 0;
+  int lo = 1024;
+} analogVal;
+
+struct measurement_strings {
+  char current[5] = "0000";
+  char hi[5] = "0000";
+  char lo[5] = "0000";
+} valStrings;
+
+enum app_state {
+  HOME,
+  CALIBRATE
+};
+
+app_state current_state = HOME;

 /* Drawing Resources */
 bool draw_totalcount_frame(SSD1306 *display, SSD1306UiState* state, int x, int y);
@@ -72,8 +87,6 @@
   draw_menu_frame,
   draw_calibration_frame
 };
-
-

 bool (*overlays[])(SSD1306 *display, SSD1306UiState* state) = {
   msOverlay
@@ -138,9 +151,19 @@
   if (remainingTimeBudget > 0) {
     yield();
     if(b1_pressed == true) {
+      switch(current_state) {
+        case HOME:
+          ui.setFrames(others, 2);
+          ui.disableAutoTransition();
+          current_state = CALIBRATE;
+          break;
+        case CALIBRATE:
+          ui.setFrames(frames, 2);
+          ui.enableAutoTransition();
+          current_state = HOME;
+          break;
+      }
       //handle b1
-      ui.setFrames(others, 2);
-      ui.disableAutoTransition();
       b1_pressed = false;
       yield();
     }
@@ -161,17 +184,31 @@

     if(b4_pressed == true) {
       //handle b4
-      ui.setFrames(frames, 2);
-      ui.enableAutoTransition();
+      switch(current_state) {
+        case CALIBRATE:
+          analogVal.hi = 0;
+          dtostrf(analogVal.hi, 4, 0, valStrings.hi);
+          analogVal.lo = 1024;
+          dtostrf(analogVal.lo, 4, 0, valStrings.lo);
+          break;
+      }
       b4_pressed = false;
       yield();
     }

-    analogCounter++;
-    if(analogCounter == 10) {
-      analogValue = analogRead(PULSE_PIN);
-      dtostrf(analogValue, 4, 0, analog_value);
-      analogCounter = 0;
+    analogVal.counter++;
+    if(analogVal.counter == 5) {
+      analogVal.value = analogRead(PULSE_PIN);
+      if(analogVal.value > analogVal.hi) {
+        analogVal.hi = analogVal.value;
+        dtostrf(analogVal.hi, 4, 0, valStrings.hi);
+      }
+      if(analogVal.value < analogVal.lo) {
+        analogVal.lo = analogVal.value;
+        dtostrf(analogVal.lo, 4, 0, valStrings.lo);
+      }
+      dtostrf(analogVal.value, 4, 0, valStrings.current);
+      analogVal.counter = 0;
     }

     /*if(pulse_triggered == true) {
@@ -229,11 +266,12 @@
   display->drawString(12 + x, 16, "Current: ");
   display->drawString(12 + x, 28, "High: ");
   display->drawString(12 + x, 40, "Low: ");
-  display->drawString(16 + x, 52, "S3: Back, S2: Ok");
+  display->drawString(x, 52, "S4: RST S3: BCK S2: Ok");
   display->setTextAlignment(TEXT_ALIGN_RIGHT);
-  display->drawString(128, 16, analog_value);
-  display->drawString(128, 28, "1024");
-  display->drawString(128, 40, "0");
+  display->drawString(128 + x, 16, valStrings.current);
+  display->drawString(128 + x, 28, valStrings.hi);
+  display->drawString(128 + x, 40, valStrings.lo);
+  display->drawString(128 + x, 52, analogVal.value > ((analogVal.hi + analogVal.lo) / 2) ? "X" : " ");
   return false;
 }

@@ -241,7 +279,7 @@
   //display->drawXbm(32, 0, 8, 8, wifiActive);
   display->setTextAlignment(TEXT_ALIGN_LEFT);
   display->setFont(Roboto_Plain_10);
-  display->drawString(0, 0, analog_value); //This should be the current time
+  display->drawString(0, 0, valStrings.current); //This should be the current time
   //display->setTextAlignment(TEXT_ALIGN_RIGHT);
   //display->drawString(128, 0, String(millis()));
   return true;


working temp sensor with pointer to TMP275 instance

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

   Part of PCA9548A Library Test Code

-  Copyright 2017 Systronix Inc www.systronix.com
+  Copyright 2018 Systronix Inc www.systronix.com

 ----------------------------------------------------------------------------**/

@@ -26,7 +26,7 @@
 #include <Arduino.h>
 #include <Systronix_PCA9548A.h>	// best version of I2C library is #included by the library. Don't include it here!
 #include <Systronix_TMP275.h>   // temp sensor
-
+#include <SALT_power_FRU.h>     // MUX and sensors pass through PowerFRU, if we have one

  /**
  * debug level
@@ -42,6 +42,10 @@

 uint8_t config_tmp275;

+// If we have PowerFRU, ext net reset must be turned off
+// Also MUX and sensors powered by FRU if a SALT new board
+SALT_power_FRU fru;
+

 //Systronix_PCA9548A PCA9548A_70(PCA9548A_SLAVE_ADDR_0);
 Systronix_PCA9548A PCA9548A_70;
@@ -50,33 +54,21 @@
 //TMP102 on board SALT has same address as TMP275 0 so don't use that
 //

-//Systronix_TMP275 Mux0Temp1(TMP275_SLAVE_ADDR_1);  // D1 ambient temp
+// Drawer 1 uses Mux 1
+Systronix_TMP275 Mux1Temp1;   // D1C1, top animal drawer, left compartment
+Systronix_TMP275 Mux1Temp2;   // D1C2, center
+Systronix_TMP275 Mux1Temp3;   // D1C3
+
+// End Cap Mux 0
 Systronix_TMP275 Mux0Temp1;
-
-//Systronix_TMP275 Mux0Temp2(TMP275_SLAVE_ADDR_2);  // D1 C1 outside
 Systronix_TMP275 Mux0Temp2;

-//Systronix_TMP275 Mux0Temp3(TMP275_SLAVE_ADDR_3);  // D1 C1 inside
-Systronix_TMP275 Mux0Temp3;
-
-//Systronix_TMP275 Mux0Temp4(TMP275_SLAVE_ADDR_4);
-Systronix_TMP275 Mux0Temp4;
-
-//Systronix_TMP275 Mux0Temp5(TMP275_SLAVE_ADDR_5);
-Systronix_TMP275 Mux0Temp5;
-
-//Systronix_TMP275 Mux0Temp6(TMP275_SLAVE_ADDR_6);
-Systronix_TMP275 Mux0Temp6;
-
-//Systronix_TMP275 Mux0Temp7(TMP275_SLAVE_ADDR_7);
-Systronix_TMP275 Mux0Temp7;
-
-
-//Systronix_TMP275 Mux1Temp1(TMP275_SLAVE_ADDR_1);
-Systronix_TMP275 Mux1Temp1;
-
-//Systronix_TMP275 Mux2Temp1(TMP275_SLAVE_ADDR_1);
+// Drawer 2
 Systronix_TMP275 Mux2Temp1;
+Systronix_TMP275 Mux2Temp2;
+Systronix_TMP275 Mux2Temp3;
+
+Systronix_TMP275 *SensorPtr;

 const char * text_ptr;
@@ -88,61 +80,11 @@

 boolean verbose = false;

-/* ========== SETUP ========== */
+//---------------------------< S E T U P >---------------------------------------------------------
+//
 void setup(void)
 {
-PCA9548A_70.setup (PCA9548A_SLAVE_ADDR_0, Wire1, (char*)"Wire1");
-PCA9548A_70.begin (I2C_PINS_29_30, I2C_RATE_100);
-PCA9548A_70.init ();
-
-/**
-TMP102 on board SALT has same address as TMP275 0 so don't use that
-*/
-
-Mux0Temp1.setup (TMP275_SLAVE_ADDR_1, Wire1, (char*)"Wire1");	// initialize this sensor instance
-Mux0Temp1.begin (I2C_PINS_29_30, I2C_RATE_100);
-Mux0Temp1.init (TMP275_CFG_RES12);
-
-Mux0Temp2.setup (TMP275_SLAVE_ADDR_2, Wire1, (char*)"Wire1");	// initialize this sensor instance
-Mux0Temp2.begin (I2C_PINS_29_30, I2C_RATE_100);
-Mux0Temp2.init (TMP275_CFG_RES12);
-
-Mux0Temp3.setup (TMP275_SLAVE_ADDR_3, Wire1, (char*)"Wire1");	// initialize this sensor instance
-Mux0Temp3.begin (I2C_PINS_29_30, I2C_RATE_100);
-Mux0Temp3.init (TMP275_CFG_RES12);
-
-Mux0Temp4.setup (TMP275_SLAVE_ADDR_4, Wire1, (char*)"Wire1");	// initialize this sensor instance
-Mux0Temp4.begin (I2C_PINS_29_30, I2C_RATE_100);
-Mux0Temp4.init (TMP275_CFG_RES12);
-
-Mux0Temp5.setup (TMP275_SLAVE_ADDR_5, Wire1, (char*)"Wire1");	// initialize this sensor instance
-Mux0Temp5.begin (I2C_PINS_29_30, I2C_RATE_100);
-Mux0Temp5.init (TMP275_CFG_RES12);
-
-Mux0Temp6.setup (TMP275_SLAVE_ADDR_6, Wire1, (char*)"Wire1");	// initialize this sensor instance
-Mux0Temp6.begin (I2C_PINS_29_30, I2C_RATE_100);
-Mux0Temp6.init (TMP275_CFG_RES12);
-
-Mux0Temp7.setup (TMP275_SLAVE_ADDR_7, Wire1, (char*)"Wire1");	// initialize this sensor instance
-Mux0Temp7.begin (I2C_PINS_29_30, I2C_RATE_100);
-Mux0Temp7.init (TMP275_CFG_RES12);
-
-
-Mux1Temp1.setup (TMP275_SLAVE_ADDR_1, Wire1, (char*)"Wire1");	// initialize this sensor instance
-Mux1Temp1.begin (I2C_PINS_29_30, I2C_RATE_100);
-Mux1Temp1.init (TMP275_CFG_RES12);
-
-Mux2Temp1.setup (TMP275_SLAVE_ADDR_1, Wire1, (char*)"Wire1");	// initialize this sensor instance
-Mux2Temp1.begin (I2C_PINS_29_30, I2C_RATE_100);
-Mux2Temp1.init (TMP275_CFG_RES12);
-
-  uint8_t iter = 0;
-
-  uint8_t stat = 0;
-
-  pinMode(LED_BUILTIN,OUTPUT);    // LED
-
-
+
   Serial.begin(115200);     // use max baud rate
   // Teensy3 doesn't reset with Serial Monitor as do Teensy2/++2, or wait for Serial Monitor window
   // Wait here for 10 seconds to see if we will use Serial Monitor, so output is not lost
@@ -168,11 +110,72 @@
 #if defined I2C_T3_H
   Serial.printf("Using i2c_t3 I2C library for Teensy\r\n");
 #endif
-
+
+
+
+fru.setup (I2C_FRU);                // POWER FRU
+fru.begin ();
+if (SUCCESS == fru.init ())
+{
+  Serial.printf("Power FRU init OK/r/n");
+}
+else
+{
+  Serial.printf("Power FRU init failed");
+}
+
+
+PCA9548A_70.setup (PCA9548A_SLAVE_ADDR_0, Wire1, (char*)"Wire1");
+PCA9548A_70.begin (I2C_PINS_29_30, I2C_RATE_100);
+PCA9548A_70.init ();
+
+/**
+TMP102 on board SALT has same address as TMP275 0 so don't use that
+*/
+
+/**
+  MUX channel is not opened to every temp sensor so we cannot init them all since that requires
+  actual access of the TMP275.
+  Here all we can do is setup and begin which just get I2C ready for that sensor instance.
+*/
+Mux1Temp1.setup (TMP275_SLAVE_ADDR_1, Wire1, (char*)"D1-C1");	// initialize this sensor instance
+Mux1Temp1.begin (I2C_PINS_29_30, I2C_RATE_100);
+
+
+Mux1Temp2.setup (TMP275_SLAVE_ADDR_2, Wire1, (char*)"D1-C2");	// initialize this sensor instance
+Mux1Temp2.begin (I2C_PINS_29_30, I2C_RATE_100);
+
+
+Mux1Temp3.setup (TMP275_SLAVE_ADDR_3, Wire1, (char*)"D1-C3");	// initialize this sensor instance
+Mux1Temp3.begin (I2C_PINS_29_30, I2C_RATE_100);
+
+
+Mux0Temp1.setup (TMP275_SLAVE_ADDR_1, Wire1, (char*)"ECTop");	// initialize this sensor instance
+Mux0Temp1.begin (I2C_PINS_29_30, I2C_RATE_100);
+
+
+Mux0Temp2.setup (TMP275_SLAVE_ADDR_2, Wire1, (char*)"ECBot");	// initialize this sensor instance
+Mux0Temp2.begin (I2C_PINS_29_30, I2C_RATE_100);
+
+
+Mux2Temp1.setup (TMP275_SLAVE_ADDR_1, Wire1, (char*)"D2-C1");	// initialize this sensor instance
+Mux2Temp1.begin (I2C_PINS_29_30, I2C_RATE_100);
+
+
+Mux2Temp2.setup (TMP275_SLAVE_ADDR_2, Wire1, (char*)"D2-C2");	// initialize this sensor instance
+Mux2Temp2.begin (I2C_PINS_29_30, I2C_RATE_100);
+
+
+Mux2Temp3.setup (TMP275_SLAVE_ADDR_3, Wire1, (char*)"D2-C3"); // initialize this sensor instance
+Mux2Temp3.begin (I2C_PINS_29_30, I2C_RATE_100);
+
+
+  uint8_t iter = 0;
+
+  uint8_t stat = 0;
+
+  pinMode(LED_BUILTIN,OUTPUT);    // LED

-  // start PCA9548A library
-//  PCA9548A_70.begin();
-
   config_value = PCA9548A_PORT_0_ENABLE;  //

   // initialize MUX Channel 0, don't proceed unless succeeds
@@ -225,11 +228,42 @@

-
-uint8_t inbyte = 0;
-
-
-/* ========== LOOP ========== */
+/** ------------------------< sensor_read >-------------------------------------------------------
+
+Read the sensor and fill the data struct
+
+@param tmp275_ptr - pointer to the TMP275 instance whose data we want to sample
+*/
+uint8_t sensor_read (Systronix_TMP275 *tmp275_ptr)
+  {
+  uint8_t stat=0;
+
+  stat = tmp275_ptr->init(TMP275_CFG_RES12);
+  if (stat != SUCCESS)
+    {
+       Serial.printf("TMP275 init %s error, stat=%u\r\n", tmp275_ptr->wire_name, stat);
+       return FAIL;
+     }
+
+  stat = tmp275_ptr->get_temperature_data();
+  if (stat != SUCCESS)
+    {
+       Serial.printf("TMP275 read %s error, stat=%u\r\n", tmp275_ptr->wire_name, stat);
+       return FAIL;
+     }
+  else
+    {
+      Serial.printf ("%s %3.1f\r\n", tmp275_ptr->wire_name, tmp275_ptr->data.deg_f);
+      return SUCCESS;
+    }
+  }
+
+
+
+
+
+//---------------------------< L O O P >-----------------------------------------------------------
+//
 void loop(void)
 {
 //  int16_t temp0;
@@ -238,6 +272,8 @@
   uint16_t rawtemp;
   float temp;

+  uint8_t inbyte = 0;
+
   // remember for tests at end of this loop
   old_seconds = millis()/1000;
   old_total_error_count = PCA9548A_70.error.total_error_count;
@@ -255,6 +291,13 @@
       case 'v':
       case 'V':
         verbose = true;
+        break;
+
+      // TODO allow entering m Some message
+      // which will then log that message.
+      // Useful for adding comments about the test in progress
+      case 'm':
+      case 'M':
         break;

 #if defined I2C_T3_H
@@ -287,126 +330,39 @@
     if (verbose) Serial.printf("OK control=0x%.2X\r\n", control_read_val);
   }

+  SensorPtr = &Mux0Temp1;   // EC Top
+  stat = sensor_read (SensorPtr);
+
+
+  SensorPtr = &Mux0Temp2;   // EC Bot
+  stat = sensor_read (SensorPtr);
+
+  // Enable Mux Channel 1
+  stat = PCA9548A_70.control_write(PCA9548A_PORT_1_ENABLE);
+  if (SUCCESS != stat)
+  {
+    text_ptr = (PCA9548A_70.status_text[PCA9548A_70.error.error_val]);
+    Serial.printf("mux1 control write failed with return of 0x%.2X: %s\r\n", PCA9548A_70.error.error_val, text_ptr);
+    delay(dtime/2); // don't blast repeat failures too quickly
+  }
+  else
+  {
+    stat = PCA9548A_70.control_read(&control_read_val);
+    if (verbose) Serial.printf("OK control=0x%.2X\r\n", control_read_val);
+  }
+
+
   // ------------------------------
-  // Init Mux0Temp7 Sensors
-  stat = Mux0Temp7.init(TMP275_CFG_RES12);
-  if (SUCCESS != stat) Serial.printf(" Mux0Temp7 init failed with return of 0x%.2X: %s\r\n", Mux0Temp7.error.error_val, Mux0Temp7.status_text[Mux0Temp7.error.error_val]);
-
-  // leave the pointer set to read temperature
-  stat = Mux0Temp7.pointer_write(TMP275_TEMP_REG_PTR);
-  if (SUCCESS != stat) Serial.printf(" Mux0Temp7 ptr write failed with return of 0x%.2X: %s\r\n", Mux0Temp7.error.error_val, Mux0Temp7.status_text[Mux0Temp7.error.error_val]);
-
-  // Read Temp on Mux0Temp7
-  rawtemp=0;
-  temp=0.0;
-  stat = Mux0Temp7.register16_read (&rawtemp);
-  if (stat != SUCCESS) Serial.printf("Mux0Temp7 error, stat=0x%.2X\r\n", stat);
-  temp = Mux0Temp7.raw12_to_f(rawtemp);
-  Serial.printf ("Mux0Temp7 %6.4f F\r\n", temp);
-
-    // ------------------------------
-  // Init Mux0Temp6 Sensors
-  stat = Mux0Temp6.init(TMP275_CFG_RES12);
-  if (SUCCESS != stat) Serial.printf(" Mux0Temp6 init failed with return of 0x%.2X: %s\r\n", Mux0Temp6.error.error_val);
-
-  // leave the pointer set to read temperature
-  stat = Mux0Temp6.pointer_write(TMP275_TEMP_REG_PTR);
-  if (SUCCESS != stat) Serial.printf(" Mux0Temp6 ptr write failed with return of 0x%.2X: %s\r\n", Mux0Temp6.error.error_val);
-
-  // Read Temp on Mux0Temp6
-  rawtemp=0;
-  temp=0.0;
-  stat = Mux0Temp6.register16_read (&rawtemp);
-  if (stat != SUCCESS) Serial.printf("Mux0Temp6 error, stat=%u\r\n", stat);
-  temp = Mux0Temp6.raw12_to_f(rawtemp);
-  Serial.printf ("Mux0Temp6 %6.4f F\r\n", temp);
-
-  // ------------------------------
-  // Init Mux0Temp5 Sensors
-  stat = Mux0Temp5.init(TMP275_CFG_RES12);
-  if (SUCCESS != stat) Serial.printf(" Mux0Temp5 init failed with return of 0x%.2X: %s\r\n", Mux0Temp5.error.error_val);
-
-  // leave the pointer set to read temperature
-  stat = Mux0Temp5.pointer_write(TMP275_TEMP_REG_PTR);
-  if (SUCCESS != stat) Serial.printf(" Mux0Temp5 ptr write failed with return of 0x%.2X: %s\r\n", Mux0Temp5.error.error_val);
-
-  // Read Temp on Mux0Temp5
-  rawtemp=0;
-  temp=0.0;
-  stat = Mux0Temp5.register16_read (&rawtemp);
-  if (stat != SUCCESS) Serial.printf("Mux0Temp5 error, stat=%u\r\n", stat);
-  temp = Mux0Temp5.raw12_to_f(rawtemp);
-  Serial.printf ("Mux0Temp5 %6.4f F\r\n", temp);
-
-  // ------------------------------
-  // Init Mux0Temp4 Sensors
-  stat = Mux0Temp4.init(TMP275_CFG_RES12);
-  if (SUCCESS != stat) Serial.printf(" Mux0Temp4 init failed with return of 0x%.2X: %s\r\n", Mux0Temp4.error.error_val);
-
-  // leave the pointer set to read temperature
-  stat = Mux0Temp4.pointer_write(TMP275_TEMP_REG_PTR);
-  if (SUCCESS != stat) Serial.printf(" Mux0Temp4 ptr write failed with return of 0x%.2X: %s\r\n", Mux0Temp4.error.error_val);
-
-  // Read Temp on Mux0Temp4
-  rawtemp=0;
-  temp=0.0;
-  stat = Mux0Temp4.register16_read (&rawtemp);
-  if (stat != SUCCESS) Serial.printf("Mux0Temp4 error, stat=%u\r\n", stat);
-  temp = Mux0Temp4.raw12_to_f(rawtemp);
-  Serial.printf ("Mux0Temp4 %6.4f F\r\n", temp);
-
-
-  // ------------------------------
-  // Init Mux0Temp3 Sensors
-  stat = Mux0Temp3.init(TMP275_CFG_RES12);
-  if (SUCCESS != stat) Serial.printf(" Mux0Temp3 init failed with return of 0x%.2X: %s\r\n", Mux0Temp3.error.error_val);
-
-  // leave the pointer set to read temperature
-  stat = Mux0Temp3.pointer_write(TMP275_TEMP_REG_PTR);
-  if (SUCCESS != stat) Serial.printf(" Mux0Temp3 ptr write failed with return of 0x%.2X: %s\r\n", Mux0Temp3.error.error_val);
-
-  // Read Temp on Mux0Temp3
-  rawtemp=0;
-  temp=0.0;
-  stat = Mux0Temp3.register16_read (&rawtemp);
-  if (stat != SUCCESS) Serial.printf("Mux0Temp3 error, stat=%u\r\n", stat);
-  temp = Mux0Temp3.raw12_to_f(rawtemp);
-  Serial.printf ("Mux0Temp3 %6.4f F\r\n", temp);
-
-
-  // ------------------------------
-  // Init Mux0Temp2 Sensors
-  stat = Mux0Temp2.init(TMP275_CFG_RES12);
-  if (SUCCESS != stat) Serial.printf(" Mux0Temp2 init failed with return of 0x%.2X: %s\r\n", Mux0Temp2.error.error_val);
-
-  // leave the pointer set to read temperature
-  stat = Mux0Temp2.pointer_write(TMP275_TEMP_REG_PTR);
-  if (SUCCESS != stat) Serial.printf(" Mux0Temp2 ptr write failed with return of 0x%.2X: %s\r\n", Mux0Temp2.error.error_val);
-
-  // Read Temp on Mux0Temp2
-  rawtemp=0;
-  temp=0.0;
-  stat = Mux0Temp2.register16_read (&rawtemp);
-  if (stat != SUCCESS) Serial.printf("Mux0Temp2 error, stat=%u\r\n", stat);
-  temp = Mux0Temp2.raw12_to_f(rawtemp);
-  Serial.printf ("Mux0Temp2 %6.4f F\r\n", temp);
-
-  // ------------------------------
-  // Init Mux0Temp1 Sensors
-  stat = Mux0Temp1.init(TMP275_CFG_RES12);
-  if (SUCCESS != stat) Serial.printf(" Mux0Temp1 init failed with return of 0x%.2X: %s\r\n", Mux0Temp1.error.error_val);
-
-  // leave the pointer set to read temperature
-  stat = Mux0Temp1.pointer_write(TMP275_TEMP_REG_PTR);
-  if (SUCCESS != stat) Serial.printf(" Mux0Temp1 ptr write failed with return of 0x%.2X: %s\r\n", Mux0Temp1.error.error_val);
-
-  // Read Temp on Mux0Temp1
-  rawtemp=0;
-  temp=0.0;
-  stat = Mux0Temp1.register16_read (&rawtemp);
-  if (stat != SUCCESS) Serial.printf("Mux0Temp1 error, stat=%u\r\n", stat);
-  temp = Mux0Temp1.raw12_to_f(rawtemp);
-  Serial.printf ("Mux0Temp1 %6.4f F\r\n", temp);
+
+  // Init Mux1Temp1 Sensors
+  SensorPtr = &Mux1Temp1;
+  stat = sensor_read (SensorPtr);
+
+  SensorPtr = &Mux1Temp2;
+  stat = sensor_read (SensorPtr);
+
+  SensorPtr = &Mux1Temp3;
+  stat = sensor_read (SensorPtr);

@@ -438,3 +394,5 @@

+
+


LEDのサンプルコードを更新

LEDのサンプルコードを更新

--- libraries/Nefry/examples/Nefry_LED/Nefry_LED.ino
+++ libraries/Nefry/examples/Nefry_LED/Nefry_LED.ino
@@ -4,8 +4,15 @@
   Nefry.println("フルカラーLED!");
   randomSeed(analogRead(A0));
 }
+int red,green,blue;
 void loop() {
-  Nefry.setLed(random(255),random(255),random(255));//ランダムに点灯します。
-  Nefry.ndelay(1000);
+  red=random(255);//random関数は0-255の数値をランダムに返します。
+  green=random(255);
+  blue=random(255);
+  Nefry.setLed(red,green,blue);//LEDがランダムに点灯します。
+  String color="Red:";color+=red;
+  color+=" Green:";color+=green;
+  color+=" Blue:";color+=blue;
+  Nefry.println(color);//Nefry consoleで色を表示
+  Nefry.ndelay(1000);//1秒待つ
 }
-


rename Scanner_ShiftRegsPISOSingleRow to Scanner_ShiftRegsRead, Scanner_ShiftRegsPISOMultiRow to Scanner_ShiftRegsReadStrobed

--- examples/shiftRegs/sr4_keys/sr4_keys.ino
+++ examples/shiftRegs/sr4_keys/sr4_keys.ino
@@ -17,17 +17,17 @@
 #include <Row.h>

 //scanner
-#include <Scanner_ShiftRegsPISOMultiRow.h>
+#include <Scanner_ShiftRegsReadStrobed.h>

 // ============ SPEED CONFIGURATION ============
 ScanDelay scanDelay(9000);

 // ==================== ICs ====================
 // ---------------- LEFT SCANNER ---------------
-Scanner_ShiftRegsPISOMultiRow scanner_L(HIGH, 6, 1); //active HIGH, slave select 6, 1 byte
+Scanner_ShiftRegsReadStrobed scanner_L(HIGH, 6, 1); //active HIGH, slave select 6, 1 byte

 // ---------------- RIGHT SCANNER --------------
-Scanner_ShiftRegsPISOMultiRow scanner_R(HIGH, 7, 1); //active HIGH, slave select 7, 1 byte
+Scanner_ShiftRegsReadStrobed scanner_R(HIGH, 7, 1); //active HIGH, slave select 7, 1 byte

 // =================== CODES ===================
 // ---------------- SCAN CODES -----------------


whole code is divided into functions

whole code is divided into functions

--- examples/indentedCodeESPArd.ino
+++ examples/indentedCodeESPArd.ino
@@ -1,22 +1,32 @@
+#include <SoftwareSerial.h>
+#include <SoftReset.h>
+
 #define ard_rx_esp_tx 2
 #define ard_tx_esp_rx 3
 #define lightPin 1
-char response[725];
+
+SoftwareSerial ESPserial(ard_rx_esp_tx, ard_tx_esp_rx); // RX | TX
+
+char jSonBuffer[128];
 String api_key = "";
-#include <SoftwareSerial.h>
+char ivenCode[5];
+
+bool isOk();
+bool apiParse();
+bool ivenCodeParse();
+
+void returnSetup();
+void responseHandle();
+
+
 String jSonBody1 = "{\"data\":[{\"available\":true,\"at\":\"now\"}]}";
 String jSonBody2 = "{\"data\":[{\"available\":false,\"at\":\"now\"}]}";

 int sensorValue = 0;
-
-SoftwareSerial ESPserial(ard_rx_esp_tx, ard_tx_esp_rx); // RX | TX
-
-int i, j;
-int count = 0;
-
-void setup()
-{
-
+int i, j, index, count, arrayIndex;
+
+void setup() {
+  // put your setup code here, to run once:
   Serial.begin(9600);     // communication with the host computer
   while (!Serial);

@@ -28,183 +38,51 @@
   Serial.println(F("Ready"));
   Serial.println(F(""));
   Serial.println(F("start"));
-
-
-  delay(1000);
-
+  ESPserial.println("AT+CIPCLOSE");
+  long startTime = millis();
+  while (millis() - startTime < 5000) {
+    if (ESPserial.available()) char c = ESPserial.read();
+  }

 }
+
 void loop() {
   // put your main code here, to run repeatedly:
   if (api_key.length() == 0) {

     ESPserial.println(F("AT+CIPSTART=\"TCP\",\"demo.iven.io\",80"));
-    delay(1000);
-
-    i = 0;
-    while (ESPserial.available() ) {
-      response[i] = ESPserial.read();
-      i++;
-    }
-    response[i++] = '\0';
-    Serial.println(response);
-    for (i = 0; i < 725; i++) {
-      response[i] = '\0';
-    }
+    if (!isOk()) returnSetup();

     ESPserial.println(F("AT+CIPSEND=107"));
-    delay(1000);
-
-    i = 0;
-    while (ESPserial.available() ) {
-      response[i] = ESPserial.read();
-      i++;
-    }
-    response[i++] = '\0';
-    Serial.println(response);
-    for (i = 0; i < 725; i++) {
-      response[i] = '\0';
-    }
+    if (!isOk()) returnSetup();

     ESPserial.println(F("GET /activate/device HTTP/1.1"));
     ESPserial.println(F("Host: demo.iven.io"));
     ESPserial.println(F("Activation: b353165e8f54e6fbf5cfa4220b38b19a5f74defa"));
     ESPserial.println();
-
-
-    i = 0;
-    while (true) {
-      if (ESPserial.available()) {
-        response[i] = ESPserial.read();
-        i++;
-        if (i > 3) {
-          if (response[i - 4] == 'I' && response[i - 3] == 'P' && response[i - 2] == 'D' && response[i - 1] == ',') {
-            Serial.print("index is: ");
-            Serial.println(i);
-            i = 0;
-            if ( ESPserial.available()) response[i] = ESPserial.read();
-            i++;
-            if ( ESPserial.available()) response[i] = ESPserial.read();
-            i++;
-            if ( ESPserial.available()) response[i] = ESPserial.read();
-            i++;
-            if ( ESPserial.available()) response[i] = ESPserial.read();
-            i++;
-            response[i++] = '\0';
-            Serial.println(response);
-            sscanf(response, "%d", &j);
-            Serial.println(j);
-            i = 0;
-            response[0] = '\0';
-          }
-        }
-
-        if (i == j) {
-          response[i++] = '\0';
-          break;
-        }
-      }
-      //    if ( Serial.available() )    {
-      //      ESPserial.write( Serial.read() );
-      //    }
-    }
-    Serial.println(F("left loop"));
-    response[i++] = '\0';
-    Serial.println(F("Server response is: "));
-    Serial.println(response);
-    if (response[9] == '2' && response[10] == '0' && response[11] == '0')
-    {
-      Serial.println("parser response: ");
-      Serial.println(response);
-      delay(1000);
-      // read api key in response body
-      int index;
-      i = 0;
-      j = 0;
-      bool api = true;
-      while (api) {
-        if (response[i] == 'a' && response[i + 1] == 'p' && response[i + 2] == 'i' && response[i + 3] == '_' && response[i + 4] == 'k' && response[i + 5] == 'e' && response[i + 6] == 'y') {
-          api = false;
-        }
-        i++;
-      }
-
-      i += 9;
-      j = i;
-
-      while (response[j] != '"') {
-        j++;
-      }
-      Serial.println(i);
-      Serial.println(j);
-      Serial.println(response[i]);
-      Serial.println(response[j]);
-      for (index = i; index < j; index++) {
-        api_key += response[index];
-      }
-
-    } else {
-      Serial.print(F("Something went wrong, server response is: "));
-      Serial.println(response);
-    }
-
+    responseHandle();
+    Serial.println(jSonBuffer);
+
+    if (!apiParse()) returnSetup();
+    Serial.println(api_key);
+
   } else {

-    for (i = 0; i < 725; i++) {
-      response[i] = '\0';
-    }
-    Serial.println(F("done"));
-    Serial.print(F("API_KEY: "));
-    Serial.println(api_key);
-    delay(1000);
-
-
     ESPserial.println("AT+CIPCLOSE");
-    delay(1000);
-    i = 0;
-    while (ESPserial.available() ) {
-      response[i] = ESPserial.read();
-      i++;
-    }
-    response[i++] = '\0';
-    Serial.println(response);
-    for (i = 0; i < 725; i++) {
-      response[i] = '\0';
-    }
-
+    long startTime = millis();
+    while (millis() - startTime < 3000) {
+      if (ESPserial.available()) char c = ESPserial.read();
+    }

     ESPserial.println(F("AT+CIPSTART=\"TCP\",\"demo.iven.io\",80"));
-    delay(1000);
-
-    i = 0;
-    while (ESPserial.available() ) {
-      response[i] = ESPserial.read();
-      i++;
-    }
-    response[i++] = '\0';
-    Serial.println(response);
-    for (i = 0; i < 725; i++) {
-      response[i] = '\0';
-    }
-
+    if (!isOk()) returnSetup();

     sensorValue = analogRead(lightPin);

     if (sensorValue < 250) {

       ESPserial.println(F("AT+CIPSEND=257"));
-      delay(1000);
-
-      i = 0;
-      while (ESPserial.available() ) {
-        response[i] = ESPserial.read();
-        i++;
-      }
-      response[i++] = '\0';
-      Serial.println(response);
-      for (i = 0; i < 725; i++) {
-        response[i] = '\0';
-      }
+      if (!isOk()) returnSetup();

       ESPserial.println(F("POST /data HTTP/1.1"));
       ESPserial.println(F("Host: demo.iven.io"));
@@ -222,18 +100,7 @@
     } else {

       ESPserial.println(F("AT+CIPSEND=258"));
-      delay(1000);
-
-      i = 0;
-      while (ESPserial.available() ) {
-        response[i] = ESPserial.read();
-        i++;
-      }
-      response[i++] = '\0';
-      Serial.println(response);
-      for (i = 0; i < 725; i++) {
-        response[i] = '\0';
-      }
+      if (!isOk()) returnSetup();

       ESPserial.println(F("POST /data HTTP/1.1"));
       ESPserial.println(F("Host: demo.iven.io"));
@@ -249,53 +116,169 @@
       ESPserial.println(jSonBody2);

     }
+
+    responseHandle();
+    Serial.println(jSonBuffer);
+
+    if (!ivenCodeParse()) returnSetup();
+
+  }
+}
+
+  bool isOk() {
+
+    int readCount = 0;
+    long startTime = millis();
+    while (millis() - startTime < 4000) { // Run for at least 5 seconds
+      // Check to make sure we don't exceed espBuffer's boundaries
+      if (ESPserial.available() > readCount + sizeof(jSonBuffer) - 1)
+        break;
+      readCount += ESPserial.readBytes(jSonBuffer + readCount, ESPserial.available());
+    }
+    readCount = 0;
+    while (jSonBuffer[readCount] != '\0') {
+      if (jSonBuffer[readCount] == 'O' && jSonBuffer[readCount + 1] == 'K') {
+        Serial.println("is ok");
+        for (i = 0; i < 128; i++) {
+          jSonBuffer[i] = '\0';
+        }
+        return true;
+      }
+      readCount++;
+    }
+    return false;
+  }
+
+  void returnSetup() {
+    delay(1000);
+    Serial.println("resetting");
+    ESPserial.println("AT+RST");
+    long startTime = millis();
+    while (millis() - startTime < 5000) {
+      if (ESPserial.available()) char c = ESPserial.read();
+    }
+    delay(2000);
+    soft_restart();
+  }
+
+  void responseHandle() {
     i = 0;
-    while (true) {
+    long startTime = millis();
+    while (millis() - startTime < 15000) {
       if (ESPserial.available()) {
-        response[i] = ESPserial.read();
-        i++;
-        if (i > 3) {
-          if (response[i - 4] == 'I' && response[i - 3] == 'P' && response[i - 2] == 'D' && response[i - 1] == ',') {
-            Serial.print("index is: ");
-            Serial.println(i);
+        jSonBuffer[i] = ESPserial.read();
+        if (i > 1) {
+          if (jSonBuffer[i - 2] == '2' && jSonBuffer[i - 1] == '0' && jSonBuffer[i] == '0') {
             i = 0;
-            if ( ESPserial.available()) response[i] = ESPserial.read();
-            i++;
-            if ( ESPserial.available()) response[i] = ESPserial.read();
-            i++;
-            if ( ESPserial.available()) response[i] = ESPserial.read();
-            i++;
-            if ( ESPserial.available()) response[i] = ESPserial.read();
-            i++;
-            response[i++] = '\0';
-            Serial.println(response);
-            sscanf(response, "%d", &j);
-            Serial.println(j);
+            while (!(jSonBuffer[i - 4] == '\r' && jSonBuffer[i - 3] == '\n' && jSonBuffer[i - 2] == '\r' && jSonBuffer[i - 1] == '\n')) {
+              if (ESPserial.available()) {
+                jSonBuffer[i] = ESPserial.read();
+                jSonBuffer[i + 1] = '\0';
+                i++;
+                i %= 120;
+              }
+            }
             i = 0;
-            response[0] = '\0';
+            jSonBuffer[4] = '\0';
+            jSonBuffer[5] = '\0';
+            while (i != 4) {
+              if (ESPserial.available()) {
+                jSonBuffer[i] = ESPserial.read();
+                i++;
+              }
+            }
+            Serial.println(jSonBuffer);
+            j = strtoul(jSonBuffer, 0, 16);
+            i = 0;
+            while (i != j) {
+              if (ESPserial.available()) {
+                jSonBuffer[i] = ESPserial.read();
+                i++;
+              }
+            }
+            for (index = j; index < 128; index++) {
+              jSonBuffer[j] = '\0';
+            }
+            break;
           }
         }
-
-        if (i == j) {
-          response[i++] = '\0';
-          break;
-        }
-      }
-    }
-    response[i++] = '\0';
-    Serial.println(response);
-    if (response[9] == '2' && response[10] == '0' && response[11] == '0') {
+        i++;
+        i %= 100;
+      }
+    }
+  }
+
+  bool apiParse() {
+    i = 0;
+    j = 0;
+    bool api = false;
+    long startTime = millis();
+    while (millis() - startTime < 5000) {
+      if (jSonBuffer[i] == 'a' && jSonBuffer[i + 1] == 'p' && jSonBuffer[i + 2] == 'i' && jSonBuffer[i + 3] == '_' && jSonBuffer[i + 4] == 'k' && jSonBuffer[i + 5] == 'e' && jSonBuffer[i + 6] == 'y') {
+        api = true;
+        break;
+      }
+      i++;
+    }
+
+    i += 10;
+    j = i;
+
+    while (jSonBuffer[j] != '"') {
+      j++;
+    }
+
+    for (index = i; index < j; index++) {
+      api_key += jSonBuffer[index];
+    }
+
+    for (i = 0; i<128; i++) {
+      jSonBuffer[i] = '\0';
+    }
+    return api;
+  }
+
+  bool ivenCodeParse() {
+    i = 0;
+    j = 0;
+    arrayIndex = 0;
+    bool code = false;
+    long startTime = millis();
+    while (millis() - startTime < 5000) {
+      if (jSonBuffer[i] == 'i' && jSonBuffer[i + 1] == 'v' && jSonBuffer[i + 2] == 'e' && jSonBuffer[i + 3] == 'n' && jSonBuffer[i + 4] == 'C' && jSonBuffer[i + 5] == 'o' && jSonBuffer[i + 6] == 'd' && jSonBuffer[i + 7] == 'e') {
+        code = true;
+        break;
+      }
+      i++;
+    }
+
+    i += 10;
+    j = i;
+
+    while (jSonBuffer[j] != '}') {
+      j++;
+    }
+
+    for (index = i; index < j; index++) {
+      ivenCode[arrayIndex] = jSonBuffer[index];
+      arrayIndex++;
+    }
+    ivenCode[arrayIndex] = '\0';
+
+    if (ivenCode[0] == '1' && ivenCode[1] == '0' && ivenCode[2] == '0' && ivenCode[3] == '0') {
       count++;
-      Serial.println("Response is 200");
-      Serial.print("Count is: ");
+      Serial.print("Iven Code: ");
+      Serial.println(ivenCode);
+      Serial.print("Succesful count: ");
       Serial.println(count);
-    }
-    delay(5000);
-
-
-
-  }
-
-}
-
-
+    } else {
+      Serial.print("Iven Code: ");
+      Serial.println(ivenCode);
+    }
+
+     for (i = 0; i<128; i++) {
+      jSonBuffer[i] = '\0';
+    }
+    return code;
+
+  }


Abort if there are problems with the SD Card.

If there are problems opening the SD card for access then there's no
point continuing as we can't cache the data.

Slightly controversially, I've chosen the bump the error codes (number
of LED flashes) of a DHCP failure and cache failure.  I don't think this
is too much of a problem, partcularly because I've bumped the version
number.

--- printer.ino
+++ printer.ino
@@ -39,7 +39,7 @@

 // -- Everything below here can be left alone

-const char* sketchVersion = "1.0.3";
+const char* sketchVersion = "1.0.4";

 // -- Debugging

@@ -113,7 +113,10 @@

 inline void initSD() {
   pinMode(SD_Pin, OUTPUT);
-  SD.begin(SD_Pin);
+  if (!SD.begin(SD_Pin)) {
+    // SD Card failure.
+    terminalError(2);
+  }
 }

@@ -124,7 +127,7 @@
   // start the Ethernet connection:
   if (Ethernet.begin(mac) == 0) {
     // DHCP Failure
-    terminalError(2);
+    terminalError(3);
   }
   delay(1000);
   // print your local IP address:
@@ -164,7 +167,7 @@
   if (SD.exists(cacheFilename)) {
     if (!SD.remove(cacheFilename)) {
       // Failed to clear cache.
-      terminalError(3);
+      terminalError(4);
     }
   }
   File cache = SD.open(cacheFilename, FILE_WRITE);


Major commenting effort

Major commenting effort

--- code/lissajous/lissajous.ino
+++ code/lissajous/lissajous.ino
@@ -1,46 +1,58 @@
-// Sweep
+// This is based on Sweep
 // by BARRAGAN <http://barraganstudio.com>
-// This example code is in the public domain.

 #include <Servo.h>

-Servo servox;  // create servo object to control a servo
-Servo servoy; // a maximum of eight servo objects can be created
+// Create the servo objects
+Servo servox;
+Servo servoy;

-double pos = 0;    // variable to store the servo position
-float spd = 0.005;
-float facter = 1.0;
-float starter = 0;
-int adjx = 90;
-int adjy = 90;
-float decay = 60000;
+double pos = 0; // Position incrementer
+float spd = 0.005; // This value seems to work for reasonable speed.
+float facter = 1.0; // Ratio between servox and servoy periods.
+float starter = 0; // Starting position offset between the servos.
+int adjx = 90; // Position of servox
+int adjy = 90; // Position of servoy
+float decay = 60000; // Gives the amount of steps to run on. Higher gives a slower decay.

 void setup()
 {
   servox.attach(9);  // attaches the servo on pin 9 to the servo object
   servoy.attach(10);  // attaches the servo on pin 10 to the servo object
-  pinMode(2, INPUT_PULLUP);
-  randomSeed(analogRead(0));
+  pinMode(2, INPUT_PULLUP); // Starting button input
+  randomSeed(analogRead(0)); // Just seed with a random value
 }

 void loop()
 {
+
+  // Wait for a button press.
   while (digitalRead(2) != 0)
   {
+    // Keep generating random values. Only on button press do we lock in the values.
+    facter = random(1001, 1021)/1000.0;
+    starter = random(3141)/1000.0;
     delay(10);
-    facter = random(2001, 2021)/1000.0;
-    starter = random(3141)/1000.0;
   }
-  for(pos = 0; pos < decay*0.9; pos += 1)
+
+  // Main loop, to 90% decay.
+  for(pos = 0; pos < decay*0.9; pos += 1)
   {
+    // Adjx just gives me a nice sine wave
     adjx = int(90 + int(70 * (1 - pos/decay) * sin(pos * spd)));
+
+    // Also a sinewave, with offsets and different period.
     adjy = int(90 + int(70 * (1 - pos/decay) * sin(starter + (pos * spd * facter))));
+
+    // Get the values to the servos.
     servox.write(adjx);
     servoy.write(adjy);
-    delay(1);                       // waits 15ms for the servo to reach the position
+    delay(1); // Just for consistent speed.
   }
+
+  // Return to center after drawing.
   servox.write(90);
   servoy.write(90);
 }


one more fix to the url in the comments

one more fix to the url in the comments

--- temp_only.ino
+++ temp_only.ino
@@ -16,7 +16,7 @@
 // Edited by John Keefe for DHT22 only
 // June 2015
 // Get the full library, including the dht.h file at the URL above
-// More info at http://johnkeefe.net/make-every-week-temperature-taker
+// More info at http://johnkeefe.net/make-every-week-taking-temperature

 #include <dht.h>


Remove old ESP32 example

Remove old ESP32 example

--- examples/Boards_WiFi/ESP32/ESP32.ino
+++ examples/Boards_WiFi/ESP32/ESP32.ino
@@ -1,52 +0,0 @@
-/**************************************************************
- * Blynk is a platform with iOS and Android apps to control
- * Arduino, Raspberry Pi and the likes over the Internet.
- * You can easily build graphic interfaces for all your
- * projects by simply dragging and dropping widgets.
- *
- *   Downloads, docs, tutorials: http://www.blynk.cc
- *   Blynk community:            http://community.blynk.cc
- *   Social networks:            http://www.fb.com/blynkapp
- *                               http://twitter.com/blynk_app
- *
- * Blynk library is licensed under MIT license
- * This example code is in public domain.
- *
- **************************************************************
- * This example runs directly on ESP32 chip.
- *
- * You need to install this for ESP32 development:
- *   https://github.com/espressif/arduino-esp32
- *
- * Please be sure to select the right ESP32 module
- * in the Tools -> Board menu!
- *
- * Change WiFi ssid, pass, and Blynk auth token to run :)
- *
- **************************************************************/
-
-#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
-#include <WiFi.h>
-#include <WiFiClient.h>
-#include <BlynkSimpleEsp32.h>
-
-// You should get Auth Token in the Blynk App.
-// Go to the Project Settings (nut icon).
-char auth[] = "YourAuthToken";
-
-// Your WiFi credentials.
-// Set password to "" for open networks.
-char ssid[] = "YourNetworkName";
-char pass[] = "YourPassword";
-
-void setup()
-{
-  Serial.begin(9600);
-  Blynk.begin(auth, ssid, pass);
-}
-
-void loop()
-{
-  Blynk.run();
-}
-


Improved magnitude impact on hue, cap max BPMs

Also lower brightness to avoid interfering with sensor data too much

--- heartbeat_with_pulse.ino
+++ heartbeat_with_pulse.ino
@@ -33,22 +33,22 @@
 Bounce modeButton;

 // config
-int staticBpm = 70; // From http://ecg.utah.edu/img/items/Normal%2012_Lead%20ECG.jpg
-byte beat[]  = {3,2,2,2,2,3,4,3,2,1,0,15,2,2,3,4,6,8,5,3,3,3};
+int staticBpm = 60; // From http://ecg.utah.edu/img/items/Normal%2012_Lead%20ECG.jpg
+int maxBpm = 180; // avoids the system going crazy
 byte beat[]  = {2,2,2,2,3,4,3,2,1,0,12,2,2,3,4,6,8,5,3,3,3,3};
 byte beatLength = 22;
-int movesPerBeat = 8;
-int minMagnitude = 80;
-int maxMagnitude = 150;
-int minBrightness = 180; // from 0-255
-int maxBrightness = 255; // from 0-255
-int beatMaxIntensity = max(beat);
-int minHue = 160; // hue value under low motion
-int maxHue = 255; // hue value under high motion
-int gainRatePerBeat = 200; // value change towards new target value (percent*100 per beat, e.g 200 = 20%)
-int decayRatePerBeat = 3  ; // percent change towards new target per beat
+int beatMaxIntensity = 12; // max value in beat array
+int movesPerBeat = 4;
+int minMagnitude = 0;
+int maxMagnitude = 50; // max difference between two magnitude measurements from accelerometer at which we show maxHue
+int minBrightness = 150; // from 0-255
+int maxBrightness = 200; // from 0-255
+int minHue = 160; // hue value under low motion, as defined through minMagnitude (from 0-255)
+int maxHue = 255; // hue value under high motion, as defined through maxMagnitude (from 0-255)
+int gainRatePerBeat = 6; // change towards new target magnitude
+int decayRatePerBeat = 2; // move back towards minMagnitude
 int sampleSize = 8; // smooth out accelerometer readings
-int samplePerBeat = 2;
+int samplePerBeat = 1;

 // state
 int bpm = staticBpm;
@@ -136,19 +136,19 @@
     adjustedMagnitude,
     minMagnitude,
     maxMagnitude,
-    3,
-    1
+    400,
+    200
   );
-
+
   // Channel 1
   for (i=0;i<NUM_LEDS_CH1;i++){
-      leds1[i] = CHSV(hue, bufr[i], bufr[i]/brightnessFactor);
+      leds1[i] = CHSV(hue, bufr[i], bufr[i]/(brightnessFactor/100));
   }

   // Channel 2
   int halfPoint = (int)sizeof(bufr)/2;
   for (i=0;i<NUM_LEDS_CH2;i++){
-      leds2[i] = CHSV(hue, bufr[halfPoint], bufr[halfPoint]/brightnessFactor);
+      leds2[i] = CHSV(hue, bufr[halfPoint], bufr[halfPoint]/(brightnessFactor/100));
   }

   FastLED.show();
@@ -168,7 +168,7 @@
   if(adjustedMagnitude <= targetMagnitude) {
     adjustedMagnitude = constrain(
       constrain(
-        targetMagnitude + (targetMagnitude*(gainRatePerBeat/100)),
+        targetMagnitude + gainRatePerBeat,
         minMagnitude,
         maxMagnitude
       ),
@@ -178,7 +178,7 @@
   } else {
     adjustedMagnitude = constrain(
       constrain(
-        targetMagnitude - (targetMagnitude*(gainRatePerBeat/100)),
+        targetMagnitude - gainRatePerBeat,
         minMagnitude,
         maxMagnitude
       ),
@@ -188,12 +188,13 @@
   }

   // Slowly decay max target
+  targetMagnitude = targetMagnitude - decayRatePerBeat;
   targetMagnitude = constrain(
-    targetMagnitude - (targetMagnitude*(decayRatePerBeat/100)),
+    targetMagnitude,
     minMagnitude,
     maxMagnitude
   );
-//
+
 //  Serial.print(magnitudeDiff);
 //  Serial.print("\t");
 //  Serial.print(targetMagnitude);
@@ -225,7 +226,7 @@
   offset = (offset + 1) % beatLength;

 //  serialOutput();
-  if (pulseFound == true) {
+  if (pulseFound == true && bpm <= maxBpm) {
 //    serialOutputWhenBeatHappens();
     bpm = pulseBpm;
     digitalWrite(CTRL_LED_RED_PIN, HIGH);
@@ -249,7 +250,7 @@
     draw();
   }

-  // Mesure only a few times per beat to avoid slowdowns
+  // Measure only a few times per beat to avoid slowdowns
   if(offset % round(beatLength/samplePerBeat) == 0) {
     calcAdjustedMagnitude();
   }


Nodes are now automatically registered

Nodes are now automatically registered

--- src/homie-sonoff-touch.ino
+++ src/homie-sonoff-touch.ino
@@ -140,8 +140,6 @@
   Homie.setResetTrigger(PIN_BUTTON, LOW, 30000);
   Homie.setLoopFunction(loopHandler);
   // FIXME relayNode.subscribe("relayState", RelayHandler);
-  // FIXME Homie.registerNode(relayNode);
-  // FIXME Homie.registerNode(buttonNode);
   Homie.setup();
 }


LpgSerial test with simple manual

LpgSerial test with simple manual

--- tests/LpgSerial/LpgSerial.ino
+++ tests/LpgSerial/LpgSerial.ino
@@ -160,7 +160,7 @@

     }

-    boolean isAvalible() {
+    boolean isAvailable() {
         return isReceive;
     }

@@ -169,7 +169,7 @@
         // Save captured data
         saveData();

-        if (isAvalible()) {
+        if (isAvailable()) {
             verify();
         }

@@ -205,7 +205,7 @@
     if (loopCounter % 1000 == 0) {
         Serial.print(" Loop offset ");
         Serial.print(loopCounter);
-        if (lpg.isAvalible()) {
+        if (lpg.isAvailable()) {

             Serial.print(" / ");
             Serial.print(lpg.getData(0), BIN);


Update template_gisgk.ino

Update template_gisgk.ino

Bugfix: UV-Index was ignored when uploading measurements

--- files/template_gisgk/template_gisgk.ino
+++ files/template_gisgk/template_gisgk.ino
@@ -131,7 +131,7 @@
         break;
       case 6:
         uvValue = analogRead(UVPIN);
-        sensorSample = (String)uvValue;
+        sensorSample = (String)calcUVIndex(uvValue);
         currentSensorId = UVSENSOR_ID;
         break;
     }
@@ -215,7 +215,7 @@
     Serial.println("done!");
     uploadSuccess = true;
     //Change case
-    if (sampleType == 5) {
+    if (sampleType == 6) {
       sampleType = 1;
       // remember the time that the connection was made or attempted
       lastConnectionTime = millis();


Adapt the code to ActiveMQ.

Adapt the code to ActiveMQ.

--- Industruino-stomp/Industruino-stomp.ino
+++ Industruino-stomp/Industruino-stomp.ino
@@ -10,7 +10,8 @@
 #define LOGIN    " "
 #define PASSCODE " "
 #define PORT     61613
-#define TOPIC    "/topic/heart"
+#define TOPIC    "/topic/PITopic"
+#define QUEUE    "/queue/Industruino"
 #define ZEROBYTE (uint8_t)0x00

 // Constants for STOMP
@@ -76,7 +77,7 @@
 // Loop
 void loop()
 {
-  int    start;
+  // int    start;
   String body;
   String frame;
   String response;
@@ -118,17 +119,17 @@
     client.print( "id:" );
     client.println( session );
     client.print( "destination:" );
-    client.println( TOPIC );
+    client.println( QUEUE );
     client.println( "receipt:subscribed" );
     client.println();
     client.write( ZEROBYTE);

-    // Subscribing to topic
-    Serial.println( "Subscribing to topic..." );
+    // Subscribing to queue
+    Serial.println( "Subscribing to queue..." );
     state = SUBSCRIBING;
   } else if( state == SUBSCRIBED ) {
     counter = counter + 1;
-    body = String( counter );
+    body = "{\"deviceID\": \"Industruino\", \"text\": \"Hello\"}";

     client.println( "SEND" );
     client.print( "destination:" );
@@ -150,9 +151,11 @@
     client.println( "DISCONNECT" );
     client.print( "receipt:disconnect-" );
     client.println( body );
+    client.println();
     client.write( ZEROBYTE);

     state = DISCONNECTING;
+    lcd.setCursor(0, 7); lcd.clearLine(); lcd.print("Disconnecting..." );
     Serial.println( "Disconnecting..." );
   }

@@ -166,10 +169,12 @@
     Serial.println( ") ***" );
     Serial.println( response );
     Serial.println( "*** Response End ***" );
+    lcd.setCursor(0, 5); lcd.clearLine(); lcd.print("Received: "); lcd.print(response.length());

     if( response.length() > 0 )
     {
       frame = getValue( response, 0, "\n" );
+      lcd.setCursor(0, 6); lcd.clearLine(); lcd.print(frame);

       if( frame == "CONNECTED" )
       {
@@ -191,16 +196,19 @@
         {
           state = SUBSCRIBED;
           Serial.println( "Subscribed." );
+          lcd.setCursor(0, 7); lcd.clearLine(); lcd.print("Subscribed...");
         } else if( state == SENDING ) {
           state = SENT;
           Serial.println( "Sent." );

+          lcd.setCursor(0, 7); lcd.clearLine(); lcd.print("Sent...");
           delay( 1000 );
         } else if( state == DISCONNECTING ) {
           Serial.println( "Disconnected." );

           client.stop();
           Serial.println( "Connection closed." );
+          lcd.setCursor(0, 7); lcd.clearLine(); lcd.print("DONE");
           state = STOP;
         }
       }


add comments

add comments

--- TClab/TClab_Firmware/TClab_Firmware.ino
+++ TClab/TClab_Firmware/TClab_Firmware.ino
@@ -137,7 +137,7 @@

 // update LED
 void LEDUpdate(void) {
-  // find led status
+  // determine led status
   ledStatus = brdStatus;
   if ((Q1 > 0) or (Q2 > 0)) {
     ledStatus = 2;
@@ -149,23 +149,23 @@
     }
   }
   // update led depending on ledStatus
-  if (ledStatus == 0) {
+  if (ledStatus == 0) {               // board is off, no alarms, reset required
     analogWrite(pinLED1, 0);
   }
-  else if (ledStatus == 1) {
+  else if (ledStatus == 1) {          // normal operation with heaters off
     analogWrite(pinLED1, loLED);
   }
-  else if (ledStatus == 2) {
+  else if (ledStatus == 2) {          // normal operation with one or both heaters on
     analogWrite(pinLED1, hiLED);
   }
-  else if (ledStatus == 3) {
+  else if (ledStatus == 3) {          // high temperature alarm with heater off
     if ((millis() % 2000) > 1000) {
       analogWrite(pinLED1, loLED);
     } else {
       analogWrite(pinLED1, 0);
     }
   }
-  else if (ledStatus == 4) {
+  else if (ledStatus == 4) {          // hight temperature alarm with either heater on
     if ((millis() % 2000) > 1000) {
       analogWrite(pinLED1, hiLED);
     } else {


added time display for both lanes; added leader display

--- Display.ino
+++ Display.ino
@@ -17,9 +17,24 @@
   lcd.clear();
 }

-void displayLaps() {
-  lcd.setCursor(1, 1); // col 1 or 9
-  lcd.printCustomChar(1);
+void displayUpdate() {
+  displayLaps();
+  displayLeader();
+  displayTimes();
+}
+
+inline void displayLeader() {
+  if (leader == 0) {
+    lcd.setCursor(1, 1);
+  } else if (leader == 1) {
+    lcd.setCursor(1, 9);
+  }
+  if (leader < LANES) {
+    lcd.printCustomChar(1);
+  }
+}
+
+inline void displayLaps() {
   lcd.setCursor(1, 2);
   sprintf(buf, "%2d", lap[0]);
   lcd.print(buf);
@@ -29,15 +44,14 @@
 }

-void displayTimes() {
-
+inline void displayTimes() {
   lcd.selectLine(2);
   lcd.setCursor(2, 2);

   cvTenthsToBuf(elapsed);
   lcd.print(buf);
   lcd.setCursor(2, 10);
-  lcd.print("99:99.9");
+  lcd.print(buf);
 }


Acquire Apparent Power

Acquire Apparent Power

--- TeleInfo/Tx_Node_TeleInfo/Tx_Node_TeleInfo.ino
+++ TeleInfo/Tx_Node_TeleInfo/Tx_Node_TeleInfo.ino
@@ -28,7 +28,7 @@
 SoftwareSerial _edfLine(rxSerialPin, txSerialPin); // rx, tx pins

 void setup() {
-  Serial.begin(9600);
+  Serial.begin(57600);

   _edfLine.begin(1200);

@@ -43,7 +43,7 @@

 /*
 *
- * Read Temp
+ * Acquire Apparent Power
  *
  */
 boolean acquireApparentPower()
@@ -53,67 +53,75 @@
   char current;
   char buffer[50];

+  // Clear buffer
+  buffer[0] = '\0';
+
   while(!exit)
   {
-    // Read
-    current = _edfLine.read();
+    // Wait a Char
+    if(_edfLine.available())
+    {
+      // Read
+      current = _edfLine.read();

-    // Check Value
-    if(current>0)
-    {
       // Clean Value
       current &=0x7F;
-
+
       // Display Raw
-      Serial.print("Raw :<");
-      Serial.write(current);
-      Serial.println('>');
+      //Serial.print("Raw :<"); Serial.write(current); Serial.println('>'); Serial.println(current,HEX);

       // Split String between LF and CR
-      if(current==0x0A)
+      if (current==0x0A)
       {
         // Begin new Information Line
-
+
         // Turn Flag
         insideLine = true;
-
+
         // Clear buffer
         buffer[0] = '\0';
       }
-      else if(current==0x0D)
+      else if (current==0x0D)
       {
         // End of Information Line
-
+
         // Turn Off Flag
         insideLine = false;
-
-        // TODO Analyse Line
-        Serial.print("Data :");Serial.println(buffer);
+
+        //Serial.print("Data : <"); Serial.print(buffer); Serial.println(">");
+
+        char * papp;
+        papp = strstr (buffer,"PAPP");
+
+        if(papp!=NULL)
+        {
+          // Remove CheckSum
+          papp[10] = '\0';
+
+          Serial.print("PAPP = <"); Serial.print(papp); Serial.println(">");
+
+          // Convert to Float
+          float value = atof(papp+5);
+
+          Serial.print("PAPP = <"); Serial.print(value); Serial.println(">");
+        }
+
       }
       else
       {
         // Data
         if(insideLine)
         {
-           // Add Char
-          strncpy (buffer, &current, 1);
+          // Add Char
+          strncat(buffer, &current, 1);
         }
       }
+    }
+  }

-
-
-    }
-
-
-
-  }
+}

-
-
-}
-
-


Delete config.ino

Delete config.ino

--- OpenEnergyMonitor/emonTX/config.ino
+++ OpenEnergyMonitor/emonTX/config.ino
@@ -1,124 +0,0 @@
-// create as a tab in emontx3-30.ino or as config.ino in same folder
-
-#include <EEPROM.h>
-
-byte value;
-
-static void load_config(){
-
-  byte flag=0;
-  // Read nodeID
-  if (EEPROM.read(0) != 255){                                // 255 = EEPROM default (blank) value
-    nodeID = EEPROM.read(0);
-    flag++;
-  }
-  if (EEPROM.read(1) != 255){
-    RF_freq = EEPROM.read(1);
-    flag++;
-  }
-  if (EEPROM.read(2) != 255){
-    networkGroup = EEPROM.read(2);
-    flag++;
-  }
-
-  if (flag > 0){
-    Serial.println("Loaded EEPROM RF config >");
-  }
-  else {
-    Serial.println("No EEPROM config");
-  }
-
-  }
-
-static void config (char c) {
-
-  if ('0' <= c && c <= '9') {
-    value = 10 * value + c - '0';
-    return;
-  }
-
-  if (c > ' ') {
-
-    switch (c) {
-
-      case 'i': //set node ID
-        if (value){
-          nodeID = value;
-        break;
-      }
-
-      case 'b': // set band: 4 = 433, 8 = 868, 9 = 915
-        value = bandToFreq(value);
-        if (value){
-          RF_freq = value;
-        }
-        break;
-
-      case 'g': // set network group
-        if (value>=0){
-          networkGroup = value;
-        }
-        break;
-
-      case 's': // Save to EEPROM. Atemga328p has 1kb  EEPROM
-        save_config();
-        break;
-
-      case 'v': // print firmware version
-        Serial.print(F("[emonTx FW: V")); Serial.print(version*0.1); Serial.print(F("]"));
-        break;
-
-      default:
-        showString(helpText1);
-      } //end case
-
-    //Print Current RF config
-    if (RF_STATUS==1) {
-      Serial.print(F(" "));
-      // Serial.print((char) ('@' + (nodeID & RF12_HDR_MASK)));
-      Serial.print(F(" i"));
-      Serial.print(nodeID & RF12_HDR_MASK);
-      Serial.print(F(" g"));
-      Serial.print(networkGroup);
-      Serial.print(F(" @ "));
-      Serial.print(RF_freq == RF12_433MHZ ? 433 :
-                   RF_freq == RF12_868MHZ ? 868 :
-                   RF_freq == RF12_915MHZ ? 915 : 0);
-      Serial.print(F(" MHz"));
-    }
-
-    Serial.print(F(" USA ")); Serial.print(USA);
-    Serial.println(F(" "));
-
-  } // end c > ' '
-  value = 0;
-
-}
-
-static void save_config(){
-  Serial.println("Saving...");
-  // Clear any old EEPROM settings
-  for (int i = 0 ; i < EEPROM.length() ; i++) {
-    EEPROM.write(i, 0);
-  }
-  //Save new settings
-  EEPROM.write(0, nodeID);
-  EEPROM.write(1, RF_freq);
-  EEPROM.write(2, networkGroup);
-  Serial.println("Done. New config saved to EEPROM");
-}
-
-static byte bandToFreq (byte band) {
-  return band == 4 ? RF12_433MHZ : band == 8 ? RF12_868MHZ : band == 9 ? RF12_915MHZ : 0;
-}
-
-static void showString (PGM_P s) {
-  for (;;) {
-    char c = pgm_read_byte(s++);
-    if (c == 0)
-      break;
-    if (c == '\n')
-      Serial.print('\r');
-    Serial.print(c);
-  }
-}


minor change in v0.21 - eeprom values to uint8_t  * changes in version 0.21:            * store settings in eeprom            * changing defaults to HVAC OFF (from HEATING)            * updating the blynk cloud periodically            * added in the blynk app the state of the thermostat (also published in the particle cloud)            * here is the link for cloning the blynk app http://tinyurl.com/zq9lcef            * changed all eeprom values to uint8_t to save space and bytes written              this saves eeprom pages to be written more often than needed              (for instance a float takes 4 bytes and an uint8_t takes only 1)

--- minimalistthermostat.ino
+++ minimalistthermostat.ino
@@ -89,6 +89,9 @@
            * updating the blynk cloud periodically
            * added in the blynk app the state of the thermostat (also published in the particle cloud)
            * here is the link for cloning the blynk app http://tinyurl.com/zq9lcef
+           * changed all eeprom values to uint8_t to save space and bytes written
+             this saves eeprom pages to be written more often than needed
+             (for instance a float takes 4 bytes and an uint8_t takes only 1)

 TODO:
   * add multi thread support for photon: SYSTEM_THREAD(ENABLED);
@@ -289,13 +292,13 @@
 *******************************************************************************/
 //randomly chosen value here. The only thing that matters is that it's not 255
 // since 255 is the default value for uninitialized eeprom
-// I used 137 in version 0.21 already
-#define EEPROM_VERSION 138
+// I used 137 and 138 in version 0.21 already
+#define EEPROM_VERSION 139
 #define EEPROM_ADDRESS 0

 struct EepromMemoryStructure {
   uint8_t version = EEPROM_VERSION;
-  float targetTemp;
+  uint8_t targetTemp;
   uint8_t internalFan;
   uint8_t internalMode;
 };
@@ -1330,7 +1333,7 @@
   // data just read with the previous EEPROM.get() is invalid and we will ignore it
   if ( myObj.version == EEPROM_VERSION ) {

-    targetTemp = myObj.targetTemp;
+    targetTemp = float( myObj.targetTemp );
     newTargetTemp = targetTemp;

     internalMode = convertIntToMode( myObj.internalMode );
@@ -1380,7 +1383,7 @@

   //store thresholds in the struct type that will be saved in the eeprom
   eepromMemory.version = EEPROM_VERSION;
-  eepromMemory.targetTemp = targetTemp;
+  eepromMemory.targetTemp = uint8_t(targetTemp);
   eepromMemory.internalMode = convertModeToInt(internalMode);

   eepromMemory.internalFan = 0;


debug of scale

debug of scale

--- _03-hx711-scale/_03-hx711-scale-v3-adaptor/_03-hx711-scale-pro-mini/_03-hx711-scale-pro-mini.ino
+++ _03-hx711-scale/_03-hx711-scale-v3-adaptor/_03-hx711-scale-pro-mini/_03-hx711-scale-pro-mini.ino
@@ -4,7 +4,7 @@

 HX711 scale(A0, A1);

-#define DEBUG_OUT 1
+#define DEBUG_OUT 0

 const int nemoisonPin = 9;
 volatile int measured = 0;
@@ -24,7 +24,7 @@
   pinMode(nemoisonPin, OUTPUT);
   digitalWrite(nemoisonPin, LOW);

-  delay(1000);
+  delay(5000);

   scale.set_scale(23040.f);
   scale.tare();
@@ -36,16 +36,29 @@

 void loop()
 {
-  measured = int( scale.get_units(10) * 1000 );
+  if ( DEBUG_OUT ) {
+    Serial.print((millis() - startMills) * 0.001, 2);
+    Serial.print("\t: ");
+  }
+
+  float fmeasured = scale.get_units(10) ;
+  measured = int(fmeasured * 1000) ;

   if ( DEBUG_OUT ) {
-    Serial.print((millis() - startMills) * 0.001, 2);
-    Serial.print(" : ");
+    Serial.print(fmeasured, 5);
+    Serial.print("\t: ");
+    Serial.print(measured);
+  }
+
+  if (( measured < 0 ) || ( measured > 7000 )) {
+    measured = 0;
+  }
+
+  if ( DEBUG_OUT ) {
+    Serial.print("\t:\t");
     Serial.println(measured);
   }
-
-  if (( measured < 0 ) || ( measured > 7000 )){ measured = 0; }
-
+
   tosend = measured;

   if ( measured > 500 )
@@ -53,10 +66,11 @@
     digitalWrite(nemoisonPin, HIGH);
   } else {
     digitalWrite(nemoisonPin, LOW);
-    }
   }

+  //scale.power_down();
   delay(200);
+  //scale.power_up();
 }

 void requestEvent()


implemented analogIn pins implemented joystick button update implemented joystick axis/rotation/throttle/rudder update switched joystick to autoupdate

--- ksp-gegi-microusb/ksp-gegi-microusb.ino
+++ ksp-gegi-microusb/ksp-gegi-microusb.ino
@@ -11,11 +11,160 @@
 // potencjometr: niebieski z czarną kreską do GND, biały do +5V, niebieski do pinu A0 / A1
 // LCD: SDA->2, SCL->3

+// Stage/Abort status (on=stage, off=abort)
+uint8_t stageabort = 1;
+// joy1 switch status - change meaning of joy2 axes (X:on=rotate, off=axis; Y:on=hatswitch#0, off=rudder)
+uint8_t joy1switch = 0;
+// joy2 switch status - change meaning of joy1 axes (X:on=rotate, off=axis; Y:on=rotate, off=axis)
+uint8_t joy2switch = 0;
+
+// almost copy from ksp-gegi-mini!
+
+class digitalPin {
+  public:
+    digitalPin(const uint8_t id, const uint8_t pinSwitch);
+    void updateSwitch();
+    uint8_t getId() { return(m_id); }
+    uint8_t getSwitchState() const { return(m_lastPinState); }
+  private:
+    void updateJoystick() const;
+    const uint8_t m_id, m_pinSwitch;
+    uint8_t m_lastPinState { HIGH } ;
+};
+
+digitalPin digiPins[] = {
+  digitalPin(10,5),    // joy1switch
+  digitalPin(11,7)	   // joy2switch
+};
+
+digitalPin::digitalPin(const uint8_t id, const uint8_t pinSwitch) :
+  m_id(id), m_pinSwitch(pinSwitch)
+{
+  if (m_pinSwitch>0) {
+    pinMode(m_pinSwitch,INPUT_PULLUP);
+  }
+}
+
+void digitalPin::updateSwitch() {
+  if (m_pinSwitch>0) {
+    // reverse logic because switches are connected to GND with internal pullup, so pushed state (ON) is 0V
+    uint8_t state = !digitalRead(m_pinSwitch);
+    if (state!=m_lastPinState) {
+      Serial.write('D');
+      Serial.print(m_id);
+      Serial.write('=');
+      Serial.println(state);
+      m_lastPinState = state;
+      updateJoystick();
+    }
+  }
+}
+
+// map to joystick events
+void digitalPin::updateJoystick() const {
+  uint8_t buttonId = 0x80;
+  switch (m_id) {
+    case 10:
+      buttonId = 6;
+      break;
+    case 11:
+      buttonId = 7;
+      break;
+  }
+  if (buttonId < 0x80) {
+    Joystick.setButton(buttonId,m_lastPinState);
+  }
+}
+
+/////////////
+
+class analogInPin {
+  public:
+    analogInPin(const uint8_t id, const uint8_t pin, const int threshold);
+    void update();
+  private:
+    void updateJoystick() const;
+    const uint8_t m_id, m_pin;
+    const int m_threshold;
+    int m_lastAValue { 0 };
+};
+
+analogInPin analogInPins[] = {
+  analogInPin(0,A4,2),  // throttle
+  analogInPin(1,A8,5),	// timewarp
+  analogInPin(2,A0,2),	// joy1x
+  analogInPin(3,A1,2),	// joy1y
+  analogInPin(4,A2,2),	// joy2x
+  analogInPin(5,A3,2),	// joy2y
+};
+
+analogInPin::analogInPin(const uint8_t id, const uint8_t pin, const int threshold) :
+	m_id(id), m_pin(pin), m_threshold(threshold)
+{
+}
+
+void analogInPin::update() {
+	// map to the range of the analog out
+	int aValue = map(analogRead(m_pin), 0, 1023, 0, 255);
+	// is it different enough from the last reading?
+	if (abs(aValue-m_lastAValue)>m_threshold) {
+		if (aValue<m_threshold) {
+			aValue = 0;
+		}
+		if (aValue>255-m_threshold) {
+			aValue = 255;
+		}
+		// dump status
+		Serial.print("P");
+		Serial.print(m_id);
+		Serial.print("=");
+		Serial.println(aValue,HEX);
+		m_lastAValue = aValue;
+		// map to joystick events
+		updateJoystick();
+	}
+}
+
+void analogInPin::updateJoystick() const {
+	switch (m_id) {
+		case 0: // throttle pot
+			Joystick.setThrottle(m_lastAValue);
+			break;
+		case 2:	// joy1x X on: rotation, off: axis
+			if (joy2switch) {
+				Joystick.setXAxisRotation(m_lastAValue-127);
+			} else {
+				Joystick.setXAxis(m_lastAValue-127);
+			}
+			break;
+		case 3: // joy1y Y on: rotation, off: axis
+			if (joy2switch) {
+				Joystick.setYAxisRotation(m_lastAValue-127);
+			} else {
+				Joystick.setYAxis(m_lastAValue-127);
+			}
+			break;
+		case 4: // joy2x Z on: rotation, off: axis
+			if (joy1switch) {
+				Joystick.setZAxisRotation(m_lastAValue-127);
+			} else {
+				Joystick.setZAxis(m_lastAValue-127);
+			}
+			break;
+		case 5: // joy2y on: ignore, off: rudder
+			if (joy1switch) {
+			} else {
+				Joystick.setRudder(m_lastAValue);
+			}
+			break;
+	}
+}
+
 class analogOutPin {
   public:
     analogOutPin(const uint8_t id, const uint8_t pin);
     void updateState(const uint8_t val) const ;
-    const uint8_t getId() const { return(m_id); }
+    const uint8_t getId() { return(m_id); }
   private:
     const uint8_t m_id, m_pin;
 };
@@ -33,9 +182,6 @@
   analogOutPin(0,9),	// g-force
   analogOutPin(1,10)    // electrical power
 };
-
-// Stage/Abort status (on=stage, off=abort
-uint8_t stageabort = 1;

 // Set the pins on the I2C chip used for LCD connections:
 //                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
@@ -59,7 +205,7 @@
   lcd.setCursor(0,1);
   lcd.print("Ready for action");
   // joystick setup
-  Joystick.begin(false);	// don't do auto send state
+  Joystick.begin(true);	// do auto send state
   // request status update
   Serial.println("I");
 }
@@ -105,6 +251,7 @@
 }

 // called after UART slave reports button press/release
+// map switch IDs to joystick buttons
 void handleSlaveButton(const uint8_t id, const uint8_t state) {
 	// handle stage switch
 	uint8_t buttonId = 0x80;
@@ -172,10 +319,30 @@
 	}
 }

+void updateAnalogs() {
+  for (auto &p : analogInPins) {
+    p.update();
+	// map to joystick axes
+  }
+}
+
+void updatePins() {
+  for (auto &p : digiPins) {
+    p.updateSwitch();
+	// remember state so analog axes are updated accordingly
+	if (p.getId()==10) {
+		joy1switch = p.getSwitchState();
+	}
+	if (p.getId()==11) {
+		joy2switch = p.getSwitchState();
+	}
+  }
+}
+
 void loop() {
   checkSerialInputUSBtoUART();
   checkSerialInputUARTtoUSB();
-  Joystick.sendState();
-  delay(200);
-}
-
+  updatePins();
+  updateAnalogs();
+  delay(50);
+}


TA/DD/WW: Added colors

TA/DD/WW: Added colors

--- conductor/conductor.ino
+++ conductor/conductor.ino
@@ -17,8 +17,15 @@
 int lightPin = 8;
 Adafruit_NeoPixel medallion = Adafruit_NeoPixel(7, lightPin, NEO_GRB + NEO_KHZ800);

-uint32_t purple = medallion.Color(36, 28, 153);
-uint32_t blueish = medallion.Color(0, 0, 200);
+uint32_t dimWhite = medallion.Color(200, 200, 255);
+uint32_t darkTeal = medallion.Color(0, 45, 45);
+uint32_t brightTeal = medallion.Color(0, 255, 255);
+uint32_t purple = medallion.Color(255, 0, 255);
+uint32_t violet = medallion.Color(125, 0, 255);
+uint32_t red = medallion.Color(255, 0, 0);
+uint32_t fireRed = medallion.Color(255, 30, 15);
+uint32_t gold = medallion.Color(175, 100, 0);
+
 uint32_t off = medallion.Color(0, 0, 0);

 void setup() {
@@ -45,9 +52,21 @@
         case 0:
             return off;
         case 1:
+            return dimWhite;
+        case 2:
+            return darkTeal;
+        case 3:
+            return brightTeal;
+        case 4:
             return purple;
-        case 2:
-            return blueish;
+        case 5:
+            return violet;
+        case 6:
+            return red;
+        case 7:
+            return fireRed;
+        case 8:
+            return gold;
         default:
             return off;
     }


Deescalated out of range fault

Deescalated out of range fault

--- Controller/Vehicle/Vehicle.ino
+++ Controller/Vehicle/Vehicle.ino
@@ -214,7 +214,16 @@
 	//out of range checks

 	if (newValues.xAxis > 1023 || newValues.xAxis < 0 || newValues.yAxis > 1023 || newValues.yAxis < 0) {
-		setFault(Input_Out_Of_Range);
+		//setFault(Input_Out_Of_Range);
+		Serial.print("Input_Out_Of_Range Fault Detected: ");
+		Serial.print("xAxis = ");
+		Serial.print(newValues.xAxis);
+		Serial.print(", yAxis = ");
+		Serial.println(newValues.yAxis);
+
+		//trying this instead of set fault
+		initializeData(newValues);
+		initializeOutputs();
 		return;
 	}


- fix: when LWiFi.connect() is failed, the return value may be 0 or -1

--- Device_LinkItOne/LASS/LASS.ino
+++ Device_LinkItOne/LASS/LASS.ino
@@ -1382,7 +1382,7 @@
     LWiFi.begin();
     int i=0;
     //while (!LWiFi.connectWPA(pSSID, pPassword)) {
-    while(!LWiFi.connect(pSSID, LWiFiLoginInfo(WIFI_AUTH, pPassword))){
+    while(LWiFi.connect(pSSID, LWiFiLoginInfo(WIFI_AUTH, pPassword))<=0){
         delay(1000);
         Serial.println("retry WiFi AP");
         i++;


Advanced blending technique for LED belt


Got a row of LEDs going.

Got a row of LEDs going.

--- LED_Blink/LED_Blink.ino
+++ LED_Blink/LED_Blink.ino
@@ -1,22 +1,89 @@
 void setup(void)
 {
-  // Initialize the digital pin 13 as an output.
   pinMode(13, OUTPUT);
+  pinMode(12,OUTPUT);
+  pinMode(11,OUTPUT);
+  pinMode(10,OUTPUT);
+  pinMode(9,OUTPUT);
+  pinMode(8,OUTPUT);
 }

 void loop(void)
 {
   digitalWrite(13, HIGH);
-  delay(50);
+  delay(100);
   digitalWrite(13, LOW);
-  delay(50);
+  delay(100);
   digitalWrite(13, HIGH);
-  delay(50);
+  delay(100);
   digitalWrite(13, LOW);
-  delay(05);
+  delay(100);
   digitalWrite(13, HIGH);
-  delay(50);
+  delay(100);
   digitalWrite(13, LOW);
   delay(1000);
+
+  digitalWrite(12, HIGH);
+  delay(100);
+  digitalWrite(12, LOW);
+  delay(100);
+  digitalWrite(12, HIGH);
+  delay(100);
+  digitalWrite(12, LOW);
+  delay(100);
+  digitalWrite(12, HIGH);
+  delay(100);
+  digitalWrite(12, LOW);
+  delay(1000);
+
+  digitalWrite(11, HIGH);
+  delay(100);
+  digitalWrite(11, LOW);
+  delay(100);
+  digitalWrite(11, HIGH);
+  delay(100);
+  digitalWrite(11, LOW);
+  delay(100);
+  digitalWrite(11, HIGH);
+  delay(100);
+  digitalWrite(11, LOW);
+  delay(1000);
+
+  delay(100);
+  digitalWrite(10, LOW);
+  delay(100);
+  digitalWrite(10, HIGH);
+  delay(100);
+  digitalWrite(10, LOW);
+  delay(100);
+  digitalWrite(10, HIGH);
+  delay(100);
+  digitalWrite(10, LOW);
+  delay(1000);
+
+  delay(100);
+  digitalWrite(9, LOW);
+  delay(100);
+  digitalWrite(9, HIGH);
+  delay(100);
+  digitalWrite(9, LOW);
+  delay(100);
+  digitalWrite(9, HIGH);
+  delay(100);
+  digitalWrite(9, LOW);
+  delay(1000);
+
+   delay(100);
+  digitalWrite(8, LOW);
+  delay(100);
+  digitalWrite(8, HIGH);
+  delay(100);
+  digitalWrite(8, LOW);
+  delay(100);
+  digitalWrite(8, HIGH);
+  delay(100);
+  digitalWrite(8, LOW);
+  delay(1000);
 }
+


Changes for latest Arduboy library compatibility

Used replacement versions of renamed and depricated library functions.
Also removed unneeded #includes.

--- ArduboyLife.ino
+++ ArduboyLife.ino
@@ -24,8 +24,6 @@
 // Conway's Game Of Life for the Arduboy
 // -------------------------------------

-#include <SPI.h>
-#include <EEPROM.h>
 #include <Arduboy.h>

 // Width and height of the screen in pixels (one pixel per cell)
@@ -62,8 +60,8 @@
 Arduboy aboy;

 void setup() {
-  aboy.start();
-  aboy.clearDisplay();
+  aboy.begin();
+  aboy.clear();
   grid = (uint8_t (*)[LIFEWIDTH]) aboy.getBuffer();

   // Display the intro screen
@@ -95,7 +93,7 @@
 }

 void loop() {
-  switch (aboy.getInput()) {
+  switch (aboy.buttonsState()) {
     case BTN_PAUSE:
       pauseGame();
       break;
@@ -214,7 +212,7 @@
 void genGrid(long seed) {
   int numChars;

-  aboy.clearDisplay();
+  aboy.clear();
   randomSeed(seed);
   numChars = random(10, 100);
   for (int c = 0; c <= numChars; c++) {
@@ -242,7 +240,7 @@

 // Display the button help screen
 void showHelp() {
-  aboy.clearDisplay();
+  aboy.clear();

   aboy.drawChar(47, 11, 0x1f, 1, 0, 1);
   aboy.drawChar(43, 15, 0x10, 1, 0, 1);
@@ -349,7 +347,7 @@
 boolean waitRelease(uint8_t button) {
   showInfo();
   delay(debounceWait);
-  while (aboy.not_pressed(button) == false) {
+  while (aboy.notPressed(button) == false) {
     if (((button == BTN_SLOWER) || (button == BTN_FASTER)) &&
          aboy.pressed(BTN_SLOWER + BTN_FASTER)) {
       return false;
@@ -365,7 +363,7 @@
 void delayPoll(unsigned long msDelay) {
   unsigned long waitTime = millis() + msDelay;

-  while (((long) (millis() - waitTime) < 0) && (aboy.getInput() == 0)) {}
+  while (((long) (millis() - waitTime) < 0) && (aboy.buttonsState() == 0)) {}
 }

 //------------------------------------------------------------


Made the arbotix work

Made the arbotix work

--- sketch_jan30a/sketch_jan30a.ino
+++ sketch_jan30a/sketch_jan30a.ino
@@ -1,31 +1,33 @@
-
-
-
-    int servoNumOne=0;//forgot which ones i set them as
-    int servoNumTwo=15;//this number sounds familiar
+   #include <ax12.h>
+   #include <Servo.h>
+   Servo thrustOne;
+   Servo thrustTwo;
+   Servo thrustThree;
+   int servoNumOne=0;//forgot which ones i set them as
+   int servoNumTwo=15;//this number sounds familiar
 void setup(){
-    Serial.begin(38400);
+   Serial.begin(38400);

-   // Servo thrustOne;
-   // Servo thrustTwo;
-   // Servo thrustThree;//Conor claims thrusters work this simply
+//Conor claims thrusters work this simply
     //thrustOne.attach(1);//arbitrary pin#
     //thrustTwo.attach(2);//arbitrary pin#
     //thrustThree.attach(3);//arbitrary pin#
 }
 void loop(){
     int i;
-    int input[6];
-    while(Serial.available()>0){
-      input = Serial.read();
+    int input[5];
+    while(Serial.available()<5){
+      for (int i=0;i<5;i++){
+       input[i]=Serial.read();
+      }
       //implement delay later on with the math
       SetPosition(servoNumOne,input[0]);
       SetPosition(servoNumTwo,input[1]);

-     // thrustOne.write(input[2]);
-   //   thrustTwo.write(input[3]);
-     // thrustThree.write(input[4]);
+      thrustOne.write(input[2]);
+      thrustTwo.write(input[3]);
+      thrustThree.write(input[4]);

     }


change the dailed number

change the dailed number

--- sketch_sep22a/sketch_sep22a.ino
+++ sketch_sep22a/sketch_sep22a.ino
@@ -61,7 +61,7 @@
   delay(40);
   Serial.println("Dial activity!");
   clearRing();
-  counter = 0;
+  counter = -1;
   pulseactive = false;
   while( digitalRead(rest) == 0 )       // Count pulses while dial rotates
   {


documentation

documentation

--- chaise2.ino
+++ chaise2.ino
@@ -36,13 +36,16 @@
 #define DEBUG_PRINTLN_F(x,f)	NOP
 #endif

-//
+//	let everyone know we are alive
 Heartbeat heartbeat(LED_BUILTIN,250,2000);
+//	manage the demo switch
 DemoSwitchManager DemoButton(DEMO_SW_PIN);
+//	manage the demo mode
 DemoModeManager DemoMode(DEMO_MODE_LED_PIN);
+//	track our passes through the loop
 uint16_t loop_count = 0;
+//	last state of the demo switch
 demo_sw_t lastDemoSwitchState = DemoSwitchUnchanged;
-
 //	ms timestamp at the last touch
 uint32_t lastTouchTime;
 CRGB leds[NUM_LEDS];
@@ -170,8 +173,11 @@
     interrupts();
     FastLED.delay(40);

-	heartbeat.update();
-	Klavier.update();		//	update touch manager
+    //	update the heartbeat LED
+	heartbeat.update();
+	//	update the touch manager
+	Klavier.update();
+	//	update the pedalboard and get its function
 	PedalFunction pedal = PedalBoard.update();
 	if( pedal == PedalChangePalette ) {
 		Transposer.toggle();


moveForward stuff

moveForward stuff

--- 2018-FirefighterL1/2018-FirefighterL1.ino
+++ 2018-FirefighterL1/2018-FirefighterL1.ino
@@ -51,6 +51,10 @@
 Ultrasonic rightUltrasonic(R_ECHO, R_TRIG, true);
 Ultrasonic backUltrasonic(B_ECHO, B_TRIG, true);

+//Move controls
+float v_max = 5;
+float t_acceleration = 0.5;
+
 float getRotation();

 //Gyroscope controls
@@ -74,6 +78,15 @@
 void rollBackward() {
   leftMotor.set(-leftSpeed);
   rightMotor.set(-rightSpeed);
+}
+
+void moveForward(float distance){
+  float time_travel = (distance/v_max) - t_acceleration;
+  leftMotor.set(leftSpeed);
+  rightMotor.set(rightSpeed);
+  delay(time_travel/1000);
+  leftMotor.set(0);
+  rightMotor.set(0);
 }

 void moveSlightLeft() {


let's not wait too much :) telnet running here

--- hardware/esp8266com/esp8266/libraries/ESP8266mDNS/examples/DNS_SD_Arduino_OTA/DNS_SD_Arduino_OTA.ino
+++ hardware/esp8266com/esp8266/libraries/ESP8266mDNS/examples/DNS_SD_Arduino_OTA/DNS_SD_Arduino_OTA.ino
@@ -92,5 +92,5 @@
     }
     free(sbuf);
   }
-  delay(100);
+  delay(1);
 }


Add: colors var, for 216 premade colors, and som daycolors

--- RGB_lamps/RGB_lamps.ino
+++ RGB_lamps/RGB_lamps.ino
@@ -8,6 +8,8 @@
 */

 RGBLamp lamps[4];
+int colors[216][3];
+int dayCols[10][3];

 void setup() {

@@ -25,14 +27,43 @@
   lamps[3].create(11,12,13);

   // Sets all lamps to a random color
-  for (int lamp = 0; lamp < 4; lamp++) {
+  /*for (int lamp = 0; lamp < 4; lamp++) {
     int col[] = {random(0, 255),random(0, 255),random(0, 255)};
     lamps[lamp].setColor(col);
     //lamps[lamp].on();
-  }
-
+  }*/
+
+  // Start at the max of colors to test the board and lamps
+  int col0[] = {255,0,0};
+  lamps[0].setColor(col0);
+  int col1[] = {0,255,0};
+  lamps[1].setColor(col1);
+  int col2[] = {0,0,255};
+  lamps[2].setColor(col2);
+  int col3[] = {255,255,255};
+  lamps[3].setColor(col3);
+
+  delay(2000);
+  lamps[0].setColor(col3);
+  lamps[1].setColor(col0);
+  lamps[2].setColor(col1);
+  lamps[3].setColor(col2);
+
+  delay(2000);
+  lamps[0].setColor(col2);
+  lamps[1].setColor(col3);
+  lamps[2].setColor(col0);
+  lamps[3].setColor(col1);
+
+  delay(2000);
+  lamps[0].setColor(col1);
+  lamps[1].setColor(col2);
+  lamps[2].setColor(col3);
+  lamps[3].setColor(col0);
+
   // Sleeps for 2 seconds to test the output before moving on
   delay(2000);
+  setColors();
 }

 // This will carry out the fades and so on. These must be run each loop! (!!!)
@@ -48,10 +79,49 @@
   if(finish) {
     // Sets all lamps to fade to a random color
     for (int lamp = 0; lamp < 4; lamp++) {
-      int col[] = {random(0, 255),random(0, 255),random(0, 255)};
-      lamps[lamp].fade(5000, col);
+      lamps[lamp].fade(10000, colors[random(0, 215)]);
     }
   }
+}
+
+void setColors() {
+
+  // Set up a 216 color array, so that we dont get all whites
+  int i = 0;
+  for(int r = 0; r <= 255; r += 51) {
+    for(int g = 0; g <= 255; g += 51) {
+      for(int b = 0; b <= 255; b += 51) {
+        colors[i][0] = r;
+        colors[i][1] = g;
+        colors[i][2] = b;
+        i++;
+      }
+    }
+  }
+
+  // Trying to simulate the colors of the day
+  dayCols[3] = {174,183,190}; // overcast
+
+  // Sunset
+  dayCols[0][0] = 182;
+  dayCols[0][1] = 126;
+  dayCols[0][2] = 91;
+
+  // Noon
+  dayCols[1][0] = 192;
+  dayCols[1][1] = 191;
+  dayCols[1][2] = 173;
+
+  // Clouds, haze
+  dayCols[2][0] = 189;
+  dayCols[2][1] = 190;
+  dayCols[2][2] = 192;
+
+  // Overcast
+  dayCols[3][0] = 174;
+  dayCols[3][1] = 183;
+  dayCols[3][2] = 190;
+
 }

 // This is our main loop


Add: more day colors

Add: more day colors


fixed animation for shutdown, removed heartbeat from server_locked

--- piserverpanel/piserverpanel.ino
+++ piserverpanel/piserverpanel.ino
@@ -87,22 +87,12 @@
 int pwm_red = 0;
 int pwm_green = 0;
 int pwm_blue = 0;
+int pwm_yellow = 0;

 int fader_red = 7;
 int fader_green = 3;
 int fader_blue = 15;
-
-//++++ cleanup due!
-
-int c_r = 0;
-int c_g = 0;
-int c_b = 0;
-int fade_r = 7;
-int fade_g = 3;
-int fade_b = 15;
-int fade_delay = 5;
-int fdel = 1;
-int cmode = 0;
+int fader_yellow = 10;

 int incomingByte = 0;
 int receivedHeartbeat = 0;
@@ -184,7 +174,7 @@

 int detect_heartbeat() {
   if (((millis()-track_missing_heartbeat) >= HEARTBEAT_IS_MISSING) && get_last_heartbeat() >= HEARTBEAT_IS_MISSING) {
-    if (statefunc != server_bootable) {
+    if ((statefunc != server_bootable) && (statefunc != server_locked)) {
       signal_heartbeat_missing();
     }
     track_missing_heartbeat = millis();
@@ -257,27 +247,29 @@

 void signal_heartbeat_ack() {
   led_color(255,0,255);
+  delay(20);
+  led_off();
   delay(10);
   led_color(255,0,255);
   delay(10);
-  led_color(0,0,0);
+  led_off();
   delay(15);
 }

 void signal_heartbeat_abort() {
-  led_color(0,0,255);
-  delay(10);
-  led_color(255,255,255);
-  delay(10);
-  led_color(0,0,0);
+  led_blue(255);
+  delay(10);
+  led_white(255);
+  delay(10);
+  led_off();
   delay(15);
 }

 void signal_heartbeat_system_shutdown() {
-  led_color(0,0,255);
-  delay(10);
+  led_blue(255);
+  delay(30);
   led_color(90,20,200);
-  delay(10);
+  delay(20);
   led_color(0,0,0);
   delay(15);
 }
@@ -336,33 +328,33 @@
 }

 void animate_booting() {
-  int del = 20;
-  analogWrite(LED_R, 255-c_r);
-  analogWrite(LED_G, 255-c_g);
-  analogWrite(LED_B, 255-c_b);
-
-  //analogWrite(LED_G, 255);
-  //analogWrite(LED_B, 255);
-
-  c_r = c_r + fade_r;
-  c_g = c_g + fade_g;
-  c_b = c_b + fade_b;
-
-  if ( c_r <= 0 || c_r >= 200 ) {
-    fade_r = -fade_r;
-  }
-  if ( c_g <= 0 || c_g >= 255 ) {
-    fade_g = -fade_g;
-  }
-  if ( c_b <= 0 || c_b >= 155 ) {
-    fade_b = -fade_b;
-  }
-
-  fade_delay = fade_delay + fdel;
-  if (fade_delay <= 1 || fade_delay >=del) {
-    fdel = -fdel;
-  }
-  delay(fade_delay);
+  int ms = 45;
+  int min_value = 0;
+  int max_value = 255;
+
+  led_color(pwm_red, pwm_green, pwm_blue);
+
+  pwm_red = pwm_red + fader_red;
+  pwm_green = pwm_green + fader_green;
+  pwm_blue = pwm_blue + fader_blue;
+
+  if ( pwm_red <= min_value || pwm_red >= max_value ) {
+    fader_red = -fader_red;
+  }
+
+  if ( pwm_green <= min_value || pwm_green >= max_value ) {
+    fader_green = -fader_green;
+  }
+
+  if ( pwm_blue <= min_value || pwm_blue >= max_value ) {
+    fader_blue = -fader_blue;
+  }
+
+  if (fader_green > 0) {
+   delay(ms);
+  } else {
+   delay(ms/2);
+  }
 }

 void animate_running() {
@@ -400,19 +392,19 @@
   int min_value = 0;
   int max_value = 150;

-  led_yellow(pwm_green);
-
-  pwm_green = pwm_green + fader_green;
-
-  if ( pwm_green > max_value+1 ) {
-    pwm_green = max_value;
-  }
-
-  if ( pwm_green <= min_value || pwm_green >= max_value ) {
-    fader_green = -fader_green;
-  }
-
-  if (fader_green > 0) {
+  led_yellow(pwm_yellow);
+
+  pwm_yellow = pwm_yellow + fader_yellow;
+
+  if ( pwm_yellow > max_value+1 ) {
+    pwm_yellow = max_value;
+  }
+
+  if ( pwm_yellow <= min_value || pwm_yellow >= max_value ) {
+    fader_yellow = -fader_yellow;
+  }
+
+  if (fader_yellow > 0) {
    delay(ms);
   } else {
    delay(ms);
@@ -424,19 +416,19 @@
   int min_value = 0;
   int max_value = 150;

-  led_yellow(pwm_green);
-
-  pwm_green = pwm_green + fader_green;
-
-  if ( pwm_green > max_value+1 ) {
-    pwm_green = max_value;
-  }
-
-  if ( pwm_green <= min_value || pwm_green >= max_value ) {
-    fader_green = -fader_green;
-  }
-
-  if (fader_green > 0) {
+  led_red(pwm_yellow);
+
+  pwm_yellow = pwm_yellow + fader_yellow;
+
+  if ( pwm_yellow > max_value+1 ) {
+    pwm_yellow = max_value;
+  }
+
+  if ( pwm_yellow <= min_value || pwm_yellow >= max_value ) {
+    fader_yellow = -fader_yellow;
+  }
+
+  if (fader_yellow > 0) {
    delay(ms);
   } else {
    delay(ms/3);
@@ -444,16 +436,9 @@
 }

 void animate_hungup() {
-  analogWrite(LED_R, 255-c_r);
-  analogWrite(LED_G, 255);
-  analogWrite(LED_B, 255);
-
-  c_r = c_r + fade_r;
-
-  if ( c_r <= 0 || c_r >= 255 ) {
-    fade_r = -fade_r;
-  }
-
+  led_yellow(255);
+  delay(80);
+  led_off();
   delay(20);
 }


set more userfriendly numbers

set more userfriendly numbers

--- code/PABS/PABS.ino
+++ code/PABS/PABS.ino
@@ -58,32 +58,32 @@
 	switch (state)
 	{
 		case 0:
-			SystemMethodsObject.SetDisplayNumber(11);
+			SystemMethodsObject.SetDisplayNumber(0);
 			gameMode = new TestMode();
 			Serial.write("TestMode");
 			SetupPlayerInts();
 			break;
 		case 1:
-			SystemMethodsObject.SetDisplayNumber(22);
+			SystemMethodsObject.SetDisplayNumber(11);
 			gameMode = new BrainRingMode();
 			Serial.write("BrainMode");
 			SetupPlayerInts();
 			break;
 		case 2:
-			SystemMethodsObject.SetDisplayNumber(33);
+			SystemMethodsObject.SetDisplayNumber(22);
 			gameMode = new OwnGameMode();
 			Serial.write("OwnGameMode");
 			SetupPlayerInts();
 			break;
 		case 3:
-			SystemMethodsObject.SetDisplayNumber(44);
+			SystemMethodsObject.SetDisplayNumber(33);
 			gameMode = new WwwMode();
 			Timer1.initialize(1000000);
 			Timer1.attachInterrupt(TimerInterrupt);
 			Serial.write("WwwMode!");
 			break;
 		case 4:
-			SystemMethodsObject.SetDisplayNumber(55);
+			SystemMethodsObject.SetDisplayNumber(44);
 			gameMode = new BrainRingWithTimerMode();
 			Timer1.initialize(1000000);
 			Timer1.attachInterrupt(TimerInterrupt);


update

update

--- src/Firmware.ino
+++ src/Firmware.ino
@@ -49,8 +49,8 @@
     long targetPosition[NUM_AXIS];
     long startPosition[NUM_AXIS];
     long timerCount = 0;
-    long time = 1250;
-    long defaultTime = 1250;
+    long time = 625;
+    long defaultTime = 625;
     long defaultAcceleration = 25;
     long defaultAccelCount = 50;
     long defaultDecelCount = 50;
@@ -267,7 +267,7 @@
     s.targetPosition[1] = y;
     if (_sys.statesLength >= STATES_COUNT)
     {
-        shiftState();
+        waitingPushPoint();
     }
     _sys.states[_sys.statesLength] = s;
     _sys.statesIndex++;


lowered the brightness and fixed the last led in emergency mode

--- TinkerTie/TinkerTie.ino
+++ TinkerTie/TinkerTie.ino
@@ -20,7 +20,7 @@

 void setup() {
   bowtie.begin();
-  bowtie.setBrightness(6);
+  bowtie.setBrightness(5);
   bowtie.show(); // Initialize all pixels to 'off'

   //For the extra button
@@ -53,7 +53,7 @@
   static long state_prev = capSensor.capacitiveSensor(30);
   long state_curr = capSensor.capacitiveSensor(30);

-  if ((state_curr <= 40) && (state_prev >= 50)) { //on short button release
+  if ((state_curr <= 40) && (state_prev >= 50)) { //on capacitive button release
     nextAnimationProfile();
   }
   state_prev = state_curr;
@@ -70,7 +70,7 @@
 }

 void callEmergency(){
-  for (byte i = 0; i < 27; i++){
+  for (byte i = 0; i < 28; i++){
     bowtie.setPixelColor(i, 0xFFFFFF);
   }
   delay(20);