Tided up if/else statement

Tided up if/else statement

--- arduboy-game/arduboy-game.ino
+++ arduboy-game/arduboy-game.ino
@@ -298,7 +298,7 @@
 }

 void printMusicOnOff() {
-  if(musicOnOff == true) {
+  if(musicOnOff) {
     printText("SOUND  ON ", 20, 25, 1);
     arduboy.drawRect(17, 22, 35, 13, 1);
   } else {


Saved 6 bytes of SRAM by removing display() call from  printsoundOnOff();

--- arduboy-game/arduboy-game.ino
+++ arduboy-game/arduboy-game.ino
@@ -129,6 +129,7 @@
         music = titleMusic;
       break;
     }
+
     currentSong = song;
     if (! arduboy.tunes.playing()) {
       arduboy.tunes.playScore(music);


Corrected one comment and remove to variables

- Corrected the comment in the my_failCmd function.
- Remove declaration of int name_len and int value_len (not used)

--- examples/Web_Parms/Web_Parms.ino
+++ examples/Web_Parms/Web_Parms.ino
@@ -154,9 +154,7 @@
 {
   URLPARAM_RESULT rc;
   char name[NAMELEN];
-  int  name_len;
   char value[VALUELEN];
-  int value_len;

   /* this line sends the standard "we're all OK" headers back to the
      browser */
@@ -219,7 +217,7 @@

 void my_failCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
 {
-  /* this line sends the standard "we're all OK" headers back to the
+  /* this line sends the "HTTP 400 - Bad Request" headers back to the
      browser */
   server.httpFail();


Changing to Adafruit TiCo Servo Library

Changing to Adafruit TiCo Servo Library

Switching to the magical TicoServo library to solve the neopixel/servo fighting problems so I don't have to detach the servos everytime the pixels update

--- Arduino/MIMIC_Extras/SGANT/SGANT.ino
+++ Arduino/MIMIC_Extras/SGANT/SGANT.ino
@@ -1,18 +1,19 @@
+#include <Adafruit_TiCoServo.h>
+#include <known_16bit_timers.h>
 #include <FastLED.h>
-#include <Servo.h>
 #include <string.h>

 #define NUM_LEDS 32
 #define DATA_PIN 6
 #define BRIGHTNESS  200
 #define FRAMES_PER_SECOND 60
+
 CRGBPalette16 gPal;
 CRGB leds[NUM_LEDS];
 //Connect USB port to Pi USB Port

-//Adafruit_NeoPixel strip = Adafruit_NeoPixel(32, 6, NEO_GRB + NEO_KHZ800);
-Servo XEL_servo;
-Servo EL_servo;
+Adafruit_TiCoServo XEL_servo;
+Adafruit_TiCoServo EL_servo;
 bool gReverseDirection = false;
 const int ledBluePin = 13;
 String test;
@@ -21,10 +22,10 @@
 boolean Transmit = false;
 int pos = 0;
 int pos2 = 0;
-int oldEL = 0;
-int oldXEL = 0;
-int oldnewEL = 0;
-int oldnewXEL = 0;
+int oldEL = 5;
+int oldXEL = 5;
+int oldnewEL = 91;
+int oldnewXEL = 84;
 int index = 0;

 uint32_t stickone[] = {0,1,2,3,4,5,6,7};
@@ -37,30 +38,22 @@

 void setup()
 {
-  pinMode(ledBluePin, OUTPUT);
   Serial.begin(9600);
   Serial.setTimeout(50);
+
   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
   gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::Yellow, CRGB::White);
   allSet(CRGB::Black);
-  //strip.begin();

   EL_servo.attach(10);
   XEL_servo.attach(9);
-
-  EL_servo.write(map(0, -90, 90, 152, 30)); //custom mapping the servo motion to the sgant elevation motion
-  XEL_servo.write(map(0, -90, 90, 28, 160)); //custom mapping the servo motion to the sgant cross elevation motion
-
-  EL_servo.detach();
-  XEL_servo.detach();
 }

 void loop()
 {
   digitalWrite(ledBluePin, LOW);
   random16_add_entropy( random());
-  //Serial.print("El ");
-  //Serial.println(EL);
+
   if(Serial.available())
   {
     checkSerial();
@@ -76,7 +69,6 @@
   {
     if(Transmit)
     {
-      //allSet(CRGB::Black);
       leds[stickone[index]] = CRGB::White;
       leds[sticktwo[index]] = CRGB::White;
       leds[stickthree[index]] = CRGB::White;
@@ -86,7 +78,6 @@
       leds[stickthree[index]].fadeLightBy(brightness);
       leds[stickfour[index]].fadeLightBy(brightness);

-      //allSet(strip.Color(50,50,50),10);
       FastLED.show();
       delay(100);
       index++;
@@ -100,13 +91,10 @@
           fadeAmount = -fadeAmount ;
         }
       }
-      //Serial.println("Transmitting");
     }
     else
     {
-      //Serial.println("Not Transmitting");
       allSet(CRGB::Red);
-      //allSet(strip.Color(50,0,0),10);
       FastLED.show();
     }
   }
@@ -129,15 +117,9 @@
     {
       XEL = -65;
     }
-    Serial.print("Sending EL ");
-    Serial.println(EL);
-    Serial.print("Sending XEL ");
-    Serial.println(XEL);
-    EL_servo.attach(10);
-    XEL_servo.attach(9);

     int newEL = map(EL, -90, 90, 152, 30);
-    int newXEL = map(XEL, -90, 90, 28, 160);
+    int newXEL = map(XEL, -90, 90, 22, 147);

     if(newEL - oldnewEL > 10)
     {
@@ -165,10 +147,6 @@
       XEL_servo.write(newXEL);
     }

-    delay(1000);
-
-    EL_servo.detach();
-    XEL_servo.detach();
     oldnewEL = newEL;
     oldnewXEL = newXEL;
     oldEL = EL;
@@ -178,7 +156,6 @@

 void checkSerial()
 {
-  digitalWrite(ledBluePin, HIGH);
   test = "";

   while(Serial.available())


modified operating conditions for automatic torque on-off processing for motors.

--- arduino/opencr_arduino/opencr/libraries/turtlebot3_ros2/examples/turtlebot3_burger/turtlebot3_core/turtlebot3_core.ino
+++ arduino/opencr_arduino/opencr/libraries/turtlebot3_ros2/examples/turtlebot3_burger/turtlebot3_core/turtlebot3_core.ino
@@ -333,7 +333,9 @@
   if(millis() - pre_time_ping >= interval_ms*100){
     pre_time_ping = millis();
     if(motor_driver.isConnected() == true){
-      motor_driver.setTorque(true);
+      if(getConnectionStateWithROS2Node() == false){
+        motor_driver.setTorque(true);
+      }
       dxl_slave.setControlTable(ADDR_DEVICE_STATUS, (int8_t)STATUS_RUNNING);
       setConnectionStateWithMotors(true);
     }else{


Serial begun setup added

Serial begun setup added

--- MID/MID.ino
+++ MID/MID.ino
@@ -50,11 +50,13 @@
     // Sets display pins to socket
     lcdPwr.begin();
     //
-    // Shutdown setupvehicle
+    // Shutdown setup vehicle
     shutDown.begin(SAV_PIN_CTR, SAV_PIN_DTC, TONE_ADT_PIN);
     //
     // Debug serial
+#if defined(DEBUG) && defined(SERIAL_MONITOR_BAUD)
     Serial.begin(SERIAL_MONITOR_BAUD);
+#endif
     //
     // Change timer 3
     setupTimer3();


add config for thread

add config for thread


atualização do ex5 - Criando um servidor http

--- Ex5/Ex5.ino
+++ Ex5/Ex5.ino
@@ -1,76 +1,106 @@
 /*
 www.CodeDecay.com.br
 Licença de uso: Apache 2.0
-
-Neste exercício vamos criar uma rede própria através do ESP8266
+Neste exercício vamos adicionar a função de toggle ao ventilador
 */

-/*Iremos utilizar a biblioteca WiFiEsp para facilitar as operações com o ESP */
-#include "WiFiEsp.h"
+/* Iremos utilizar a bibiloteca WiFIEsp para facilitar as operações com o ESP */
+#include "SoftwareSerial.h"

 /*E tambem a SoftwareSerial para estabelecer comunicação serial do Arduino
 com o ESP */
-#include "SoftwareSerial.h"
+#include "WiFiEsp.h"
+

 /* Inicializa objeto do tipo SoftwareSerial especificando que os pinos 10 e 11
 do Arduino serão RX e TX desta interface. A comunicação serial padrão do
 Arduino com o computador é realizada sempre com os pinos 0 e 1. */
-SoftwareSerial ESP8266(10, 11); // RX do Arduino, TX do Arduino
-
-char ssidStation[] = "Claudia";            // nome da rede wifi a ser utilizada
-char senhaStation[] = "140897hr";        // senha da rede wifi a ser utilizada
-
-char ssidAP[] = "codedecay";                 // nome do access point
-char senhaAP[] = "codedecay2017";         // senha do access point
+SoftwareSerial ESP8266(10, 11);

 /*Inicializa o objeto do tipo cliente, que usaremos para enviar as informações
 para o servidor do Thingspeak*/
-WiFiEspClient espCliente;
+RingBuffer buf(20);
+
+// Inicializar servidor no ESP que receberá conexões na porta 80 (HTTP)
+WiFiEspServer espServidor(80);

 void setup() {

   Serial.begin(9600);  // Inicializa comunic. serial Arduino <-> computador
   ESP8266.begin(9600); // Inicializa comunic. serial Arduino <-> ESP
-  WiFi.init( &ESP8266 ); /* Associa a interface serial do ESP8266 com o objeto
+
+  /* Associa a interface serial do ESP8266 com o objeto
   WiFi do Arduino, indicando que todas as conexões de rede são feitas através
   do ESP8266 conectado na interface SoftwareSerial indicada */
+  WiFi.init( &ESP8266 );

-  // Tenta conectar à rede wifi
-  Serial.print( "Tentando conectar a rede wifi WPA de SSID: " );
-  Serial.println( ssidStation );
-  while ( WiFi.begin(ssidStation, senhaStation) != WL_CONNECTED ) delay(10);
-  // Informa que a conexão foi bem sucedida e mostra informações mais detalhadas
-  printWifiStatus();
+  // Conecta à rede WiFi
+  WiFi.begin("code", "codecode");

-  // Tenta iniciar o Access Point
-  Serial.print( "Tentando iniciar o Access Point de SSID: " );
-  Serial.println( ssidAP );
-  // Inicia o AP (nome, canal, senha, segurança, desligar station)
-  if ( WiFi.beginAP(ssidAP, 10, senhaAP, ENC_TYPE_WPA2_PSK, false) ) {
-    Serial.print("Endereco IP no AP: ");
-    Serial.println( WiFi.localIP() );
-  }
-}
+  // Mostra nome da rede à qual o modulo esta conectado
+  Serial.print("SSID: ");
+  Serial.println(WiFi.SSID());

-void loop() {
-  // verifica se o último envio foi feito há mais de 60000 segundos:
-  delay(1000);
-}
-
-void printWifiStatus() {
-  // Imprime o SSID da rede a qual nos conectamos
-  Serial.print("SSID: ");
-  Serial.println( WiFi.SSID() );
-
-  // Imprime o IP do ESP8266
+  // Mostra o IP local do ESP na rede WiFi
   IPAddress ip = WiFi.localIP();
-  Serial.print("IP Address: ");
-  Serial.println( ip );
-
-  // Imprime a potência do sinal
-  Serial.print("Potencia do sinal (RSSI):");
+  Serial.print("End. IP: ");
+  Serial.println(ip);
+
+  //Mostra a potencia do sinal WiFi da rede
+  Serial.print("Potencia do sinal (RSSI): ");
   Serial.print(WiFi.RSSI());
   Serial.println(" dBm");

   Serial.println();
+
+  // Incia o AP (nome, canal, senha, segurança, desligar station)
+  WiFi.beginAP("WiFi-Douglas", 2, "12345678", ENC_TYPE_WPA_PSK, false);
+
+  // Mostra o endereço IP do AP, que usamos para conectar localmente ao servidor
+  Serial.print("Endereco IP do AP: ");
+  Serial.println(WiFi.localIP());
+
+  //Inicializa servidor
+  espServidor.begin();
+
 }
+
+void loop() {
+
+  // aguarda a conexao de clientes novos:
+  WiFiEspClient cliente = espServidor.available();
+  if (cliente) atenderCliente(cliente);
+}
+
+// Esta função processa as requisições recebidas
+void atenderCliente ( WiFiEspClient cliente){
+  buf.init(); //inicializa o buffer circular
+
+  while(cliente.connected()){
+    if(cliente.available()){ // verifica se ainda existem bytes a serem recebidos do cliente
+      buf.push(cliente.read()); // adiciona o byte lido ao buffer
+    }
+
+    /* um request http termina com dois \r\n consecutivos.
+      quando atingirmos essa situacao, basta enviar a resposta */
+    if(buf.endsWith("\r\n\r\n")){
+      enviarResposta(cliente);
+      break;
+    }
+  }
+  cliente.stop(); //desconecta do cliente
+}
+
+void enviarResposta(WiFiEspClient cliente){
+  // Envia o cabeçalho da resposta HTTP
+  cliente.print("HTTP/1.1 200 OK\r\n");
+  cliente.print("Content-Type: text/html\r\n");
+  cliente.print("Connection: close\r\n");
+  cliente.print("\r\n");
+  // Envia o corpo da mensagem HTTP
+  cliente.print("<!DOCTYPE HTML>\r\n"); // não é uma tag HTML! É uma declaração ao navegador sobre a versão de html da página
+  cliente.print("\r\n"); // tag html que diz ao navegador que este arquivo é no formato html
+  cliente.print("
Smartfan
\r\n"); //tag HTTP de título
+  cliente.print("
\r\n"); // tag HTTP para pular linha
+  cliente.print("\r\n");
+}


Added heading offset to display

Added heading offset to display

--- gps_arduino/gps_arduino.ino
+++ gps_arduino/gps_arduino.ino
@@ -405,6 +405,9 @@
          lcd2.setCursor(0,2);
          lcd2.print("MAG: ");
          lcd2.print(compassHeading);
+         lcd2.print(" (");
+         lcd2.print(mHeadingOffset);
+         lcd2.print(")");
          lcd2.setCursor(0,3);
          lcd2.print("SAT: ");
          lcd2.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? DEC: gps.satellites());


Working Serial0 and Serial1 example

Working Serial0 and Serial1 example

--- sketches/OpenROV/OpenROV.ino
+++ sketches/OpenROV/OpenROV.ino
@@ -5,8 +5,8 @@
 	//digitalWrite(PIN_LED_0, HIGH);
 	//digitalWrite(PIN_LED_1, HIGH);

-	//Serial.begin( 115200 );
-	//Serial1.begin( 115200 );
+	Serial.begin( 115200 );
+	Serial1.begin( 115200 );
 }

 void loop()
@@ -16,6 +16,6 @@
   	digitalWrite(PIN_LED, LOW);    // turn the LED off by making the voltage LOW
  	delay(1000);

-	//Serial.println( "Hello0" );
-	//Serial1.println( "Hello1" );
+	Serial.println( "Hello0" );
+	Serial1.println( "Hello1" );
 }


Testing some colors

Testing some colors

--- DiamondOre.ino
+++ DiamondOre.ino
@@ -27,6 +27,43 @@
   }
 }

+int cloud_set_colors(String _colors) {
+  Serial.print("Received new colors from the cloud: "); Serial.println(_colors);
+  int col[3] = { 0, 0, 0};
+
+  int ci = 0;
+  for (int i=0; i<_colors.length(); i++) {
+    char c = _colors.charAt(i);
+    if (c >= '0' && c <= '9') {
+      col[ci] = 10 * col[ci] + (c - '0');
+    } else if (c == ';') {
+      if (ci++ > 2) {
+        Serial.println("Too many numbers in string. Aborting.");
+        return -1;
+      }
+    } else {
+      Serial.println("Invalid character in string. Aborting.");
+      Serial.println(c);
+      return -2;
+    }
+  }
+
+  if (ci != 2) {
+    Serial.println("Not enough numbers in string. Aborting.");
+    return -3;
+  }
+
+  // TODO: Check if all values are in range 0-255
+
+  // All looks good
+  for (int i=0; i<PIXEL_COUNT; i++) {
+    strip.setPixelColor(i, col[0], col[1], col[2]);
+  }
+  strip.show();
+
+  return 0;
+}
+

 ServerState server;

@@ -117,6 +154,7 @@

   // Register configuration function and varibales to Particle Cloud
   Particle.function("setServer", cloud_set_server);
+  Particle.function("setColors", cloud_set_colors);
   Particle.variable("serverName", config.server_name);
   Particle.variable("serverPort", config.server_port);
   // additional variables are exported inside the ServerState class
@@ -159,29 +197,27 @@

     int r, g, b, flicker;
     if (server.get_state() != ServerState::STAT_ONLINE) {
-      r = 220;
-      g = 50;
-      b = 35;
+      r = 255;
+      g = 30;
+      b = 5;
       ledWait = random(50, 300);
-      flicker = random(50, 150);

     } else {
       ledWait = random(500, 1000);
-      flicker = random(75, 100);
       if (server.get_players_online()) {
         // Player online, diamond block!
-        r = 35;
-        g = 50;
-        b = 220;
+        r = 150;
+        g = 175;
+        b = 255;

       } else { // No player - gold block
         r = 255;
-        g = r-40;
-        b = 40;
+        g = 125;
+        b = 10;
       }
     }
-
-    strip.setPixelColor(random(0, 10), max(0, r-flicker), max(0, g-flicker), max(0, b-flicker));
+    flicker = random(0, 24) - 12;
+    strip.setPixelColor(random(0, 10), max(0, min(255,r+flicker)), max(0, min(255,g+flicker)), max(0, min(255,b+flicker)));
     strip.show();
   }


updated RelayControl

updated RelayControl

cleaned up the status topic string creating


remove old neopixel library comments

remove old neopixel library comments

--- HalloweenCostume_FASTLED_VERSION.ino
+++ HalloweenCostume_FASTLED_VERSION.ino
@@ -41,12 +41,6 @@
 CRGB pixels_r[NUMPIXELS_R];

-// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
-// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
-// example for more information on possible values.
-//Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
-//Adafruit_NeoPixel pixels_l = Adafruit_NeoPixel(NUMPIXELS_L, PIN_L, NEO_GRB + NEO_KHZ800);
-//Adafruit_NeoPixel pixels_r = Adafruit_NeoPixel(NUMPIXELS_R, PIN_R, NEO_GRB + NEO_KHZ800);

 /* BUTTON CONFIG DELAY */
 const int bounceDelay = 20; // delay to detect debounce
@@ -218,7 +212,7 @@

     }

-    //TODO CLEAR button event - move this when we handle individual presses
+    // clear button event
     buttonEvent = 0;
   }

@@ -515,7 +509,7 @@

     for (int j=0; j < NUMPIXELS;j++ ){

-      // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
+
       if (currpos == j) {
           pixels[j] = CRGB::White;
       }
@@ -539,13 +533,11 @@
 void rect() {
    // every 2th animation frame
     if (animationframe % 2 != 0) return;
-    // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
     int i = (animationframe/2) % NUMPIXELS;
     int times = (animationframe/2)/(NUMPIXELS);
       for (int j=0; j < NUMPIXELS;j++ ){

-      // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
-      if (i%12 == j%12 || (j+6 + ((i+NUMPIXELS*times)/7)) % 12 == i  % 12) {
+     if (i%12 == j%12 || (j+6 + ((i+NUMPIXELS*times)/7)) % 12 == i  % 12) {
       pixels[j].setHue(animationframe%256); // superbright white

      }
@@ -563,11 +555,9 @@
 void square() {
    // every 2th animation frame
     if (animationframe % 2 != 0) return;
-    // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
     int i = (NUMPIXELS -1) - ((animationframe/2) % NUMPIXELS);
       for (int j=0; j < NUMPIXELS;j++ ){

-      // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
       if (i%6 == j%6 ) {
         pixels[j].setHue(animationframe%256);

@@ -593,7 +583,6 @@

     for (int j=0; j < NUMPIXELS;j++ ){

-      // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
       if (j <= 4 || j == 9 || j == 15 || j >=20 ) {
           pixels[(j+i)%NUMPIXELS].setHue((i*4)%256); // from colorwheel
       }
@@ -611,7 +600,6 @@

     for (int j=0; j < NUMPIXELS;j++ ){

-      // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
       if (j/12 == i % 2) {
           pixels[(j+i)%NUMPIXELS].setHue( ((i*4)+((i%2)*128))%256); // from colorwheel
       }
@@ -630,7 +618,6 @@

     for (int j=0; j < NUMPIXELS;j++ ){

-      // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
       if (j/6 == i % 4) {
           pixels[j].setHue((i*8)%256); // from colorwheel
       }
@@ -660,7 +647,6 @@

     for (int j=0; j < NUMPIXELS;j++ ){

-      // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
       if ((i==j || NUMPIXELS-j == i) && i < 6) {
         pixels[j] = CRGB::Fuchsia;

@@ -731,10 +717,8 @@
   if (animationframe % 2 != 0) return;
   int i = (animationframe / 2) % NUMPIXELS;

-    // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
     for (int j=0; j < NUMPIXELS;j++ ){

-      // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
     if (i%8 == j%8 ) {
         pixels[j] = CRGB::White;
     }
@@ -757,7 +741,6 @@

     for (int j=0; j < NUMPIXELS;j++ ){

-    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
     if (((NUMPIXELS + (j - i) )% NUMPIXELS) < 6 ) {

     pixels[j] = CHSV(animationframe%256, 255, pixelbright);


Make it more portable across different Arduinos

--- avr/avr.ino
+++ avr/avr.ino
@@ -55,6 +55,11 @@
 int pwm_i = 0; // Current PWM cycle
 uint8_t *buf_pwm = buf_a[0];

+// Hardware configuration
+uint8_t pin_col[] = {6, 7, A0, A1, A2, A3, A4, A5};
+#define PIN_ROW_LATCH 4
+#define PIN_COL_LATCH 5
+
 // Serial access
 unsigned int byte_i;
 uint8_t bit_i;
@@ -174,25 +179,24 @@
 }

 void driveDisplay() {
+	static int cur_pin = pin_col[0];
+
 	// Main screen turn off.
-	PORTC = 0xFF;
-	PORTD = 0xFF; // Latch data on pin 5 at the same time
+	digitalWrite(cur_pin, HIGH);
+	digitalWrite(PIN_COL_LATCH, HIGH);

 	// Switch the row on row driver if needed
 	if (col_iter == 0) {
 		SPI.transfer(1 << row_i);

 		// Latch it
-		digitalWrite(4, LOW);
-		digitalWrite(4, HIGH);
+		digitalWrite(PIN_ROW_LATCH, LOW);
+		digitalWrite(PIN_ROW_LATCH, HIGH);
 	}

 	// Main screen turn on!
-	if (col_i < 2) {
-		PORTD = ~((1 << 6) << col_i);
-	} else {
-		PORTC = ~(1 << (col_i-2));
-	}
+	cur_pin = pin_col[col_i];
+	digitalWrite(cur_pin, LOW);

 	// After turning on the screen, we have "plenty" of CPU cycles
 	// to spend. Preparing a new segment to display.
@@ -225,7 +229,7 @@

 	// Column driver latches on rising edge so we can already pull
 	// it down.
-	digitalWrite(5, LOW);
+	digitalWrite(PIN_COL_LATCH, LOW);

 	// Send new data via SPI. Don't need to wait it to complete
 	// because it completes before the next timer interrupt.


Update ControlViaSerialAndBluetooth.ino

Update ControlViaSerialAndBluetooth.ino

ControlViaSerialANDBluetooth changed input to INPUT_JACK_AS_MIC

--- examples/02-Utility/ControlViaSerialAndBluetooth/ControlViaSerialAndBluetooth.ino
+++ examples/02-Utility/ControlViaSerialAndBluetooth/ControlViaSerialAndBluetooth.ino
@@ -71,8 +71,8 @@
   audioHardware.enable(); // activate AIC

   //Choose the desired input
-  audioHardware.inputSelect(TYMPAN_INPUT_ON_BOARD_MIC); // use the on board microphones
-  // audioHardware.inputSelect(TYMPAN_INPUT_JACK_AS_MIC); // use the microphone jack - defaults to mic bias 2.5V
+  //audioHardware.inputSelect(TYMPAN_INPUT_ON_BOARD_MIC); // use the on board microphones
+  audioHardware.inputSelect(TYMPAN_INPUT_JACK_AS_MIC); // use the microphone jack - defaults to mic bias 2.5V
   // audioHardware.inputSelect(TYMPAN_INPUT_JACK_AS_LINEIN); // use the microphone jack - defaults to mic bias OFF

   //Set the desired volume levels


Testing string function

Testing string function

--- module/module.ino
+++ module/module.ino
@@ -14,8 +14,7 @@

 	// Set up serial communication
 	Serial.begin(monitorBaud);
-	strcpy_P(stringBuffer, (char*)pgm_read_word( &(message[initialize]) ));
-	Serial.print(stringBuffer);
+	getStringFromMem(initialize);
 	WIFI.begin(moduleBaud);
 	connectWIFI();

@@ -333,3 +332,8 @@
 	}
 }

+void getStringFromMem(int index) {
+	char stringBuffer[stringSize];
+	strcpy_P(stringBuffer, (char*)pgm_read_word( &(message[index]) ));
+	Serial.print(stringBuffer);
+}


refactor lcd updating stuff into class

refactor lcd updating stuff into class

--- SmartAlarm.ino
+++ SmartAlarm.ino
@@ -165,6 +165,62 @@

 }

+/**
+ * updates LCD
+ * clock at 10Hz
+ * wifi status every ten seconds
+ */
+class DisplayUpdater {
+  // last updated
+  unsigned long LastUpdatedTime;
+  unsigned long LastUpdatedWifiStatus;
+  const unsigned long TimeUpdateInterval = 100; // 100ms
+  const unsigned long WifiUpdateInterval = 10000; // 10 seconds
+
+public:
+  DisplayUpdater() {
+    LastUpdatedTime = 0;
+    LastUpdatedWifiStatus = 0;
+  }
+
+  void update(LiquidCrystal_I2C& lcd, RTC_DS1307& rtc, Adafruit_CC3000& cc3000) {
+    // is it time yet?
+    if ((millis() - LastUpdatedTime) > TimeUpdateInterval) {
+      LastUpdatedTime = millis();
+      now = rtc.now();
+      lcd.setCursor(0,3);
+      lcd.print("                    "); // clear that line
+      lcd.setCursor(0,3);
+      lcd.print(now.year()); lcd.print('-');
+      lcd.print(now.month()); lcd.print('-');
+      lcd.print(now.day()); lcd.print(' ');
+      lcd.print(now.hour()); lcd.print(':');
+      lcd.print(now.minute()); lcd.print(':');
+      lcd.print(now.second());
+    } else if ((millis() - LastUpdatedWifiStatus) > WifiUpdateInterval) {
+      LastUpdatedWifiStatus = millis();
+      lcd.setCursor(0,0);
+      if (cc3000.checkConnected()) {
+        lcd.print("ssid: ");
+        uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
+        char ipbuf[17];
+        cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv);
+        lcd.setCursor(0,1);
+        lcd.print(WLAN_SSID);
+        lcd.setCursor(0,2);
+        lcd.print("ip: ");
+        sprintf(ipbuf, "%d.%d.%d.%d", (uint8_t)(ipAddress>>24), (uint8_t)(ipAddress>>16), (uint8_t)(ipAddress>>8), (uint8_t)(ipAddress));
+        lcd.print(ipbuf);
+      } else {
+        lcd.clear();
+        lcd.print("disconnected!");
+      }
+    }
+  }
+};
+
+DisplayUpdater DU;
+
 void setup() {
   // serial debug connection
   Serial.begin(115200);
@@ -225,27 +281,6 @@
 void loop() {
   // put your main code here, to run repeatedly:
   now = rtc.now();
-  lcd.setCursor(0,0);
-  if (cc3000.checkConnected()) {
-    lcd.print("ssid: ");
-    uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
-    char ipbuf[17];
-    cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv);
-    lcd.setCursor(0,1);
-    lcd.print(WLAN_SSID);
-    lcd.setCursor(0,2);
-    lcd.print("ip: ");
-    sprintf(ipbuf, "%d.%d.%d.%d", (uint8_t)(ipAddress>>24), (uint8_t)(ipAddress>>16), (uint8_t)(ipAddress>>8), (uint8_t)(ipAddress));
-    lcd.print(ipbuf);
-  } else {
-    lcd.print("disconnected!");
-  }
+  DU.update(lcd, rtc, cc3000);

-  lcd.setCursor(0,3);
-  lcd.print(now.year()); lcd.print('-');
-  lcd.print(now.month()); lcd.print('-');
-  lcd.print(now.day()); lcd.print(' ');
-  lcd.print(now.hour()); lcd.print(':');
-  lcd.print(now.minute()); lcd.print(':');
-  lcd.print(now.second());
-}
+}


move up mutt check

move up mutt check

--- _04-mqtt-lcd-dust-sensor/_04-mqtt-lcd-dust-sensor-esp-12/_04-mqtt-lcd-dust-sensor-esp-12.ino
+++ _04-mqtt-lcd-dust-sensor/_04-mqtt-lcd-dust-sensor-esp-12/_04-mqtt-lcd-dust-sensor-esp-12.ino
@@ -431,6 +431,27 @@
 void loop()
 {
   if (timeStatus() != timeNotSet) {
+
+    if (WiFi.status() == WL_CONNECTED) {
+      if (!client.connected()) {
+        if  (
+          client.connect(MQTT::Connect((char*) clientName.c_str()).set_clean_session().set_keepalive(120))) {
+          client.subscribe(subtopic);
+          client.publish(hellotopic, "hello from ESP8266 s03");
+          client.set_callback(callback);
+        }
+      }
+
+      if (client.connected()) {
+        client.loop();
+      } else {
+        ESP.restart();
+      }
+    } else {
+        Serial.println("Could not connect to WIFI");
+        ESP.restart();
+    }
+
     if (now() != prevDisplay) { //update the display only if time has changed
       prevDisplay = now();
       digitalClockDisplay();
@@ -443,27 +464,6 @@
       }
       */
       checkDisplayValue();
-    }
-
-
-    if (WiFi.status() == WL_CONNECTED) {
-      if (!client.connected()) {
-        if  (
-          client.connect(MQTT::Connect((char*) clientName.c_str()).set_clean_session().set_keepalive(120))) {
-          client.subscribe(subtopic);
-          client.publish(hellotopic, "hello from ESP8266 s03");
-          client.set_callback(callback);
-        }
-      }
-
-      if (client.connected()) {
-        client.loop();
-      } else {
-        ESP.restart();
-      }
-    } else {
-        Serial.println("Could not connect to WIFI");
-        ESP.restart();
     }
   }
 }


updated indicator leds logic

updated indicator leds logic

--- src/analog_sensors_board.ino
+++ src/analog_sensors_board.ino
@@ -141,6 +141,9 @@
 int status_water_fwd = HIGH;
 int status_water_aft = HIGH;
 int status_sw_motor = LOW;
+int status_led_green = LOW;
+int status_led_yellow = LOW;
+int status_led_red = LOW;

 // the setup routine runs once when you press reset
@@ -171,18 +174,22 @@
     pinMode(WATER_FWD, INPUT);
     pinMode(WATER_AFT, INPUT);

-    // LED flash
-    digitalWrite(LED_GREEN, HIGH);
-    digitalWrite(LED_YELLOW, HIGH);
-    digitalWrite(LED_RED, HIGH);
+    for(int i=0; i<4; i++){
+        // LED flash on
+        digitalWrite(LED_GREEN, HIGH);
+        digitalWrite(LED_YELLOW, HIGH);
+        digitalWrite(LED_RED, HIGH);
+
+        delay(DELAY_LEDS);
+
+        // LED flash off
+        digitalWrite(LED_GREEN, LOW);
+        digitalWrite(LED_YELLOW, LOW);
+        digitalWrite(LED_RED, LOW);
+    }

     // (reset) protection delay
-    delay(1000);
-
-    // LED flash
-    digitalWrite(LED_GREEN, LOW);
-    digitalWrite(LED_YELLOW, LOW);
-    digitalWrite(LED_RED, LOW);
+    //delay(1000);

     // enable watchdog
     wdt_enable(WDTO_8S);
@@ -204,26 +211,36 @@
     status_water_aft = digitalRead(WATER_AFT);
     status_sw_motor = digitalRead(SW_MOTOR);

-    if(status_sw_motor == HIGH) {
-        digitalWrite(LED_GREEN, HIGH);
+    if(status_sw_motor == LOW) {
+        status_led_green = 0x01;
     } else {
-        digitalWrite(LED_GREEN, LOW);
-    }
-
-    if(status_water_fwd == HIGH || status_water_aft == HIGH) {
-        digitalWrite(LED_RED, HIGH);
+        status_led_green = 0x01 ^ status_led_green;
+    }
+
+    if(true) {
+       status_led_yellow = 0x01;
     } else {
-        digitalWrite(LED_RED, LOW);
-    }
-
-    // // led slow-loop delta
-    // delta = millis() - time_leds;
-
-    // if(delta >= DELAY_LEDS) {
-
-    //     // update timestamp
-    //     time_leds = millis();
-    // }
+       status_led_yellow = 0x01 ^ status_led_yellow;
+    }
+
+    if(status_water_fwd == HIGH && status_water_aft == HIGH) {
+        status_led_red = 0x01;
+    } else {
+        status_led_red = 0x01 ^ status_led_red;
+    }
+
+    // led slow-loop delta
+    delta = millis() - time_leds;
+
+    if(delta >= DELAY_LEDS) {
+        // led indications
+        digitalWrite(LED_GREEN, status_led_green);
+        digitalWrite(LED_YELLOW, status_led_yellow);
+        digitalWrite(LED_RED, status_led_red);
+
+        // update timestamp
+        time_leds = millis();
+    }

     // serial control
@@ -348,6 +365,10 @@
         report_humidity();

+        // send indicators report
+        report_indicators();
+
+
         // send timestamp
         Serial.print("$TIME,");
         Serial.println(time_slow, DEC);
@@ -358,6 +379,15 @@

     // reset watchdog
     wdt_reset();
+}
+
+void report_indicators() {
+    Serial.print("$IND,");
+    Serial.print(sta, 4);
+    Serial.print(',');
+    Serial.print(raw_acs0, DEC);
+    Serial.print(',');
+    Serial.println(millis(), DEC);
 }


Arduino solar_value support

Arduino solar_value support

--- arduino/bp2013h1_sketch1.ino
+++ arduino/bp2013h1_sketch1.ino
@@ -7,7 +7,7 @@
 int plant1_value = 0;
 int plant2_value = 0;
 int plant3_value = 0;
-int plant4_value = 0;
+int voltage_value = 0;
 int temperature_value = 0;
 int light_value = 0;

@@ -16,6 +16,7 @@

 int incomingByte = 0; // for incoming serial data

+float solar_value = 0.0f;
 float temperature = 0.0f;
 float resistance = 0.0f;

@@ -34,7 +35,7 @@
     plant1_value = analogRead(A0);
     plant2_value = analogRead(A1);
     plant3_value = analogRead(A2);
-    plant4_value = analogRead(A3);
+    voltage_value = analogRead(A3);
     light_value = analogRead(A4);
     temperature_value = analogRead(A5);

@@ -58,6 +59,9 @@
             Serial.println("{ \"relay_state\": 0 }");
         } else { // otherwise, reply with sensor data

+            // voltage mapping
+            solar_value = (10 * (float)voltage_value * 4980)/1023000;
+
             // temperature mapping to celsius
             resistance=(float)(1023-temperature_value)*10000/temperature_value;
             temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;
@@ -69,8 +73,8 @@
             Serial.print(plant2_value);
             Serial.print(", \"plant3_value\": ");
             Serial.print(plant3_value);
-            Serial.print(", \"plant4_value\": ");
-            Serial.print(plant4_value);
+            Serial.print(", \"solar_value\": ");
+            Serial.print(solar_value);
             Serial.print(", \"light_value\": ");
             Serial.print(light_value);
             Serial.print(", \"temperature_value\": ");


made it possible to use longer on periods

--- hacks/smart_psu/smart_psu/smart_psu.ino
+++ hacks/smart_psu/smart_psu/smart_psu.ino
@@ -6,7 +6,9 @@
 #define POWER_SWITCH_PIN 0
 #define MAX1555_CHG_PIN 2
 #define SECONDS_TO_SLEEP 400 // Multiple of 8
-#define SECONDS_ON 3
+#define SECONDS_ON 60L // For rf_temp_sensor, seconds on is 3, tracker version, seconds on is 60
+
+//NB: Remember to compile for 1 mhz internal clock.

 long internal_v = 0;
 long watchdog_counter = 0;
@@ -118,7 +120,7 @@
     digitalWrite(GREEN_PIN, LOW);
     digitalWrite(RED_PIN, LOW);

-    delay(1000*SECONDS_ON-1000);
+    delay(1000L*SECONDS_ON-1000L); // Use long numbers to handle long seconds on periods

     for (int i=0; i<5; i++) {
         digitalWrite(RED_PIN, HIGH);


Recalibrated statuses and tided code.

Recalibrated statuses and tided code.


待ち時間修正

待ち時間修正

--- 2_example/example07_temp/example07_temp.ino
+++ 2_example/example07_temp/example07_temp.ino
@@ -38,7 +38,7 @@
     float temp;                             // 温度値用の変数

     digitalWrite(PIN_EN,HIGH);              // センサ用の電源をONに
-    delay(10);                              // 起動待ち時間
+    delay(100);                             // 起動待ち時間
     temp=(float)system_adc_read();          // AD変換器から値を取得
     digitalWrite(PIN_EN,LOW);               // センサ用の電源をOFFに
     temp *= 1000. / 1023. / 10.;            // 温度(相対値)へ変換


Added "bis init" capability

Added "bis init" capability

--- software/_proto_DriverFirmware/MainControlFirmware/MainControlFirmware.ino
+++ software/_proto_DriverFirmware/MainControlFirmware/MainControlFirmware.ino
@@ -75,6 +75,9 @@
 const uint8_t charsL [16] = {0b1000000,0b1111001,0b0100100,0b0110000,0b0011001,0b0010010,0b0000010,0b1111000,0b0000000,0b0010000,0b0001000,0b0000011,0b1000110,0b0100001,0b0000110,0b0001110};  //Contains the constants for the 7seg values
 const uint8_t nothingL = 0b1111111;
 const uint8_t errorL = 0b0110110;
+const uint8_t iL = 0b1111011; //Just segment c_str
+const uint8_t tL = 0b0000111; // c d e f g
+const uint8_t nL = 0b0101011; //c g e

 enum MasterStates {
   POLLING,
@@ -103,41 +106,19 @@
 	i = ++i%10;
 	char temp[2];

-	disp.setLeft("B1");
-	disp.setRight('5');
-	//disp.setAll("b15 ");
+	//disp.setLeft("B1");
+	//disp.setRight("it");
+	disp.setAll("bi5 ");
+	disp2.setAll("init");

 	//disp2.setAll('5');
+	/*
 	disp2.setLeft('5');
 	temp[0] = i + 48;
 	temp[1] = '4'; //4 + 48;
 	disp2.setRight(temp);
+	*/
   }
-
-
-
-
-  disp.writeToDisplay();
-  disp2.writeToDisplay();
-
-  /*
-  PCComm.print("[Wrote '");
-  PCComm.print(to_write, BIN);
-  PCComm.print("' to board timing: ");
-  PCComm.print(timing);
-  PCComm.print("]\n\r");
-  */
-
-  ++timing;
-
-  timing = timing % TIMING_CONSTANT;
-
-}
-
-//Drives the I2C interface for the displays
-void dispDrive(){
-
-  PCComm.println("[dispDrive]");

   switch(CurrentState) {
     case DISPLEFT:
@@ -152,6 +133,30 @@
       break;
   }

+  disp.writeToDisplay();
+  disp2.writeToDisplay();
+
+  /*
+  PCComm.print("[Wrote '");
+  PCComm.print(to_write, BIN);
+  PCComm.print("' to board timing: ");
+  PCComm.print(timing);
+  PCComm.print("]\n\r");
+  */
+
+  ++timing;
+
+  timing = timing % TIMING_CONSTANT;
+
+}
+
+//Drives the I2C interface for the displays
+void dispDrive(){
+
+  //PCComm.println("[dispDrive]");
+
+
+

 }

@@ -184,6 +189,15 @@
 	else if (left_digit == ' '){
 		to_write += nothingL;
 	}
+	else if (left_digit == 't'){
+		to_write += tL;
+	}
+	else if (left_digit == 'i'){
+		to_write += iL;
+	}
+	else if (left_digit == 'n'){
+		to_write += nL;
+	}
 	else {
 		to_write += errorL;
 	}
@@ -196,6 +210,15 @@
 	}
 	else if (right_digit == ' '){
 		to_write += (nothingL << 8);
+	}
+	else if (right_digit == 't'){
+		to_write += (tL << 8);
+	}
+	else if (right_digit == 'i'){
+		to_write += (iL << 8);
+	}
+	else if (right_digit == 'n'){
+		to_write += (nL << 8);
 	}
 	else {
 		to_write += (errorL << 8);


bipolar.ino removed obsolete

bipolar.ino removed obsolete

--- bipolar.ino
+++ bipolar.ino
@@ -1,19 +0,0 @@
-
-void setup() {
-  Serial.begin(115200);
-
-  byte high = 0x7F;
-  byte mid = 0xFF;
-  byte low = 0xFF;
-  unsigned long value = ((unsigned long)high << 16) | ((unsigned long)mid << 8) | low;
-  if (~high & 0x80) {
-    Serial.println("high");
-    value = ~value;
-    //value -= 1;
-  }
-  value &= ~((unsigned long)1 << 23);
-  Serial.println(value);
-}
-
-void loop() {
-}


finally got timing and logic worked out...ish is getting complex

--- controlBox.ino
+++ controlBox.ino
@@ -9,6 +9,7 @@
 unsigned long measureInterval = 60000; // can send data to thingspeak every 15s, but once a minute is fine

 bool pumpOn = false;
+heardFromSensor = false;
 float waterHeight = 1000; // we want to make sure the relay isn't falsely triggered on from the get-go
 //################### update these vars ###################
 float lowerCutoff = 20; // lowest acceptable water height, in inches
@@ -20,7 +21,7 @@
 unsigned long lastSignal = millis();
 unsigned long pumpTimeout = 15*60*1000; // turn off the pump if haven't heard from sensor in 15 mins
 unsigned long pumpOffTime = 60*60*1000; // make sure we don't turn on the pump more than once per hour
-long pumpOffTimeStart = -pumpOffTime; // so we can turn on pump when we startup if we need to
+long lastPumpTimeOff = -60*60*1000; // so we can turn on pump when we startup if we need to

 // PIR motion sensor
 int relayPin = 0;
@@ -69,17 +70,20 @@
 }

 void autoPumpControl() {
-	if (pumpOn) {
-		if (millis() - lastSignal > pumpTimeout) { // if we haven't heard from the water tanks in a while, turn off the pump
-			relayControl("off");
+	if (heardFromSensor) {
+		if (pumpOn) {
+			if (millis() - lastSignal > pumpTimeout) { // if we haven't heard from the water tanks in a while, turn off the pump
+				relayControl("off");
+			}
 		}
-	}
-	if (waterHeight < lowerCutoff && millis() - pumpOffTimeStart > pumpOffTime) {
-		success = relayControl("on");
-	} else if (waterHeight > higherCutoff) {
-		success = relayControl("off");
-	} else {
-		Serial.println("not doin nothin");
+		if (waterHeight < lowerCutoff && millis() - lastPumpTimeOff > pumpOffTime) {
+			success = relayControl("on");
+		} else if (waterHeight > higherCutoff) {
+			success = relayControl("off");
+			lastPumpTimeOff = millis();
+		} else {
+			Serial.println("not doin nothin");
+		}
 	}
 }

@@ -119,6 +123,7 @@
 		Particle.publish(eventPrefix + "/waterTankPump/pumpOn", boolToText(pumpOn));
 		(data == "true") ? lastSignal = millis() : Serial.println(data);
 	} else if (event == eventPrefix + "/waterTankSensor/waterHeight") {
+		heardFromSensor = true;
 		waterHeight = data.toFloat();
 	}
 }


added watchdog and set antenna selection back to external

--- firmware/src/PoolBuddy.ino
+++ firmware/src/PoolBuddy.ino
@@ -10,6 +10,10 @@

 // Set external antenna (remembered after power off)
 STARTUP(WiFi.selectAntenna(ANT_EXTERNAL));
+//STARTUP(WiFi.selectAntenna(ANT_AUTO));
+
+// Reset application if unresponsive for 3 minutes
+ApplicationWatchdog wd(180000, System.reset);

 DS18B20 ds18b20(TEMP_SENSOR);
 int nextSampleTime, nextSleepTime, sleepInterval;


Explicitly connect to the Particle cloud as we normally run in semi-automatic mode

--- Particle/THLMqttSensor/src/THLMqttSensor.ino
+++ Particle/THLMqttSensor/src/THLMqttSensor.ino
@@ -178,6 +178,8 @@
     }
     // run a loop of the MQTT client lib
     client.loop();
+    // connect to the Particle cloud
+    Particle.connect();
     // and keep WiFi on for other Photon activities/upgrades
   }
   else {


added blinkmstart

added blinkmstart

--- BlinkM/examples/BlinkMStart/BlinkMStart.ino
+++ BlinkM/examples/BlinkMStart/BlinkMStart.ino
@@ -41,7 +41,7 @@
     Serial.print("Fading to hue ");
     Serial.println(hue);

-    //blinkm.fadeToHSB( hue, 255, 255);
+    blinkm.fadeToHSB( hue, 255, 255);

     delay(1000);
   }


BLE example sketch: Don't instantiate a new BLE() object until the Serial has been started (Serial->begin)

--- examples/07-Bluetooth/01-BasicGain_wApp_BLE/01-BasicGain_wApp_BLE.ino
+++ examples/07-Bluetooth/01-BasicGain_wApp_BLE/01-BasicGain_wApp_BLE.ino
@@ -35,7 +35,7 @@

 usb_serial_class *USB_Serial = &Serial;
 HardwareSerial *BT_Serial = &Serial1;
-BLE ble = BLE(&Serial1);
+BLE *ble;
 String msgFromBle = String(""); // Message from ble
 int msgLen;

@@ -53,6 +53,10 @@

   //allocate the dynamic memory for audio processing blocks
   AudioMemory_F32(10);
+
+  //create BLE object
+  USB_Serial->println("Setup: new BLE()...");
+  ble = new BLE(&Serial1);

   //Enable the Tympan to start the audio flowing!
   myTympan.enable(); // activate the Tympan's audio module


COH:25: $Id$ working?

COH:25: $Id$ working?

--- COHEAT2015/testBranch20150719/V0p2_Main/V0p2_Main.ino
+++ COHEAT2015/testBranch20150719/V0p2_Main/V0p2_Main.ino
@@ -173,7 +173,7 @@
   {
   serialPrintAndFlush(F("board V0.2 REV"));
   serialPrintAndFlush(V0p2_REV);
-  serialPrintAndFlush(F("; code $Id$ ")); // Expect SVN to substitute the Id keyword here with svn:keywords property set.
+  serialPrintAndFlush(F("; code $Id: ebf1e586609ba1370e863d4011681e8f73d1713f $ ")); // Expect SVN/git to substitute the Id keyword here with svn:keywords property set.
   serialPrintAndFlush(_YYYYMmmDD);
   serialPrintAndFlush(F(" " __TIME__));
   serialPrintlnAndFlush();


the string returned by G command is guarded by G and #

--- jenny5-firmware/jenny5-firmware.ino
+++ jenny5-firmware/jenny5-firmware.ino
@@ -22,11 +22,11 @@

 char is_command_running;

-char firmware_version[] = "2015.12.27.1";// year.month.day.build number
+char firmware_version[] = "2015.12.27.2";// year.month.day.build number

 char current_buffer[65];

-#define DEBUG
+//#define DEBUG

 //--------------------------------------------------------------------------------------------
 void setup()
@@ -201,6 +201,7 @@
               else{
                           // for all motors, unformated data
                 int index;
+                Serial.write("G ");
                 for(index = 0; index < motors_control.num_motors; index++) {
                   Serial.write("Motor: ");
                   Serial.println(index);
@@ -218,6 +219,7 @@
                       Serial.println(potentiometers_control.isWithinLimits(sensor_index));
                     }
                 }
+                Serial.write("#");
                 i++;
               }
         }


tidyup of comments

tidyup of comments

--- Arduino/hardware/REV10/REV10SecureBHR/REV10SecureBHR.ino
+++ Arduino/hardware/REV10/REV10SecureBHR/REV10SecureBHR.ino
@@ -231,7 +231,6 @@
  * INTERRUPT SERVICE ROUTINES
  *****************************************************************************/

-// Controller's view of Least Significant Digits of the current (local) time, in this case whole seconds.
 // Previous state of port B pins to help detect changes.
 //
 // NOTE: PrimaryRadio may switch PCINT0 on and off during operation! This pin bank should not be relied
@@ -447,16 +446,12 @@
         // frame-length byte for encrypted frame.
         uint8_t *const realTXFrameStart = sW.buf + 1;

-        // If forcing encryption or if unconditionally suppressed
-        // then suppress the "@" ID field entirely,
-        // assuming that the encrypted commands will carry the ID, ie in the 'envelope'.
+        // Forcing encryption so suppress the "@" and "+" ID fields,
+        // assuming that the encrypted commands will carry these in the 'envelope'.
         ss1.setID(V0p2_SENSOR_TAG_F(""));
+        ss1.enableCount(false);

         // Managed JSON stats.
-        // Enable "+" count field for diagnostic purposes, eg while TX is lossy,
-        // if the primary radio channel does not include a sequence number itself.
-        // Assume that an encrypted channel will provide its own (visible) sequence counter.
-        ss1.enableCount(false);
         // Show internal temperature of boiler hub.
         ss1.put(TemperatureC16);
         // Show boiler state for boiler hubs.
@@ -467,7 +462,8 @@
         const size_t curMinSP = OTV0P2BASE::MemoryChecks::getMinSP();
         const uint8_t txMinSP = (255U >= curMinSP) ? (uint8_t) curMinSP : 255U;
         ss1.put(V0p2_SENSOR_TAG_F("SP"), txMinSP, true);
-        // OPTIONAL items
+
+        // Always TX in this case, as channel is secure.
         constexpr uint8_t privacyLevel = OTV0P2BASE::stTXalwaysAll;

         // Redirect JSON output appropriately.


changed naming

changed naming

--- arduino-heli-control.ino
+++ arduino-heli-control.ino
@@ -1,5 +1,5 @@
 #include "lib/tacho.h"
-//#include "lib/ircontrol.h"
+#include "lib/ircontrol.h"
 //#include "lib/mpusensor.h"

 #define Poti A0
@@ -11,16 +11,17 @@
 int debugIndex = 0;

 void setup() {
-//  setup_mpu();
-//  setup_ircontrol();
+  //mpusensor::setup();
+  ircontrol::setup();
   tacho::setup();
 }

 void loop() {
   throttle = analogRead(Poti);
-  //yaw = mpu::read_yaw();
-  //pitch = mpu::read_pitch();
-  //ir::sendControl(throttle, pitch, yaw);
+  //yaw = mpusensor::read_yaw();
+  //pitch = mpusensor::read_pitch();
+  ircontrol::sendControl(throttle, pitch, yaw);
   tacho::drawValues(throttle, pitch, yaw);
+  delay(50);
 }


git test

git test

git test (whitespace added)


Thermistor working.

Thermistor working.

--- sketch_steppermotor/sketch_steppermotor.ino
+++ sketch_steppermotor/sketch_steppermotor.ino
@@ -1,4 +1,5 @@
 #include <SPI.h>
+#include <math.h>

 // testing a stepper motor with a Pololu A4988 driver board or equivalent
 // on an Uno the onboard led will flash with each step
@@ -19,9 +20,15 @@
 float upTime = 0.5; //sec
 int platTime = 4; //sec
 int thermNozzle = 0;
-
+int fan0 = 8;
+const int BETA = 4267;
+const float R_ZERO = 100000.0;
+const float TO_VOLTS = 5.0/1024.0;
+const float R_INF = R_ZERO*exp(1.0*-BETA/298.0);
 void setup() {
   pinMode(13, OUTPUT);
+  pinMode(fan0, OUTPUT);
+  analogWrite(fan0, 0);
   Serial.begin(9600);

 //  pinMode(slaveSelectPin, OUTPUT);
@@ -79,8 +86,18 @@

 void loop() {
   digitalWrite(13, HIGH);
+//  float resistance = 4700.0*5.0/(1.0*analogRead(thermNozzle)*TO_VOLTS)-4700;
+  float resistance = 4700.0*1.0/(5/(1.0*analogRead(thermNozzle)*TO_VOLTS)-1);
+  String tov = "To Volts: " + String(TO_VOLTS, 9);
+  String res = "Resist: " + String(resistance);
+  String rinf = "R_INF: " + String(R_INF, 9);
+  Serial.println(tov);
+  Serial.println(res);
+  Serial.println(rinf);
+  float temp = BETA/log(resistance/R_INF)-273.15;
   Serial.println(analogRead(thermNozzle));
-  delay(100);
+  Serial.println(temp);
+  delay(1000);
   digitalWrite(13, LOW);
   delay(50);
 }


Changed adjustment angle to the maximum possible for step response analysis. Got rid of semicolon (made Excel burp). It worked.

--- sonar_error_mapping/sonar_error_mapping.ino
+++ sonar_error_mapping/sonar_error_mapping.ino
@@ -8,7 +8,7 @@
  * @author:    Tyler Lucas
  * Student ID: 3305203
  * Date:       October 6, 2017
- * Version     1.1
+ * Version     1.2
  *
  * References: N/A
  *
@@ -23,7 +23,7 @@

 #define angleMax 110
 #define angleMin 30
-#define angleAdjustmentMagnitude 10
+#define angleAdjustmentMagnitude 80 /* Changed to maximum possible. */

 #define timeDelayToNextAngle 1000

@@ -43,7 +43,7 @@
   servo.write( angle );

   Serial.println();
-  Serial.println("Printing time, input angle, and sonar measurement (echo pulse delay [us]).");
+  Serial.println("time [ms], input angle, sonar");

   delay(1000);
 }
@@ -68,7 +68,6 @@
     Serial.print( angle );
     Serial.write(',');
     Serial.print( sonarDuration );
-    Serial.write(';');
   }

   angle += angleAdjustment;


Formatting

Formatting

Formatted layout of comments and omitted some unnecesary code

--- WVO_Controller_0.6.3.ino
+++ WVO_Controller_0.6.3.ino
@@ -63,12 +63,12 @@
 #define CLK   32
 Adafruit_MAX31855 thermocouple(CLK, CS, DO);

-const int numReadings = 10.00;				// number of readings to be taken for temperature average
-int readings[numReadings];  				// the readings from the analog input
-int index = 0;              				// the index of the current reading
-int total = 0;              				// the running total
-int average = 0;            				// the average of temperature readings
-int oldaverage = 0;          				// the old average to overwrite on the scree
+const int numReadings = 10.00;				// number of readings to be taken for fuel temperature average
+int readings[numReadings];  				  // the readings from the analog input
+int index = 0;              				  // the index of the current reading
+int total = 0;              				  // the running total
+int average = 0;            				  // the average of temperature readings
+int oldaverage = 0;          				  // the old average to overwrite on the scree
 int temperaturePin = A11;			        // temperature input pin to read temperature of oil temperature
 int temp = 0;
 int EGT = 0;
@@ -85,22 +85,21 @@
 const int returnValve = 24;      			// red LED
 const int supplyValve = 26;    				// green LED, will also power bypass valve and Fuel pump Relay
 int page = 0;                  				// the page to prevent button pushes from working on pages where the button doesnt exist
-// homescreen = 0, settings = 2, purgeSetTime = 3, tempSet = 4
-int number = 0;						// unknown variable.....
-
-int purgeTime;					// purge time of the of valves in seconds. Set to 5 now for ease of troubleshooting.
-// minimum in purgeSetTime menu is 30. this value will be changed for final code.
-unsigned long Timer = 0;				// unkown variable.....
-boolean autoState;    				// whether the controller is running in auto or manual mode. Auto = 1, manual = 0.
-boolean oilState = 0;     				// whether the controller is switched to oil or not. Oil = 1, diesel = 0.
-boolean tempState = 0;     				// whether the temp is above or below set temp. Above setTemp = 1, below setTemp = 0.
-boolean oldtempState = 0;				// used to get into if statements only when tempState has just switched and oldTempState is different.
-boolean purgeState = 0;					// whether or not purgeTimer is running. Purging = 1, not purging = 0.
-int setTemp;       				// Automatic oil switch and purge temperature threshold in degrees Farenheit
-long previousMillis = 0;				// time in millis when purge timer function begins
+                                      // homescreen = 0, settings = 2, purgeSetTime = 3, tempSet = 4
+
+int purgeTime;					              // purge time of the of valves in seconds. Set to 5 now for ease of troubleshooting.
+                                      // minimum in purgeSetTime menu is 30. this value will be changed for final code.
+unsigned long Timer = 0;				      // unkown variable.....
+boolean autoState;    				        // whether the controller is running in auto or manual mode. Auto = 1, manual = 0.
+boolean oilState = 0;     				    // whether the controller is switched to oil or not. Oil = 1, diesel = 0.
+boolean tempState = 0;     				    // whether the temp is above or below set temp. Above setTemp = 1, below setTemp = 0.
+boolean oldtempState = 0;				      // used to get into if statements only when tempState has just switched and oldTempState is different.
+boolean purgeState = 0;					      // whether or not purgeTimer is running. Purging = 1, not purging = 0.
+int setTemp;       				            // Automatic oil switch and purge temperature threshold in degrees Farenheit
+long previousMillis = 0;				      // time in millis when purge timer function begins
 unsigned long currentMillis = 0;			// current time in millis compared to previousMillis to determine when purgeTime is met
-int countdown = 0;					// purgeTime left in seconds, to be displayed during purge process
-int oldCountdown = 0;					// old purgeTime value , compared to countdown to determine when to overwrite countdown value.
+int countdown = 0;					          // purgeTime left in seconds, to be displayed during purge process
+int oldCountdown = 0;					        // old purgeTime value , compared to countdown to determine when to overwrite countdown value.

 int backlightPin = 7;
 float backlightValue;
@@ -112,10 +111,6 @@
 int oldLightLevel;
 int lightLevel;

-//const int returnCheckPin = 34;                          // analog pin to check state of return valve with the use of a reed switch to check for magnetic field
-//const int bypassCheckPin = 36;                          // analog pin to check state of bypass valve with the use of a reed switch to check for magnetic field
-//const int supplyCheckPin = 38;                          // analog pin to check state of supply valve with the use of a reed switch to check for magnetic field
-
 boolean returnState = 0;
 boolean oldReturnState = 0;
 boolean bypassState = 0;
@@ -128,19 +123,19 @@
 int tempSetPointAddress = 2;
 int brightnessAddress = 3;

-int fuelLevel;                                          // value from 0 to 100 equating to the fuel level
-float fuelLevelVal;                                     // analog value from 728 to 254, read from the fuel level voltage divider;
-int xLength;                                            // length of bar in fuel level bar graph
+int fuelLevel;                            // value from 0 to 100 equating to the fuel level
+float fuelLevelVal;                       // analog value from 728 to 254, read from the fuel level voltage divider;
+int xLength;                              // length of bar in fuel level bar graph
 int oldxLength;
-int fuelLevelPin = A15;                                    // pin that is reading the voltage of the voltage divider for the fuel sender
-
-int readingP[numReadings];          // the readings from the analog input
-int indexP = 0;                      // the index of the current reading
-int sumP = 0;                      // the running total
+int fuelLevelPin = A15;                   // pin that is reading the voltage of the voltage divider for the fuel sender
+
+int readingP[numReadings];                // the readings from the analog input
+int indexP = 0;                           // the index of the current reading
+int sumP = 0;                             // the running total
 int psi = 0;
-int pressure = 0;                   // current fuel pressure
-int oldpressure = 0;                // old fuel pressure
-int pressurePin = A14;              // analog pressure pin
+int pressure = 0;                         // current fuel pressure
+int oldpressure = 0;                      // old fuel pressure
+int pressurePin = A14;                    // analog pressure pin
 double pressureVoltage;

 TouchScreen ts = TouchScreen(XP, YP, XM, YM);	        // values for coordinate system inputs on touchscreen.
@@ -148,26 +143,17 @@
 void setup()
 {
   dayLightVal = analogRead(A10);
-  //Serial.println(dayLightVal);
-  //backlightPerc = (0.0000003*(dayLightVal*dayLightVal*dayLightVal))-(0.0006*(dayLightVal*dayLightVal))+(0.397*dayLightVal);
-  //Serial.println(backlightPerc);
   backlightValue = 0.2138*dayLightVal + 20.5;
-  //Serial.println(backlightValue);
-  //backlightValue = ((backlightPercent*backlightPercent*backlightPercent)/3937) + 1.5;
-  //backlightValue = (127 * backlightPercent) / 50 + 1;
   analogWrite(backlightPin, backlightValue);
-  //Serial.println(backlightValue);

   Tft.TFTinit();                                        // init TFT library

-  pinMode(24, OUTPUT);					// needed to set digital pin to high at 5v for switching MOSFET
-  pinMode(26, OUTPUT);					// needed to set digital pin to high at 5v for switching MOSFET
+  pinMode(24, OUTPUT);					                        // needed to set digital pin to high at 5v for switching MOSFET
+  pinMode(26, OUTPUT);					                        // needed to set digital pin to high at 5v for switching MOSFET

   Serial.begin(9600);

-  //Tft.fillRectangle(0, 0, 239, 319, WHITE);
-
-  Tft.drawRectangle(10, 20, 220, 280, GREEN); 	    // (X-coord start, Y-coord start, X length, y length, color)
+  Tft.drawRectangle(10, 20, 220, 280, GREEN); 	        // (X-coord start, Y-coord start, X length, y length, color)
   Tft.drawString("OIL", 73, 38, 5, GREEN);
   Tft.drawString("OIL", 75, 40, 5, BLUE);
   delay(500);
@@ -189,12 +175,12 @@
   purgeTime = EEPROM.read(purgeTimeAddress);
   setTemp = EEPROM.read(tempSetPointAddress);

-  delay(3000);						// display boot screen for set time in millis
-  Tft.fillScreen();					// clear display
-
-  homescreen();						// draw homescreen once boot screen is cleared
-
-  Point p = ts.getPoint();				// setup point to read touch values
+  delay(3000);						                        // display boot screen for set time in millis
+  Tft.fillScreen();					                      // clear display
+
+  homescreen();						                        // draw homescreen once boot screen is cleared
+
+  Point p = ts.getPoint();				                // setup point to read touch values
   p.x = 0;
   p.y = 0;
 }
@@ -211,9 +197,6 @@
   Point p = ts.getPoint();
   p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);
   p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);
-
-  Serial.print("oil state ");
-  Serial.println(oilState);

   dayLightVal = analogRead(A10);
   //Serial.println(dayLightVal);
@@ -242,18 +225,12 @@
   //degreesC = (voltage - 0.5) * 100.0;
   //degreesF = degreesC * (9.0/5.0) + 32.0;
   // subtract the last reading:
-  total = total - readings[index];
-  // read from the sensor:
-  readings[index] = temp;
-  // add the reading to the total:
-  total = total + readings[index];
-  // advance to the next position in the array:
-  index = index + 1;
-  // if we're at the end of the array...
-  if (index >= numReadings)
-    // ...wrap around to the beginning:
-    index = 0;
-  // calculate the average:
+  total = total - readings[index];              // read from the sensor:
+  readings[index] = temp;                       // add the reading to the total:
+  total = total + readings[index];              // advance to the next position in the array:
+  index = index + 1;                            // if we're at the end of the array...
+  if (index >= numReadings)                     // ...wrap around to the beginning:
+    index = 0;                                  // calculate the average:
   average = total / numReadings;

 fuelGage();


Reorganised and commented Arduino sketch.

--- src/ArduinoSCPIParser/ArduinoSCPIParser.ino
+++ src/ArduinoSCPIParser/ArduinoSCPIParser.ino
@@ -3,6 +3,74 @@

 struct scpi_parser_context ctx;

+scpi_error_t identify(struct scpi_parser_context* context, struct scpi_token* command);
+scpi_error_t get_voltage(struct scpi_parser_context* context, struct scpi_token* command);
+scpi_error_t get_voltage_2(struct scpi_parser_context* context, struct scpi_token* command);
+scpi_error_t get_voltage_3(struct scpi_parser_context* context, struct scpi_token* command);
+scpi_error_t set_voltage(struct scpi_parser_context* context, struct scpi_token* command);
+scpi_error_t set_voltage_2(struct scpi_parser_context* context, struct scpi_token* command);
+
+void setup()
+{
+  struct scpi_command* source;
+  struct scpi_command* measure;
+
+  /* First, initialise the parser. */
+  scpi_init(&ctx);
+
+  /*
+   * After initialising the parser, we set up the command tree.  Ours is
+   *
+   *  *IDN?         -> identify
+   *  :SOURCE
+   *    :VOLTage    -> set_voltage
+   *    :VOLTage1   -> set_voltage_2
+   *  :MEASure
+   *    :VOLTage?   -> get_voltage
+   *    :VOLTage1?  -> get_voltage_2
+   *    :VOLTage2?  -> get_voltage_3
+   */
+  scpi_register_command(ctx.command_tree, SCPI_CL_SAMELEVEL, "*IDN?", 5, "*IDN?", 5, identify);
+
+  source = scpi_register_command(ctx.command_tree, SCPI_CL_CHILD, "SOURCE", 6, "SOUR", 4, NULL);
+  measure = scpi_register_command(ctx.command_tree, SCPI_CL_CHILD, "MEASURE", 7, "MEAS", 4, NULL);
+
+  scpi_register_command(source, SCPI_CL_CHILD, "VOLTAGE", 7, "VOLT", 4, set_voltage);
+  scpi_register_command(source, SCPI_CL_CHILD, "VOLTAGE1", 8, "VOLT1", 5, set_voltage_2);
+
+  scpi_register_command(measure, SCPI_CL_CHILD, "VOLTAGE?", 8, "VOLT?", 5, get_voltage);
+  scpi_register_command(measure, SCPI_CL_CHILD, "VOLTAGE1?", 9, "VOLT1?", 6, get_voltage_2);
+  scpi_register_command(measure, SCPI_CL_CHILD, "VOLTAGE2?", 9, "VOLT2?", 6, get_voltage_3);
+
+  /*
+   * Next, we set our outputs to some default value.
+   */
+  analogWrite(3, 0);
+  analogWrite(5, 0);
+
+  Serial.begin(9600);
+}
+
+void loop()
+{
+  char line_buffer[256];
+  unsigned char read_length;
+
+  while(1)
+  {
+    /* Read in a line and execute it. */
+    read_length = Serial.readBytesUntil('\n', line_buffer, 256);
+    if(read_length > 0)
+    {
+      scpi_execute_command(&ctx, line_buffer, read_length);
+    }
+  }
+}
+
+
+/*
+ * Respond to *IDN?
+ */
 scpi_error_t identify(struct scpi_parser_context* context, struct scpi_token* command)
 {
   scpi_free_tokens(command);
@@ -11,6 +79,9 @@
   return SCPI_SUCCESS;
 }

+/**
+ * Read the voltage on A0.
+ */
 scpi_error_t get_voltage(struct scpi_parser_context* context, struct scpi_token* command)
 {
   float voltage;
@@ -22,6 +93,9 @@
   return SCPI_SUCCESS;
 }

+/**
+ * Read the voltage on A1.
+ */
 scpi_error_t get_voltage_2(struct scpi_parser_context* context, struct scpi_token* command)
 {
   float voltage;
@@ -33,6 +107,9 @@
   return SCPI_SUCCESS;
 }

+/**
+ * Read the voltage on A2.
+ */
 scpi_error_t get_voltage_3(struct scpi_parser_context* context, struct scpi_token* command)
 {
   float voltage;
@@ -44,6 +121,9 @@
   return SCPI_SUCCESS;
 }

+/**
+ * Set the voltage using PWM on pin 3.
+ */
 scpi_error_t set_voltage(struct scpi_parser_context* context, struct scpi_token* command)
 {
   struct scpi_token* args;
@@ -88,6 +168,9 @@
   return SCPI_SUCCESS;
 }

+/**
+ * Set the voltage using PWM on pin 5.
+ */
 scpi_error_t set_voltage_2(struct scpi_parser_context* context, struct scpi_token* command)
 {
   struct scpi_token* args;
@@ -132,44 +215,3 @@
   return SCPI_SUCCESS;
 }

-void setup()
-{
-  struct scpi_command* source;
-  struct scpi_command* measure;
-
-  scpi_init(&ctx);
-
-  scpi_register_command(ctx.command_tree, SCPI_CL_SAMELEVEL, "*IDN?", 5, "*IDN?", 5, identify);
-
-  source = scpi_register_command(ctx.command_tree, SCPI_CL_CHILD, "SOURCE", 6, "SOUR", 4, NULL);
-  measure = scpi_register_command(ctx.command_tree, SCPI_CL_CHILD, "MEASURE", 7, "MEAS", 4, NULL);
-
-  scpi_register_command(source, SCPI_CL_CHILD, "VOLTAGE", 7, "VOLT", 4, set_voltage);
-  scpi_register_command(source, SCPI_CL_CHILD, "VOLTAGE1", 8, "VOLT1", 5, set_voltage_2);
-
-  scpi_register_command(measure, SCPI_CL_CHILD, "VOLTAGE?", 8, "VOLT?", 5, get_voltage);
-  scpi_register_command(measure, SCPI_CL_CHILD, "VOLTAGE1?", 9, "VOLT1?", 6, get_voltage_2);
-  scpi_register_command(measure, SCPI_CL_CHILD, "VOLTAGE2?", 9, "VOLT2?", 6, get_voltage_3);
-
-  analogWrite(3, 0);
-
-  Serial.begin(9600);
-}
-
-void loop()
-{
-  char line_buffer[256];
-  unsigned char read_length;
-
-  while(1)
-  {
-    read_length = Serial.readBytesUntil('\n', line_buffer, 256);
-    if(read_length > 0)
-    {
-      scpi_execute_command(&ctx, line_buffer, read_length);
-    }
-  }
-}
-
-
-


update of ino

update of ino

Updated with another requirement

--- Herba-Automata.ino
+++ Herba-Automata.ino
@@ -34,8 +34,9 @@
  *
  * Hardware Planned/Required:
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~
- * Arduino board, Req.
- * Soil moisture sensor, Req.
+ * Arduino board
+ * Soil moisture sensor
+ * Real time clock (premade OTS comp. or IC???)
  * Relay/s, Required for water/light control
  * Photosistor, Optional
  * Air temp./Humidity sensor, Optional


Fix KonamiContraBuzzer example indexes beyond the end of the defined array(!)

--- build/shared/examples/09.EducationalBP_MKII/KonamiContraBuzzer/KonamiContraBuzzer.ino
+++ build/shared/examples/09.EducationalBP_MKII/KonamiContraBuzzer/KonamiContraBuzzer.ino
@@ -222,7 +222,7 @@
       break;
     case 11:
       digitalWrite(RGB_BLUE_LED, 1);
-	  for (int thisNote = 0; thisNote < 80; thisNote++)
+	  for (int thisNote = 0; (sizeof(melody)/sizeof(int)); thisNote++)
 	  {

 		// to calculate the note duration, take one second


Refined protocol and channel structs.

Refined protocol and channel structs.

Made sure code compiles (even though it's incomplete).

--- teensy-stim/teensy-stim.ino
+++ teensy-stim/teensy-stim.ino
@@ -3,6 +3,7 @@
  */

 #include <EEPROM.h>
+#include <math.h>

 int eepsigN = 8;
 int idN = 12;
@@ -29,49 +30,50 @@
 };

 struct Protocol {
-  Dura t;
-  Dura d;
-  Dura y;
-  Dura n;
-  Dura p;
-  Dura q;
-  byte i;
-  byte s;
-  byte next;
+  Dura t;    // Total time
+  Dura d;    // Delay
+  Dura y;    // Stimulus on time
+  Dura n;    // Stimulus off time
+  Dura p;    // Pulse time
+  Dura q;    // Pulse off time
+  byte i;    // Invert? 0 = no
+  byte s;    // What is this for?
+  byte next; // Number of next protocol, 255 = none
   byte unused0;
-}
-
-struct State {
-  Dura t;
-  Dura yn;
-  Dura pq;
-  byte i;
-  byte s;
-  byte protocol;
-  byte runlevel;
-  byte pin;
+};
+
+struct Channel {
+  Dura t;        // Time remaining
+  Dura yn;       // Time until next stimulus status switch
+  Dura pq;       // Time until next pulse status switch
+  byte protocol; // Which protocol we're running, 255 = none
+  byte runlevel; // Runlevel 0 = off, 1 = stim off, 2 = stim on pulse off, 3 = pulse on
+  byte pin;      // The digital pin number for this output, or 255 = analog out
   byte unused0;
-  byte unused1;
-  byte unused2;
 };

 int proto_i = 0;
 Protocol protocols[PROT];

-State channels[CHAN];
+Channel channels[CHAN];

 int errormsgN = 12;
 byte errormsg[12];

 char buf[63];
+
+int tick;               // Last clock tick (microseconds), used to update time
+Dura global_clock;      // Counts up from the start of protocols
+volatile int running;   // Number of running channels.  0 = setup, values < 0 = error state

 void read_my_eeprom() {
   // Make sure the EEPROM corresponds to the expected device
   int i = 0;
   for (; i < eepsigN; i++) if (EEPROM.read(i) != eepsig[i]) {
-    char *msg = "wrong-ver"
-    runlevel = 255;
-    for (int j = 0; j < 9; j++) errormsg[j] = msg[j];
+    char msg[] = "wrong-ver";
+    running = -1;
+    int j = 0;
+    for (; j < 9; j++) errormsg[j] = msg[j];
     for (; j < errormsgN; j++) errormsg[j] = ' ';
     return;
   }
@@ -100,17 +102,17 @@
   }
 }

+void init_wave() {
+  for (int i = 0; i < 256; i++) {
+    wave[i] = 2047 + (short)round(2047*sin(i * 2 * M_PI));
+  }
+}
+
 void init_pins() {
   if (waveN > 0) analogWriteResolution(12);
   pinMode(LED_PIN, OUTPUT);
   for (int i = 0; i < digiN; i++) pinMode(digi[i], OUTPUT);
 }
-
-int tick;
-Dura global_clock;
-volatile int running;
-volatile int errorcode;
-volatile bool finished;

 void advance(Dura *x, int us) {
   x->u += us;
@@ -141,17 +143,26 @@
   Serial.begin(115200);
   ARM_DEMCR |= ARM_DEMCR_TRCENA;
   ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA;
-  fix = micros();
-  for (int i = 0; i < PROT; i++) protocols[i].protocol = 255;
+  for (int i = 0; i < PROT; i++) protocols[i].next = 255;
   for (int j = 0; j < CHAN; j++) channels[j].protocol = 255;
   running = 0;
-  errorcode = 0;
-  finished = false;
+}
+
+void turn_off(Channel *ci) {
+  Protocol *p = (protocols + ci->protocol);
+  if (p->i == 0) digitalWrite(ci->pin, LOW);
+  else digitalWrite(ci->pin, HIGH);
+}
+
+void turn_on(Channel *ci) {
+  Protocol *p = (protocols + ci->protocol);
+  if (p->i == 0) digitalWrite(ci->pin, HIGH);
+  else digitalWrite(ci->pin, LOW);
 }

 // Loop runs forever
 void loop() {
-  if (running > 0 && errorcode == 0) {
+  if (running > 0) {
     int now = micros();
     int delta = now - tick;
     tick = now;
@@ -163,7 +174,7 @@
         if (ci->t.s < 0) {
           if (ci->runlevel == 3) turn_off(ci);
           ci->runlevel = 0;
-          runlevel -= 1;
+          running -= 1;
           continue;   // CONTINUE WITH NEXT CHANNEL, THIS ONE IS DONE
         }
         else {
@@ -172,7 +183,7 @@
             bool flipped = false;
             bool on = (ci->runlevel > 1);
             while (ci->yn.s < 0) {
-              advance_from(&(ci->yn), on ? protocol[ci->protocol].n : protocol[ci->protocol].y);
+              advance_from(&(ci->yn), on ? protocols[ci->protocol].n : protocols[ci->protocol].y);
               flipped = !flipped;
               on = !on;
             }
@@ -192,21 +203,19 @@
         }
       }
     }
-    if (running == 0 || errorcode != 0) finished = true;
-  }
-
-
-  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
+  }
+
+
+  int r0 = ARM_DWT_CYCCNT;
+  digitalWrite(LED_PIN, HIGH);   // turn the LED on (HIGH is the voltage level)
   int m = micros();
   int n = 100000;
-  while (micros() - m < n) {};
-  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
+  while ((int)micros() - m < n) {};
+  digitalWrite(LED_PIN, LOW);    // turn the LED off by making the voltage LOW
   m = micros();
   n = 900000;
-  while (micros() - m < n) {};
+  while ((int)micros() - m < n) {};
   int r = ARM_DWT_CYCCNT;
   Serial.println(r - r0);
-  Serial.println(micros() - fix);
   Serial.send_now();
 }
-


Update rotaryEncoderNoSoftDebouncing.ino

--- RotaryEncoder/rotaryEncoderNoSoftDebouncing/rotaryEncoderNoSoftDebouncing.ino
+++ RotaryEncoder/rotaryEncoderNoSoftDebouncing/rotaryEncoderNoSoftDebouncing.ino
@@ -6,7 +6,7 @@
 const int PinDT=3;                    // Used for reading DT signal
 const int PinSW=8;                    // Used for the push button switch

-volatile long     virtualPosition  =0;  // without STATIC it does not count correctly!!!
+volatile long     virtualPosition  =0;  // must be volatile to work with the isr

 void isr0 ()  {
   detachInterrupt(0);


Delete Otto_ServoHome.ino

Delete Otto_ServoHome.ino


Added comments where to paste pattern and placed a dummy


Use writeStream() method instead of write()

write() now crashes on the second call?
writeStream() pulls in the whole stream, not allowing us to update the number of bytes read.

--- examples/ESP8266-OTA/ESP8266-OTA.ino
+++ examples/ESP8266-OTA/ESP8266-OTA.ino
@@ -50,7 +50,7 @@

   uint32_t total = 0;
   while (!Update.isFinished()) {
-    uint32_t written = Update.write(*pub.payload_stream());
+    uint32_t written = Update.writeStream(*pub.payload_stream());
     if (written > 0) {
       total += written;
       Serial.print(total, DEC);


changed SPI clock div to 64 in example

changed SPI clock div to 64 in example

--- firmware/examples/ble-mesh-cloud.ino
+++ firmware/examples/ble-mesh-cloud.ino
@@ -82,10 +82,9 @@
   pins.miso_pin   = A4;
   pins.sck_pin    = A3;

-  pins.spi_clock_divider      = SPI_CLOCK_DIV8; //SPI_CLOCK_DIV8  = 2MHz SPI speed
-                                                 //SPI_CLOCK_DIV16 = 1MHz SPI speed
-                                                 //if you are having trouble with the connection this might be the reason
-                                                 //you might want SPI_CLOCK_DIV64 = 256 KHz
+  pins.spi_clock_divider      = SPI_CLOCK_DIV64; //SPI_CLOCK_DIV8  = 8MHz SPI speed
+                                                 //SPI_CLOCK_DIV16 = 4MHz SPI speed
+                                                 //SPI_CLOCK_DIV64 = 1MHz SPI speed

   pins.reset_pin              = D2;
   pins.active_pin             = NRF_UNUSED;


modified led param

modified led param

--- arduino/opencr_arduino/opencr/libraries/turtlebot3/turtlebot3_burger/turtlebot3_core/turtlebot3_core.ino
+++ arduino/opencr_arduino/opencr/libraries/turtlebot3/turtlebot3_burger/turtlebot3_core/turtlebot3_core.ino
@@ -122,6 +122,7 @@
 #define LED_RXD         1
 #define LED_LOW_BATTERY 2
 #define LED_ROS_CONNECT 3
+#define LED_WORKING_CHECK 13

 /*******************************************************************************
 * Declaration for Battery
@@ -225,7 +226,7 @@

   prev_update_time = millis();

-  pinMode(13, OUTPUT);
+  pinMode(LED_WORKING_CHECK, OUTPUT);

   SerialBT2.begin(57600);

@@ -784,7 +785,7 @@
   if ((millis()-t_time) >= 500)
   {
     t_time = millis();
-    digitalWrite(13, !digitalRead(13));
+    digitalWrite(LED_WORKING_CHECK, !digitalRead(LED_WORKING_CHECK));
   }

   if (getPowerInVoltage() < 11.1)


Version 0.7

Version 0.7

Update because changes in main files.

--- examples/GPRS_LoopHandle/GPRS_LoopHandle.ino
+++ examples/GPRS_LoopHandle/GPRS_LoopHandle.ino
@@ -16,6 +16,8 @@
 #define PIN_TX    7
 #define PIN_RX    8
 #define BAUDRATE  9600
+
+#define MESSAGE_LENGTH 20

 char gprsBuffer[64];
 int i = 0;


delete examples

delete examples

--- examples/PIRMotionSensor/PIRMotionSensor.ino
+++ examples/PIRMotionSensor/PIRMotionSensor.ino
@@ -1,82 +0,0 @@
-/*
- * PIRMotionSensor.ino
- * Example sketch for the PIR motion sensor
- *
- * Copyright (c) 2013 seeed technology inc.
- * Website    : www.seeed.cc
- * Author     : FrankieChu
- * Create Time: Jan 21,2013
- * Change Log :
- *
- * The MIT License (MIT)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-
-/*****************************************************************************/
-//  Function: If the sensor detects the moving people in it's detecting range,
-//			  the Grove - LED is turned on.Otherwise, the LED is turned off.
-//  Hardware: Grove - PIR Motion Sensor, Grove - LED
-//	Arduino IDE: Arduino-1.0
-/*******************************************************************************/
-/*macro definitions of PIR motion sensor pin and LED pin*/
-#define PIR_MOTION_SENSOR 2//Use pin 2 to receive the signal from the module
-#define LED	4//the Grove - LED is connected to D4 of Arduino
-
-void setup()
-{
-	pinsInit();
-}
-
-void loop()
-{
-	if(isPeopleDetected())//if it detects the moving people?
-		turnOnLED();
-	else
-		turnOffLED();
-}
-void pinsInit()
-{
-	pinMode(PIR_MOTION_SENSOR, INPUT);
-	pinMode(LED,OUTPUT);
-}
-void turnOnLED()
-{
-	digitalWrite(LED,HIGH);
-}
-void turnOffLED()
-{
-	digitalWrite(LED,LOW);
-}
-/***************************************************************/
-/*Function: Detect whether anyone moves in it's detecting range*/
-/*Return:-boolean, ture is someone detected.*/
-boolean isPeopleDetected()
-{
-	int sensorValue = digitalRead(PIR_MOTION_SENSOR);
-	if(sensorValue == HIGH)//if the sensor value is HIGH?
-	{
-		return true;//yes,return ture
-	}
-	else
-	{
-		return false;//no,return false
-	}
-}


Fix temperature calculation.

Fix temperature calculation.

--- keg_scribe.ino
+++ keg_scribe.ino
@@ -192,7 +192,7 @@
   int reading = analogRead(sensorPin);

   // see explanation below
-  return ((((analogRead(sensorPin) * 5.0)/1024.0) * 100) * 9.0 / 5.0) + 32.0;
+  return (((((analogRead(sensorPin) * 5.0)/1024.0) - 0.5) * 100) * 9.0 / 5.0) + 32.0;

   /*
   // converting that reading to voltage, for 3.3v arduino use 3.3


Updated direction array, and random walker effects

--- ArduinoMotionStairLights.ino
+++ ArduinoMotionStairLights.ino
@@ -1,11 +1,206 @@
 /*
  * Description: Motion activated stair lights.
  * Author: Dean Montgomery
- * Version: 0.1 (Alpha)
+ * Version: 0.2 (Beta)
+ *
+ * 2 PIR sesors at the top and bottom of the stairs.
+ * WS28012B Addressable RGB lights - 2 LEDs on each stair - This spread out the strip of 30 and left 2-pairs for spare bulbs.
+ * My Arduino is at the top of the stairs and the RGB strip is connected at the top.
+ * This will cycle through several varitions of stair walkers.
+ *
 */

 #include "FastLED.h"
-/*
+
+#define NUM_LEDS 26
+#define LEDS_PER_STAIR 2        // Number of Leds per stair.  Not yet currenlty changable - just noteable
+#define BRIGHTNESS  120         // 0...255  ( used in fade7 )
+#define PIN_LED 3               // LED Data pin
+#define PIN_PIR_DOWN 5          // PIR Downstairs Pin
+#define PIN_PIR_UP 7            // PIR Upstairs Pin
+#define GO_UP -1                // Direction control - Arduino at top of stairs
+#define GO_DOWN 1               // Direction control - Arduino at top of stairs
+int8_t  lightsOn = LOW;         // track lights on/off
+uint8_t gHue = 0;               // track color shifts.
+int8_t  gStair = 0;             // track curent stair.
+uint8_t gBright = 0;            // track brightness
+uint8_t gUpDown[NUM_LEDS];      // directional array to walk/loop up or down stairs.
+CRGB    leds[NUM_LEDS];         // setup leds object to access the string
+CRGBPalette16 gPalette;         // some favorite and random colors for display.
+int8_t  gLastPalette = 15;      // track last chosen palette.
+uint8_t gLastWalk = 1;
+
+void setup() {
+  delay (3000); // Power Up 3 second safety delay.
+  //Serial.begin(9600);
+  FastLED.addLeds<WS2812B, PIN_LED, GRB>(leds, NUM_LEDS);  // NOTE set LED string type here.
+  pinMode(PIN_PIR_DOWN, INPUT);
+  pinMode(PIN_PIR_UP, INPUT);
+  digitalWrite(PIN_PIR_DOWN, LOW);
+  digitalWrite(PIN_PIR_UP, LOW);
+  welcomeRainbow();             // rainbow - give time for PIR sensors to colibrate.
+  setUpDown(GO_DOWN);           // populate the array index used for stair direction.
+  setPalette();                 // setup some favorite & random colors
+}
+
+// Main Loop track PIR sensors.
+void loop() {
+  // Walk Down.
+  if ( digitalRead(PIN_PIR_UP) == HIGH ){
+    if ( lightsOn == LOW ) {
+      lightsOn = HIGH;
+      setUpDown(GO_DOWN);
+      walker();
+      delay(50);
+    }
+  }
+  // Walk Up.
+  if ( digitalRead(PIN_PIR_DOWN) == HIGH  ){
+    if ( lightsOn == LOW ) {
+      lightsOn = HIGH;
+      setUpDown(GO_UP);
+      walker();
+      delay(50);
+    }
+  }
+}
+
+// Cycle through stair walkers.
+void walker(){
+  switch (gLastWalk % 3) {
+    case 0:
+      fade7();
+      break;
+    case 1:
+      flicker();
+      break;
+    default:
+      walk();
+  }
+  if (gLastWalk >= 50){
+    gLastWalk = 0;
+  }else{
+    gLastWalk++;
+  }
+}
+
+void setUpDown(int8_t upDownDir){
+  // setup walking gUpDown array in forward: 0,1,2,3... or reverse:  ...3,2,1,0
+  uint8_t gStairStart = 0;
+  if (upDownDir == GO_UP){
+    for ( gStair = NUM_LEDS -1; gStair >= 0; gStair-- ){
+      gUpDown[gStair] = gStairStart++;
+    }
+  } else {
+    for ( gStair = 0; gStair <= NUM_LEDS; gStair++ ){
+      gUpDown[gStair] = gStairStart++;
+    }
+  }
+}
+
+void welcomeRainbow(){
+  // Sparkle rainbow welcome give delay to calibrate pir sensors.  This also indicates if program crashed.
+  for ( int i = 0; i < 500; i++ ){
+    rainbowWithGlitter();
+    FastLED.show();
+    FastLED.delay(8.3);
+    EVERY_N_MILLISECONDS( 20 ) { gHue++; }
+  }
+  for (int tick=0; tick < 64; tick++){
+    for ( uint8_t i = 0; i < NUM_LEDS; i++ ){
+      leds[i].fadeToBlackBy( 64 );
+      FastLED.show();
+      FastLED.delay(1);
+    }
+  }
+}
+
+void walkold() {
+  static uint8_t hueStart = 208; //purple;
+  static uint8_t hueEnd = 160;
+  static uint8_t hueShift = 0;
+  static uint8_t brightTop = 200;
+  static int i = 0;
+
+  for(gStair=0; gStair < NUM_LEDS; gStair+=2) {
+    // Fade in step
+    hueShift = hueStart;
+    for (gBright=0; gBright<=brightTop; gBright+=2) {
+      leds[gUpDown[gStair]] = CHSV( hueStart, 204, gBright );  // purple
+      leds[gUpDown[gStair + 1]] = CHSV( hueStart, 204, gBright );  // purple
+      if (  gStair >= 2 ) { // slide hue from pruple to blue on previous stair
+        //hueShift = hueShift + ((hueEnd-hueStart)/brightTop*gBright); //=D1+((160-240)/200*10)
+        if ( hueShift >= hueEnd ) {
+          hueShift--;
+          leds[gUpDown[gStair - 1]] = CHSV( hueShift, 204, 200 );
+          leds[gUpDown[gStair - 2]] = CHSV( hueShift, 204, 200 );
+        }
+      }
+      FastLED.show();
+      //FastLED.delay(1);
+    }
+  }
+
+  // Hue shift the last two stairs
+  hueShift = hueStart;
+  for (gBright=0; gBright<=brightTop; gBright+=2) {
+    if ( hueShift >= hueEnd )
+    //hueShift = 1/(hueShift + ((hueEnd-hueStart)/brightTop*bright));
+    hueShift--;
+    leds[gUpDown[NUM_LEDS - 1]] = CHSV( hueShift, 204, 200 );
+    leds[gUpDown[NUM_LEDS - 2]] = CHSV( hueShift, 204, 200 );
+    FastLED.show();
+    //FastLED.delay(1);
+  }
+  //Flash
+  FastLED.delay(500);
+  for(gStair=0; gStair < NUM_LEDS; gStair+=2) {
+    leds[gUpDown[gStair]] = CRGB( 100, 100, 100);
+    leds[gUpDown[gStair + 1]] = CRGB( 100, 100, 100);
+    FastLED.show();
+  }
+  for(gStair=0; gStair < NUM_LEDS; gStair+=2) {
+    leds[gUpDown[gStair]] = CHSV( hueEnd, 204, 200 );
+    leds[gUpDown[gStair+1]] = CHSV( hueEnd, 204, 200 );
+    FastLED.show();
+  }
+
+
+  // Stay on for a bit
+  fill_solid(leds, NUM_LEDS, CHSV( hueEnd, 204, 200 ));
+  //addGlitter(70);
+  FastLED.show();
+  FastLED.delay(5000);
+
+  // Turn off steps
+  for(gStair=0; gStair < NUM_LEDS; gStair+=2) {
+    // Fade in step
+    //hueShift = hueStart;
+    for (gBright=200; gBright>=1; gBright--) {
+      leds[gUpDown[gStair]] = CHSV(hueEnd, 204, gBright);
+      leds[gUpDown[gStair + 1]] = CHSV(hueEnd, 204, gBright);
+      FastLED.show();
+      FastLED.delay(1);
+    }
+    leds[gUpDown[gStair]].setHSV( 0, 0, 0);
+    leds[gUpDown[gStair + 1]].setHSV( 0, 0, 0);
+    FastLED.show();
+  }
+  lightsOn = LOW;
+}
+
+// Increment to the next color pair in the palette.
+void choosePalette(){
+  if ( gLastPalette >= 15 ) {
+    gLastPalette = 0;
+  } else {
+    gLastPalette+=2;
+  }
+}
+
+// Fill a palette with some colors that my wife picked.
+void setPalette(){
+  /*
  * Jenn's colors RGB  0 0 81  BLUE
  * 0 100 100 Teal 006464
  * 60 100 100 Cool White 3C6464
@@ -16,195 +211,144 @@
  * teal to blue
  * red to blue
  */
-#define NUM_LEDS 26
-#define LEDS_PER_STAIR 2        // Number of Leds per stair.
-#define BRIGHTNESS  120         // 0...255  ( needed ?)
-#define UPDATES_PER_SECOND 100
-#define PIN_LED 3               // LED Data pin
-#define PIN_PIR_DOWN 5          // PIR Downstairs Pin
-#define PIN_PIR_UP 7            // PIR Upstairs Pin
-#define STEP_DELAY 200          //ms = 1/5th second. ( needed ?)
-#define GO_UP -1                // Direction control - Arduino at top of stairs
-#define GO_DOWN 1               // Direction control - Arduino at top of stairs
-int8_t lightsOn = LOW;          // track lights on/off
-uint8_t gHue = 0;
-int8_t gStair = 0;
-uint8_t gBright = 0;
-int8_t gStairStart = 0;
-int8_t gStairEnd = 0;
-uint8_t gUpDown[NUM_LEDS];      // directional array to walk/loop up or down stairs.
-
-CRGB leds[NUM_LEDS];
-
-
-
-
-void setup() {
-  delay (3000); // Power Up 3 second safety delay.
-  Serial.begin(9600);
-  FastLED.addLeds<WS2812B, PIN_LED, GRB>(leds, NUM_LEDS);
-  //FastLED.setBrightness(BRIGHTNESS);
-  //Serial.print("calibrating sensor ");
-  pinMode(PIN_PIR_DOWN, INPUT);
-  pinMode(PIN_PIR_UP, INPUT);
-  digitalWrite(PIN_PIR_DOWN, LOW);
-  digitalWrite(PIN_PIR_UP, LOW);
-  Serial.println(" done");
-  welcomeRainbow();  // rainbow - give time for PIR sensors.
-  setUpDown(GO_DOWN);
-  Serial.println("SENSOR ACTIVE");
-}
-
-// Main Loop track PIR sensors.
-void loop() {
-  // Walk Down.
-  if ( digitalRead(PIN_PIR_UP) == HIGH ){
-    if ( lightsOn == LOW ) {
-      lightsOn = HIGH;
-      setUpDown(GO_DOWN);
-      // TODO: Add random pattern picker.
-      fade7();
-      //walk(1);
-      //flicker(1);
-      delay(50);
-    }
-  }
-  // Walk Up.
-  if ( digitalRead(PIN_PIR_DOWN) == HIGH  ){
-    if ( lightsOn == LOW ) {
-      lightsOn = HIGH;
-      setUpDown(GO_UP);
-      fade7(); //Up
-      //walk(-1); // Up
-      //flicker(-1);
-      delay(50);
-    }
-  }
-}
-
-void setUpDown(int8_t upDownDir){
-  // setup walking gUpDown array in forward: 0,1,2,3... or reverse:  ...3,2,1,0
-  gStairStart = 0;
-  if (upDownDir == GO_UP){
-    for ( gStair = NUM_LEDS -1; gStair >= 0; gStair-- ){
-      gUpDown[gStair] = gStairStart++;
-    }
-  } else {
-    for ( gStair = 0; gStair <= NUM_LEDS; gStair++ ){
-      gUpDown[gStair] = gStairStart++;
-    }
-  }
-  //printUpDown();
-}
-
-void printUpDown(){
-  for (gStair = 0; gStair < NUM_LEDS; gStair++){
-    Serial.print (gStair);
-    Serial.print (" " );
-    Serial.println (gUpDown[gStair]);
-  }
-}
-
-void welcomeRainbow(){
-  // Sparkle rainbow welcome give delay to calibrate pir sensors.  This also indicates if program crashed.
-  for ( int i = 0; i < 500; i++ ){
-    rainbowWithGlitter();
-    FastLED.show();
-    FastLED.delay(8.3);
-    EVERY_N_MILLISECONDS( 20 ) { gHue++; }
-  }
-  for (int tick=0; tick < 64; tick++){
-    for ( uint8_t i = 0; i < NUM_LEDS; i++ ){
-      leds[i].fadeToBlackBy( 64 );
-      FastLED.show();
-      FastLED.delay(1);
-    }
-  }
-}
-
-
-
-void walk(int8_t dir) {
-  Serial.print("Walk dir: ");
-  Serial.println(dir);
-  static uint8_t hueStart = 208; //purple;
-  static uint8_t hueEnd = 160;
-  static uint8_t hueShift = 0;
-  static uint8_t brightTop = 200;
+  fill_solid( gPalette, 16, CRGB::Red);
+  gPalette[0] = CRGB( 60, 100, 100 ); // Jenn cool white
+  gPalette[1] = CRGB( 0, 90, 90 );    // Jenn teal
+  gPalette[2] = CRGB( 60, 10, 100 );  // Jenn violet
+  gPalette[3] = CRGB( 60, 0, 50 );    // Jenn purple
+  gPalette[4] = CRGB( 0, 0, 81);      // Jenn blue
+  gPalette[5] = CRGB( 100, 0, 0);     // Red
+  gPalette[6] = CRGB( 0, 0, 100);     // Blue
+  gPalette[7] = CRGB( 120, 0, 120);
+  // Random fill the rest.
+  for (uint8_t i = 8; i<16; i++){
+    gPalette[i] = CRGB(random8(3,100), random8(3,100), random8(3,100));
+  }
+}
+
+// Walk the stairs adding random effects.
+void walk() {
+  static uint8_t valTop = 200;
   static int i = 0;
-  setStartEnd(dir);
-
-  for(gStair=gStairStart; (dir == 1 && gStair < gStairEnd ) || (dir == -1 && gStair >= gStairEnd && gStair <= gStairStart+1 ); gStair+=(2*dir)) {
+  // Pick two colors from the palette.
+  choosePalette();
+  CRGB c1 = gPalette[gLastPalette];
+  CRGB c2 = gPalette[gLastPalette+1];
+  if ( random8( 5 ) == 3 ){
+    c1 = CRGB(random8(100),random8(100),random8(100));
+    c2 = CRGB(random8(100),random8(100),random8(100));
+  }
+  CRGB trans = CRGB::Black;
+  CRGB trans2 = CRGB::Black;
+  //(r2-r1)/ticks * tick)
+
+  for(gStair=0; gStair < NUM_LEDS; gStair+=2) {
     // Fade in step
-    hueShift = hueStart;
-    for (gBright=0; gBright<=brightTop; gBright+=2) {
-      leds[gStair] = CHSV( hueStart, 204, gBright );  // purple
-      leds[gStair + 1*dir] = CHSV( hueStart, 204, gBright );  // purple
-      if (  (dir == 1 && gStair >= 2) || (dir == -1 && gStair <= (gStairStart-2)) ) { // slide hue from pruple to blue on previous stair
-        //hueShift = hueShift + ((hueEnd-hueStart)/brightTop*gBright); //=D1+((160-240)/200*10)
-        if ( hueShift >= hueEnd ) {
-          hueShift--;
-          leds[gStair - 1*dir] = CHSV( hueShift, 204, 200 );
-          leds[gStair - 2*dir] = CHSV( hueShift, 204, 200 );
+    for (gBright=0; gBright<=valTop; gBright+=2) {
+      // Fade in from off
+      trans.r = 0 + int16_t((c1.r*gBright)/valTop);
+      trans.g = 0 + int16_t((c1.g*gBright)/valTop);
+      trans.b = 0 + int16_t((c1.b*gBright)/valTop);
+      leds[gUpDown[gStair]] = trans;
+      leds[gUpDown[gStair + 1]] = trans;
+      if (  gStair >= 2 ) { // shift last to stairs to the 2nd color.
+        trans2.r = c1.r + int16_t(((c2.r - c1.r)*gBright)/valTop);
+        trans2.g = c1.g + int16_t(((c2.g - c1.g)*gBright)/valTop);
+        trans2.b = c1.b + int16_t(((c2.b - c1.b)*gBright)/valTop);
+        leds[gUpDown[gStair - 1]] = trans2;
+        leds[gUpDown[gStair - 2]] = trans2;
+      }
+      FastLED.show();
+      FastLED.delay(1);
+    }
+  }
+
+  // Hue shift the last two stairs
+  for (gBright=0; gBright<=valTop; gBright+=2) {
+    trans2.r = c1.r + int16_t(((c2.r - c1.r)*gBright)/valTop);
+    trans2.g = c1.g + int16_t(((c2.g - c1.g)*gBright)/valTop);
+    trans2.b = c1.b + int16_t(((c2.b - c1.b)*gBright)/valTop);
+    leds[gUpDown[NUM_LEDS - 1]] = trans2;
+    leds[gUpDown[NUM_LEDS - 2]] = trans2;
+    FastLED.show();
+    FastLED.delay(1);
+  }
+
+  // Delay + random effects
+  randomEffect(c1, c2);
+
+  // Turn off steps
+  for(gStair=0; gStair < NUM_LEDS; gStair+=2) {
+    for (gBright=0; gBright<=valTop; gBright++) {
+      leds[gUpDown[gStair]].fadeToBlackBy( valTop );
+      leds[gUpDown[gStair + 1]].fadeToBlackBy( valTop );
+      FastLED.show();
+    }
+    leds[gUpDown[gStair]] = CRGB( 0, 0, 0);
+    leds[gUpDown[gStair + 1]] = CRGB( 0, 0, 0);
+    FastLED.show();
+  }
+  lightsOn = LOW;
+}
+
+// Random effects for the walk() stair function.
+void randomEffect(CRGB c1, CRGB c2){
+  uint8_t var = random8( 1, 5 );
+  int i = 0, x = 0;
+  CRGB trans2 = CRGB::Black;
+  FastLED.delay(500); // Wait for it...
+  switch (var) {
+    case 1:
+      //sparkle
+      {
+        for ( i=0; i<=500; i++){
+          fill_solid(leds, NUM_LEDS, c2);
+          addGlitter(80);
+          FastLED.show();
+          FastLED.delay(8.5);
+        }
+        fill_solid(leds, NUM_LEDS, c2);
+        FastLED.show();
+      }
+      break;
+    case 2:
+      //pulsate between colors
+      {
+        CRGBPalette16 z;
+        z[0] = c2;
+        z[1] = c1;
+        z[2] = CRGB(random8(1,100),random8(1,100),random8(1,100));
+        z[3] = c1;
+        uint8_t ticks = 200;
+        for (i=0; i<4; i++){
+          for (x = 0; x<ticks; x++){
+            trans2.r = z[i].r + int16_t(((z[i+1].r - z[i].r)*x)/ticks);
+            trans2.g = z[i].g + int16_t(((z[i+1].g - z[i].g)*x)/ticks);
+            trans2.b = z[i].b + int16_t(((z[i+1].b - z[i].b)*x)/ticks);
+            fill_solid(leds, NUM_LEDS, trans2);
+            FastLED.show();
+            FastLED.delay(10);
+          }
         }
       }
-      FastLED.show();
-      //FastLED.delay(1);
-    }
-    Serial.print(gStair);
-    Serial.println(" step");
-  }
-
-  Serial.println("Last Stairs");
-  hueShift = hueStart;
-  for (gBright=0; gBright<=brightTop; gBright+=2) {
-    if ( hueShift >= hueEnd )
-    //hueShift = 1/(hueShift + ((hueEnd-hueStart)/brightTop*bright));
-    hueShift--;
-    leds[gStairEnd] = CHSV( hueShift, 204, 200 );
-    leds[gStairEnd - 1*dir] = CHSV( hueShift, 204, 200 );
-    FastLED.show();
-    //FastLED.delay(1);
-  }
-  //Flash
-  FastLED.delay(500);
-  for(gStair=gStairStart; (dir == 1 && gStair <= gStairEnd ) || (dir == -1 && gStair >= gStairEnd && gStair <= gStairStart+1 ); gStair+=(2*dir)) {
-    leds[gStair] = CRGB( 100, 100, 100);
-    leds[gStair + 1*dir] = CRGB( 100, 100, 100);
-    FastLED.show();
-  }
-  for(gStair=gStairStart; (dir == 1 && gStair <= gStairEnd ) || (dir == -1 && gStair >= gStairEnd && gStair <= gStairStart+1 ); gStair+=(2*dir)) {
-    leds[gStair] = CHSV( hueEnd, 204, 200 );
-    leds[gStair+1*dir] = CHSV( hueEnd, 204, 200 );
-    FastLED.show();
-  }
-
-
-  Serial.println("Delay");
-  // Stay on for a bit
-  fill_solid(leds, NUM_LEDS, CHSV( hueEnd, 204, 200 ));
-  //addGlitter(70);
-  FastLED.show();
-  FastLED.delay(5000);
-
-  // Turn off steps
-  Serial.println("Steps Off");
-  for(gStair=gStairStart; (dir == 1 && gStair <= gStairEnd ) || (dir == -1 && gStair >= gStairEnd && gStair <= gStairStart+1 ); gStair+=(2*dir)) {
-    // Fade in step
-    //hueShift = hueStart;
-    for (gBright=200; gBright>=1; gBright--) {
-      leds[gStair] = CHSV(hueEnd, 204, gBright);
-      leds[gStair + 1*dir] = CHSV(hueEnd, 204, gBright);
-      FastLED.show();
-      FastLED.delay(1);
-    }
-    leds[gStair].setHSV( 0, 0, 0);
-    leds[gStair + 1*dir].setHSV( 0, 0, 0);
-    FastLED.show();
-  }
-  lightsOn = LOW;
-
-  Serial.println("Done");
+      break;
+    default:
+      //Flash then solid
+      {
+        for(gStair=0; gStair < NUM_LEDS; gStair+=2) {
+          leds[gUpDown[gStair]] = CRGB( 100, 100, 100);
+          leds[gUpDown[gStair + 1]] = CRGB( 100, 100, 100);
+          FastLED.show();
+        }
+        for(gStair=0; gStair < NUM_LEDS; gStair+=2) {
+          leds[gUpDown[gStair]] = c2;
+          leds[gUpDown[gStair+1]] = c2;
+          FastLED.show();
+        }
+        FastLED.show();
+        FastLED.delay(5000);
+      }
+  }
 }

 // startup rainbow
@@ -219,7 +363,6 @@
   rainbow();
   addGlitter(80);
 }
-
 void addGlitter( fract8 chanceOfGlitter)
 {
   if( random8() < chanceOfGlitter) {
@@ -227,28 +370,27 @@
   }
 }

-// Candle flicker.
-void flicker(int8_t dir){
-  setStartEnd(dir);
+// Candle flicker, blown out, + ember glow
+void flicker(){
   static uint16_t i = 0;
   static uint8_t rnd = 0;
-  uint8_t stair = 0;
+  uint8_t r = 0, g = 0, b = 0;
+  int8_t stair = 0;
   gBright = 0;
-  for(gStair=gStairStart; (dir == 1 && gStair < gStairEnd ) || (dir == -1 && gStair >= gStairEnd && gStair <= gStairStart+1 ); gStair+=(2*dir)) {
+  for(gStair=0; gStair < NUM_LEDS; gStair+=2) {
     for( i = 0; i <= 18; i++ ) {
-      for (stair = gStairStart; (dir == 1 && stair <= gStair ) || ( dir == -1 && stair >= gStair && stair <= gStairStart+1); stair+=(2*dir)) {
+      for (stair = 0; stair <= gStair; stair+=2) {
         rnd = random8(1, 4);
         if ( rnd == 2 ){
           gBright = random8(90,140);
-          leds[stair] = CHSV( 60, 200, gBright );
-          leds[stair + 1*dir] = CHSV( 60, 200, gBright );
+          leds[gUpDown[stair]] = CHSV( 60, 200, gBright );
+          leds[gUpDown[stair + 1]] = CHSV( 60, 200, gBright );
         }
         FastLED.show();
       }
     }
   }
   // Wait
-  Serial.println("Wait");
   for ( i=0; i<=300; i++) {
     for( gStair = 0; gStair < NUM_LEDS; gStair+=2) {
       rnd = random8(1, 4);
@@ -261,36 +403,30 @@
     FastLED.show();
     FastLED.delay(25);
   }
-  Serial.println("Shutdown");
-  // Shutdown
-  for(gStair=gStairStart; (dir == 1 && gStair <= gStairEnd ) || (dir == -1 && gStair >= gStairEnd && gStair <= gStairStart+1 ); gStair+=(2*dir)) {
-    for( i = 0; i <= 18; i++) {
-      for (stair = gStair; (dir == 1 && stair <= gStairEnd ) || ( dir == -1 && stair >= gStair && stair <= gStairStart+1); stair+=(2*dir)) {
-        rnd = random8(1, 4);
-        if ( rnd == 2 ){
-          gBright = random8(90,140);
-          leds[stair] = CHSV( 60, 200, gBright );
-          leds[stair + 1*dir] = CHSV( 60, 200, gBright );
-          leds[gStair] = CRGB( 0,0,0 );
-          leds[gStair + 1*dir] = CRGB( 0,0,0 );
-        }
-        FastLED.show();
-      }
-    }
-    leds[gStair] = CRGB( 0,0,0 );
-    leds[gStair + 1*dir] = CRGB( 0,0,0 );
-    FastLED.show();
-    FastLED.delay(25);
-  }
+  // Blow out candles and leave an ember.
+  for(gStair=0; gStair < NUM_LEDS; gStair+=2) {
+    rnd = random8(4, 6);
+    r = rnd+1;
+    g = rnd-2;
+    leds[gUpDown[gStair]] = CRGB( r,g,0 );
+    leds[gUpDown[gStair + 1]] = CRGB( r,g,0 );
+    FastLED.show();
+    FastLED.delay(50);
+  }
+  for ( i=0; i<=200; i++) {
+    rnd = random8(0, NUM_LEDS-1);
+    leds[gUpDown[rnd]].fadeToBlackBy( 5 );
+    FastLED.show();
+    FastLED.delay(50);
+  }
+  fill_solid(leds, NUM_LEDS, CRGB( 0, 0, 0 ));
+  FastLED.show();
   lightsOn = LOW;
 }

-// Fade7 effect.
+// Fade7 effect with each led: r,rb,b,bg,g,gr rgb(white)
 void fade7(){
-  //setStartEnd(dir);
-  Serial.println("Fade7");
-  //Serial.println(dir);
   const uint8_t mx = BRIGHTNESS;
   uint8_t r = mx;
   uint8_t g = 0;
@@ -363,12 +499,4 @@
   lightsOn = LOW;
 }

-void setStartEnd(int8_t dir){
-  if (dir == 1){ //Down
-    gStairStart = 0;
-    gStairEnd = NUM_LEDS-1;
-  } else {
-    gStairStart = NUM_LEDS-1;
-    gStairEnd = 0;
-  }
-}
+


Add safe-guard flag for lcd

Add safe-guard flag for lcd

--- src/IoTBox.ino
+++ src/IoTBox.ino
@@ -56,6 +56,7 @@
 volatile bool requestDisplayTime = false;
 volatile bool requestDisplayConfigurationTime = true;
 volatile bool requestOpeningOperation = false;
+volatile bool isLCDBusy = false;

 Timer clockTimer(1000, updateTime); // timer used to display the clock on the lcd display

@@ -116,11 +117,6 @@

 void loop() {
     if (requestOpeningOperation) {
-        lcd.setCursor(0,1);
-        lcd.print("               ");
-        lcd.setCursor(0,1);
-        lcd.print("will open....");
-
         digitalWrite(LEDPIN, HIGH);
         openOperation.start();

@@ -134,19 +130,22 @@

 void displayStatus() {
     if (requestDisplayStatus) {
-        if (switchState == HIGH) {
-            lcd.setCursor(0,1);
-            lcd.print("               ");
-            lcd.setCursor(0,1);
-            lcd.print("LOCKED");
-        } else {
-            lcd.setCursor(0,1);
-            lcd.print("               ");
-            lcd.setCursor(0,1);
-            lcd.print("OPEN");
-        }
-
-        requestDisplayStatus = false;
+        if (!isLCDBusy) {
+            isLCDBusy = true;
+            if (switchState == HIGH) {
+                lcd.setCursor(0,1);
+                lcd.print("               ");
+                lcd.setCursor(0,1);
+                lcd.print("LOCKED");
+            } else {
+                lcd.setCursor(0,1);
+                lcd.print("               ");
+                lcd.setCursor(0,1);
+                lcd.print("OPEN");
+            }
+            isLCDBusy = false;
+            requestDisplayStatus = false;
+        }
     }
 }

@@ -164,29 +163,37 @@
 void displayTime() {
     if (!requestDisplayConfigurationTime) {
         if (requestDisplayTime) {
-            lcd.setCursor(0,0);
-            lcd.print("          ");
-            lcd.setCursor(0,0);
-            // Format from C library: https://www.gnu.org/software/libc/manual/html_node/Low_002dLevel-Time-String-Parsing.html
-            lcd.print(Time.format(Time.now(), "%T"));
-
-            requestDisplayTime = false;
+            if (!isLCDBusy) {
+                isLCDBusy = true;
+                lcd.setCursor(0,0);
+                lcd.print("          ");
+                lcd.setCursor(0,0);
+                // Format from C library: https://www.gnu.org/software/libc/manual/html_node/Low_002dLevel-Time-String-Parsing.html
+                lcd.print(Time.format(Time.now(), "%T"));
+                isLCDBusy = false;
+
+                requestDisplayTime = false;
+            }
         }
     }
 }

 void displayConfigurationTime() {
     if (requestDisplayConfigurationTime) {
-        lcd.setCursor(11,0);
-        lcd.print(configurationTime.hour);
-
-        lcd.setCursor(13,0);
-        lcd.print(":");
-
-        lcd.setCursor(14,0);
-        lcd.print(configurationTime.minute);
-
-        requestDisplayConfigurationTime = false;
+        if (!isLCDBusy) {
+            isLCDBusy = true;
+            lcd.setCursor(11,0);
+            lcd.print(configurationTime.hour);
+
+            lcd.setCursor(13,0);
+            lcd.print(":");
+
+            lcd.setCursor(14,0);
+            lcd.print(configurationTime.minute);
+            isLCDBusy = false;
+
+            requestDisplayConfigurationTime = false;
+        }
     }
 }


fix continue in the loop

fix continue in the loop

--- arduino_motor/mains/movements.ino
+++ arduino_motor/mains/movements.ino
@@ -36,9 +36,11 @@
       rightTicks /= (timez/1000.0); // ms

       InputMid = deltaY / DISTANCE_PER_TICK_CM;
-      if(leftTicks<0 || rightTicks<0) continue;
-      InputLeft = leftTicks;
-      InputRight = rightTicks;
+      if(leftTicks>0 && rightTicks>0) {
+        InputLeft = leftTicks;
+        InputRight = rightTicks;
+      }
+

       midPID.Compute();
       const double COEFFICIENT = 0.125;