Delete Ball-Board.ino

Delete Ball-Board.ino

--- Firmware/Ball/Ball-Board/Ball-Board.ino
+++ Firmware/Ball/Ball-Board/Ball-Board.ino
@@ -1,830 +0,0 @@
-String version = "0.2.1";
-/*
-  - OPEN BB-X -
- A open source BB-8 for create you own BB-8!
- ###########################################
-
- https://github.com/Gruniek/OPEN-BB-X
- Made by Daniel M/Gruniek/
-
- Compatible only with an Arduino MEGA 2560 and the specific PCB.
- PCB Link : https://github.com/Gruniek/OPEN-BB-X/tree/master/Head/Stabiliser/PCB
-
- --------------
- - Change log -
- --------------
-
- 11/2016
- =========
- - Conversion for a Arduino Mega 2560 Board
- - ADD motor A and B
- - FIX alls bug for stabilisation
- - ADD BOOT, STAT, ROTATE command
- - ADD Z motor configuration and production
- - ADD BOOT mode, for initilize or reinizialize the Droid position
-
- 10/2016
- ==========
- - Add PID for X and Y
-
-
- To do list
- ==========
- - Add Z rotation controller
- - Add Rx/Tx from the motherboard for change de coordinate of the head,
-  rotate the head and report to the remote the status off all sensors/positiom.
-
-
-  Big thanks for http://r2builders.fr/ !
-  Initial project : http://r2builders.fr/forum/viewtopic.php?f=26&t=3928&hilit=BB8+par+MOUS
-
-  ===============
-  EXEMPLE COMMAND
-  ===============
-  < SET >
-  'SET x87 y75 h3 \n'        // SET a new setpoint for x and y with 3degree of Hysteressis
-  'SET x90 y90 i1 j0 k1 \n'  // SET an inversion of the sensor X Y and invert the direction of X
-
-  	x = SETPOINT for X
-	y = SETPOINT for Y
-	m = MULTIPLIER FOR THE SPEED OF THE MOTOR X and Y
-	i = INVERT the angle sensor ( X = Y and Y = X )
-	j = INVERT the direction of X
-	k = INVERT the direction of Y
-	h = SET a new HYSTERESSIS
-
-  < BOOT >
-  'BOOT \n'  // LAUNCH TEST for X, Y and Z -> Return X and Y to initial SETPOINT (x90 y90 ) and Z to ZERO
-
-  < RUN >
-  'RUN \n'   // RUN the code in production mode (Recieved all data, X and Y runing for the SETPOINT poistion and Z folow the remote controll
-
-  < STOP >
-  'STOP \n'  // STOP the production mode. All motors are stopped.
-
-  < ROTATE >
-  'ROTATE d1 s100 \n'   // ROTATE Z motor on the RIGHT DIRECTION (d0 LEFT, d1 RIGHT) WITH the SPEED at 1000/100 = 10 step/sec = 18dec/sec
-
-  < STAT >
-  // It is all data SENDED to the remote
-
-  < ENABLE >
-  'ENABLE a1 x1 z1 \n'    // ENABLE MOTOR AB, XY and Z (a = AB, x=XY, z = Z | 0 = desabled | 1 = enabled )
-
-*/
-
-#include "Wire.h"
-#include "MPU6050.h"
-#include <SPI.h>
-#include <nRF24L01.h>
-#include <RF24.h>
-
-
-// RF24
-RF24 radio(54, 55);
-
-// MPU6050
-MPU6050 accelgyro;
-
-int16_t ax, ay, az;
-int16_t gx, gy, gz;
-
-// MOTOR CONFIGURATION // YOU CAN TOUCH THIS
-
-bool    invertA        = false; // INVERT THE A MOTOR DIRECTION
-bool    invertB        = false; // INVERT THE B MOTOR DIRECTION
-bool    invertX        = false; // INVERT THE X MOTOR DIRECTION
-bool    invertY        = true;  // INVERT THE Y MOTOR DIRECTION
-bool    invertXY       = false; // INVERT X Y AXIAL
-
-int     minX           = 45;    // SET THE MIN INCLINAISON FOR X
-int     maxX           = 135;   // SET THE MAX INCLINAISON FOR X
-int     minY           = 45;    // SET THE MIN INCLINAISON FOR Y
-int     maxY           = 135;   // SET THE MAX INCLINAISON FOR Y
-
-int     etalonX        = 0;     // AJUSTEMENT FOR X
-int     etalonY        = -6;    // AJUSTEMENT FOR Y
-
-int     hysteresis     = 1;     // HYSTERESSIS FOR THE ANGLE CALCULATION
-
-//
-//=====================//
-// NOW YOU CAN'T TOUCH //
-//=====================//
-
-//PINOUT
-
-#define pinEnableXY      2      // Activation off all stepper
-#define pinEnableAB      3
-#define pinEnableZ       4
-
-#define pinStepA         5      // PIN STEP FOR X
-#define pinDirA          6      // PIN DIRECTION FOR X
-
-#define pinStepB         7      // PIN STEP FOR X
-#define pinDirB          8      // PIN DIRECTION FOR X
-
-#define pinStepX         9      // PIN STEP FOR X
-#define pinDirX          10      // PIN DIRECTION FOR X
-
-#define pinStepY         11      // PIN STEP FOR Y
-#define pinDirY          12      // PIN DIRECTION FOR Y
-
-#define pinStepZ         14      // PIN STEP FOR Y
-#define pinDirZ          15      // PIN DIRECTION FOR Y
-
-#define Z_POSITION       16      // PIN FOR THE DIGITAL INPUT FOR THE HEAD POSITION
-
-#define PING             13
-
-#define CurrentBat1      0
-#define CurrentBat2      1
-#define CurrentBat3      2
-#define CurrentBat4      3
-#define Pinvoltage       6
-
-// I2C
-int adress         = 2;
-
-// MOTOR VARIABLE
-int speedA         = 0;
-int speedB         = 0;
-bool runA          = false;
-bool runB          = false;
-bool dirA          = true;   // true = Front | false = back
-bool dirB          = true;   // true = Front | false = back
-
-int x              = 0;
-int y              = 0;
-int vx             = 0;
-int vy             = 0;
-
-int speedX         = 0;
-int speedY         = 0;
-int speedZ         = 0;
-int setpointX      = 90;
-int setpointY      = 90;
-
-int Zangle         = 0;
-bool newData       = false;
-
-int multiplier     = 15;
-int emergencyStop  = 11; // PIN
-int eStop          = 12; // PIN
-bool emgStop       = false;
-
-bool runX          = false;
-bool runY          = false;
-bool runZ          = false;
-bool directX       = false; // false = Gauche / true = droite
-bool directY       = false; // false = Gauche / true = droite
-bool directZ       = false; // false = Gauche / true = droite
-
-bool xok           = false;
-bool yok           = false;
-bool zok           = false;
-
-long intX          = 0;
-long intY          = 0;
-
-bool production    = false;
-bool LED_PING      = false;
-bool BOOT          = false;
-
-bool enMotAB       = false;
-bool enMotXY       = false;
-bool enMotZ        = false;
-
-unsigned long previousMillisX = 0;
-unsigned long previousMillisY = 0;
-unsigned long previousMillisZ = 0;
-unsigned long previousMillisA = 0;
-unsigned long previousMillisB = 0;
-unsigned long currentA = 0;
-unsigned long currentB = 0;
-
-unsigned long trigGyro = 100;
-unsigned long trigSec  = 1000;
-unsigned long trigG    = 0;
-unsigned long trigS    = 0;
-
-
-//=============================================================================//
-//   SETUP
-//=============================================================================//
-void setup()
-{
-    // PINMODE
-    pinMode( pinEnableAB , OUTPUT );
-    pinMode( pinEnableXY , OUTPUT );
-    pinMode( pinEnableZ  , OUTPUT );
-    pinMode( pinDirX     , OUTPUT );
-    pinMode( pinStepX    , OUTPUT );
-    pinMode( pinDirY     , OUTPUT );
-    pinMode( pinStepY    , OUTPUT );
-    pinMode( pinDirA     , OUTPUT );
-    pinMode( pinStepA    , OUTPUT );
-    pinMode( pinDirB     , OUTPUT );
-    pinMode( pinStepB    , OUTPUT );
-    pinMode( PING        , OUTPUT );
-
-    pinMode( Z_POSITION  , INPUT  );
-
-    // SERIAL
-    Serial.begin(9600);
-
-    // Blabla, blablabla
-    Serial.println("==================================================");
-    Serial.println("  _______ ______     _     _  ______  ____ ______ ");
-    Serial.println(" (____   (____  )   | |   | |/ ___  |(____|______)");
-    Serial.println("  ____)  )____)  )__| |   | | |   | | | |   | |   ");
-    Serial.println(" |  __  (|  __  (___) |   | | |   | | | |   | |   ");
-    Serial.println(" | |__)  ) |__)  )  | |___| | |   | |_| |_  | |   ");
-    Serial.println(" |______/|______/   |______/|_|   |_(_____) |_|   ");
-    Serial.println("            _ Astromech Industrie _               ");
-    Serial.println("      > https://github.com/Gruniek/BB-UNIT <      ");
-    Serial.println("           > http://r2builders.fr/ <              ");
-    Serial.print("           FIRMWARE VERSION : ");
-    Serial.print(version);
-    Serial.println("               ");
-    Serial.println("==================================================");
-
-    Serial.println(" ");
-    Serial.println("[1]-Booting up...");
-
-    // Start of the I2C protocol
-    Serial.print("[2]-Initializing I2C devices...  I2C ADRESS :");
-    Serial.print(adress);
-    Wire.begin(adress);
-
-    // Start the MPU6050 Gyroscope
-    Serial.print("[3]-Connect to the MPU6050 : ");
-    accelgyro.initialize();
-    //Serial.println(accelgyro.testConnection());
-    Serial.println(accelgyro.testConnection() ? "Connection successful" : "Connection failed");
-
-    // Start the RF24 Radio controll
-    Serial.println("[4]-Initializing RF24 devices...  ");
-    radio.begin();
-    radio.openReadingPipe(0, 00001);
-    radio.startListening();
-
-    // END OF BOOT/SETUP
-    Serial.println("====================");
-    Serial.println("Booting successful !");
-    Serial.println("====================");
-}
-
-//=============================================================================//
-//   LOOP
-//=============================================================================//
-void loop()
-{
-    unsigned long currentG = millis(); // millis();
-
-    if (currentG - trigG  >= trigGyro)
-    {
-    	trigG = currentG;
-
-         // GET MOTION
-         //-------------------------------------------------------------------------//
-    	accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
-	if(invertXY)
-	{
-	    y = (((ax/180)+etalonX)+90);
-  	    x = (((ay/180)+etalonY)+90);
-	}
-	else
-	{
-	    x = (((ax/180)+etalonX)+90);
-  	    y = (((ay/180)+etalonY)+90);
-	}
-    }
-
-    // GET SERIAL AND RF24 DATA
-    //-------------------------------------------------------------------------//
-
-    char msg[64];
-    if (Serial.available() > 0)
-    {
-    	Serial.readBytesUntil('\n', msg, sizeof msg);
-    	newData = true;
-    }
-
-    if (radio.available())
-    {
-    	char msg[64] = {0};
-    	radio.read(&msg, sizeof(msg));
-    	newData = true;
-    }
-
-    if(newData)
-    {
-	Serial.println(msg);
-	newData = false;
-
-    	if (strcmp(strtok(msg, " "), "SET") == 0)
-    	{
-            Serial.println("UPDATE SETPOINT");
-      	    // trouvé le message
-      	    char *p;
-      	    while ((p = strtok(NULL, " ")) != NULL)
-      	    {
-       		int val = atoi(p + 1);
-       		switch (*p)
-       		{
-		    case 'x': setpointX  = val; break;
-          	    case 'y': setpointY  = val; break;
-      	  	    case 'm': multiplier = val; break;
-      		    case 'i': invertXY   = val; break;
-      		    case 'j': invertX    = val; break;
-      		    case 'k': invertX    = val; break;
-      		    case 'h': hysteresis = val; break;
-        	}
-      	    }
-    	}
-
-    	if (strcmp(strtok(msg, " "), "RUN") == 0)
-    	{
-            Serial.println("ROll BB-8 ROLL !");
-      	    production = true;
-    	}
-
-    	if (strcmp(strtok(msg, " "), "STOP") == 0)
-    	{
-    	    Serial.println("STOP");
-    	    production = false;
-    	}
-
-    	if (strcmp(strtok(msg, " "), "RESET") == 0)
-    	{
-    	    Serial.println("RESET");
-    	    production = false;
-    	    emgStop    = false;
-    	}
-
-    	if (strcmp(strtok(msg, " "), "BOOT") == 0)
-    	{
-    	    BOOT = true;
-    	    Serial.println("BOOTING UP...");
-    	    delay(2000);
-    	}
-
-    	if (strcmp(strtok(msg, " "), "ROTATE") == 0) // ROTATE d1 s100  <-- Rotate Z right, 18c/sec
-    	{
-      	    // trouvé le message
-      	    char *p;
-      	    while ((p = strtok(NULL, " ")) != NULL)
-      	    {
-                 int val = atoi(p + 1);
-        	 switch (*p)
-        	 {
-          	     case 'd': directZ  = val; break;
-          	     case 's': speedZ   = val; break;
-                 }
-            }
-    	}
-
-    	if (strcmp(strtok(msg, " "), "MOVE") == 0)
-    	{
-            Serial.println("UPDATE SETPOINT");
-      	    // trouvé le message
-      	    char *p;
-      	    while ((p = strtok(NULL, " ")) != NULL)
-      	    {
-                int val = atoi(p + 1);
-        	switch (*p)
-        	{
-          	     case 'a': speedA  = val; break;
-          	     case 'b': speedB  = val; break;
-      	  	     case 'c': dirA    = val; break;
-      		     case 'd': dirB    = val; break;
-        	}
-      	    }
-        }
-
-    	if (strcmp(strtok(msg, " "), "ENABLE") == 0)
-    	{
-       	    //Serial.println("UPDATE SETPOINT");
-  	    // trouvé le message
-  	    char *p;
-      	    while ((p = strtok(NULL, " ")) != NULL)
-   	    {
-      	        int val = atoi(p + 1);
-        	switch (*p)
-        	{
-        	    case 'a': enMotAB  = val; break;
-        	    case 'x': enMotXY  = val; break;
-      		    case 'z': enMotZ   = val; break;
-        	}
-      	    }
-    	}
-
-    }
-
-   digitalWrite(pinEnableAB, enMotAB);
-   digitalWrite(pinEnableXY, enMotXY);
-   digitalWrite(pinEnableZ, enMotZ);
-
-   if(BOOT)
-   {
- 	enMotAB = true;
- 	enMotXY = true;
- 	enMotZ  = true;
-
-   	// SET X IN POSITION
-   	if(x < 90) directX = false;
-  	else directX = true;
-
-  	if(invertX)
-  	{
-    		if(directX) directX = false;
-    		else directX = true;
-  	}
-  	digitalWrite(pinDirX, directX); // dirX
-
-  	if(x > (setpointX + hysteresis) || (x < setpointX - hysteresis ))
-  	{
-  	    digitalWrite(pinStepX, 1);
-            delayMicroseconds( 500 );
-    	    digitalWrite(pinStepX, 0);
-    	    delayMicroseconds( 500 );
-  	}
-  	else
-  	{
-  	    if(!xok)
-            {
-  	        Serial.println("BOOT x1 ");
-  		xok = true;
-  		delay(2000);
- 	    }
-  	}
-
-        // SET Y IN POSITION
-   	if(y < 90) directY = false;
-  	else directY = true;
-
-	if(invertY)
-  	{
-    	    if(directY) directY = false;
-    	    else directY = true;
-  	}
-  	digitalWrite(pinDirY, directY); // dirX
-
-  	if(x > (setpointY + hysteresis) || (y < setpointY - hysteresis ))
-  	{
-  	    digitalWrite(pinStepY, 1);
-            delayMicroseconds( 500 );
-    	    digitalWrite(pinStepY, 0);
-    	    delayMicroseconds( 500 );
-        }
-  	else
-  	{
-  	    if(!yok)
-  	    {
-  		Serial.println("BOOT y1 ");
-  		yok = true;
-  		delay(2000);
-  	    }
-  	}
-
-  	// SET Z IN POSITION
-  	if(!Z_POSITION)
-  	{
-  	    digitalWrite(pinStepZ, 1);
-            delayMicroseconds( 500 );
-    	    digitalWrite(pinStepZ, 0);
-    	    delayMicroseconds( 500 );
-  	}
-  	else
-  	{
-       	    if(!zok)
-  	    {
-  	        Serial.println("BOOT z1 ");
-  		zok = true;
-  		Zangle = 0;
-  		delay(2000);
-  	    }
-  	}
-
-  	if( xok && yok && zok)
-  	{
-	    Serial.println("STAT b1 ");
-  	    Serial.println("Booting UP OK!");
-  	    Serial.println("SEND 'RUN \n' for start the production");
-  	    BOOT = false;
-  	}
-     }
-
-    // PRODUCTION CODE
-    //-------------------------------------------------------------------------//
-    if(production && !emgStop)  //-
-    {
-    	enMotAB = true;
- 	enMotXY = true;
- 	enMotZ  = true;
-
-    	//======================================================================
-    	//        d8888
-    	//       d88888
-     	//	d88P888
-    	//     d88P 888
-   	//    d88P  888
-  	//   d88P   888
- 	//  d8888888888
-	// d88P     888
-	//======================================================================
-    	// MOTOR A (Left)
-
-	// Run the motor
-	if(speedA > 0) runA = true;
-	else runA = false;
-	speedA = 1000 / speedA;
-
-	// Motor direction / With inversion
-	if(invertA)
-  	{
-    	    if(dirA) dirA = false;
-	    else dirA = true;
-	}
-	digitalWrite(pinDirA, dirA); // Set the direction
-
-	// Send Step inpultion to the motor
-	unsigned long currentA = millis(); // millis();
-	if (currentA - previousMillisA >= speedA)
-	{
-	    previousMillisA = currentA;
-
-	    if(runA)
-	    {
-	        digitalWrite(pinStepA, 1);
-	        delayMicroseconds( 500 );
-	        digitalWrite(pinStepA, 0);
-	        delayMicroseconds( 500 );
-	    }
-	}
-
-    	//======================================================================
-	// 888888b.
-	// 888  "88b
-	// 888  .88P
-	// 8888888K.
-	// 888  "Y88b
-	// 888    888
-	// 888   d88P
-	// 8888888P"
-	//======================================================================
-	// MOTOR B (Right)
-
-	// Run the motor
-	if(speedB > 0) runB = true;
-	else runB = false;
-	speedB = 1000 / speedB;
-
-	// Motor direction / With inversion
-	if(invertB)
- 	{
-	    if(dirB) dirB = false;
-	    else dirB = true;
-	}
-	digitalWrite(pinDirB, dirB); // Set the direction
-
-	// Send Step inpultion to the motor
-	unsigned long currentB = millis(); // millis();
-	if (currentB - previousMillisB >= speedB)
-	{
-	    previousMillisB = currentB;
-
-	    if(runB)
-	    {
-	        digitalWrite(pinStepB, 1);
-	        delayMicroseconds( 500 );
-	        digitalWrite(pinStepB, 0);
-	        delayMicroseconds( 500 );
-	     }
-	}
-
-    	//======================================================================
-        // Y88b   d88P
-	//  Y88b d88P
-	//   Y88o88P
-	//    Y888P
-	//    d888b
-	//   d88888b
-	//  d88P Y88b
-	// d88P   Y88b
-	//======================================================================
-
-	// Direction
-  	if(x < 90) directX = false;
-  	else directX = true;
-
-  	if(invertX)
-  	{
-    	    if(directX) directX = false;
-    	    else directX = true;
-  	}
-  	digitalWrite(pinDirX, directX); // dirX
-
-  	// Si ont doit demarer le moteur
-  	if(x > (setpointX + hysteresis) || (x < setpointX - hysteresis ))
-  	{
-    	    if(x > minX && x < maxX) runX = true;
-    	    else runX = false;
-  	}
-  	else runX = false;
-
-  	// Calcul du PID X
-  	if(x < 90) vx = (90 - x);
-  	if(x == 0) vx = 0;
-  	if(x > 90) vx = (x - 90);
-
-  	speedX = 1000 / (vx);
-  	speedX = speedX * multiplier; // DEL
-  	if(speedX < 15) speedX = 15;
-
-	// Mise en route du moteur
-  	unsigned long currentX = millis();
-
-    	if (currentX - previousMillisX >= speedX)
-    	{
-      	    previousMillisX = currentX;
-
-	    if(runX)
-      	    {
-                digitalWrite(pinStepX, 1);
-        	delayMicroseconds( 500 );
-        	digitalWrite(pinStepX, 0);
-    	 	delayMicroseconds( 500 );
-            }
-  	}
-
-    	//======================================================================
-	// Y88b   d88P
-	//  Y88b d88P
-  	//   Y88o88P
-   	//    Y888P
-    	//     888
-    	//     888
-        //     888
-        //     888
-	//======================================================================
-
-	// Direction
-  	if(y < 90) directY = false;
-  	else directY = true;
-  	if(invertY)
-  	{
-    	    if(directY) directY = false;
-    	    else directY = true;
-  	}
-  	digitalWrite(pinDirY, directY);
-
-	// Si ont doit demarer le moteur
-  	if(y > (setpointY + hysteresis) || (y < setpointY - hysteresis ))
-  	{
-    	    if(y > minY && y < maxY) runY = true;
-    	    else runY = false;
-  	}
-  	else runY = false;
-
-  	// Calcul du PID Y
-  	if(y < 90) vy = (90 - y);
-  	if(y == 0) vy = 0;
-  	if(y > 90) vy = (y - 90);
-
-  	speedY = 1000 / (vy);
-  	speedY = speedY * multiplier; // DEL
-  	if(speedY < 15) speedY = 15;
-
-	// Mise en route du moteur
-  	unsigned long currentY = millis(); // millis();
-
-    	if (currentY - previousMillisY >= speedY)
-    	{
-      	    previousMillisY = currentY;
-
-            if(runY)
-      	    {
-        	digitalWrite(pinStepY, 1);
-        	delayMicroseconds( 500 );
-        	digitalWrite(pinStepY, 0);
-        	delayMicroseconds( 500 );
-            }
-  	}
-
-    	//======================================================================
-	// 8888888888P
-        //       d88P
-        //      d88P
-    	//     d88P
-        //    d88P
-        //   d88P
-        //  d88P
-        // d8888888888
-	//======================================================================
-
-	digitalWrite(pinDirZ, directZ);
-	if(speedZ != 0)
-  	{
-  	    unsigned long currentZ = millis();
-
-	    if (currentZ - previousMillisZ >= speedZ)
-    	    {
-      		previousMillisZ = currentZ;
-
-		digitalWrite(pinStepY, 1);
-    	    	delayMicroseconds( 500 );
-    	    	digitalWrite(pinStepY, 0);
-    	    	delayMicroseconds( 500 );
-    	    	if(directZ) Zangle++;
-    	    	else Zangle--;
-  	    }
-  	}
-
-	if(Zangle == 201) Zangle = 0;
-  	if(Zangle == -1)  Zangle = 0;
-
-    }
-
-    // TRIGGER / SEC
-    //-------------------------------------------------------------------------//
-    unsigned long currentS = millis(); // millis();
-
-    if (currentS - trigS  >= trigSec)
-    {
-    	trigS = currentS;
-
-    	// PING
-    	if(LED_PING) LED_PING = false;
-    	else LED_PING = true;
-    	digitalWrite(PING, LED_PING);
-
-	// IF THE MPU6050 ARE ALWAYS CONNECTED, IF NOT, HE RECONNECT AUTOMATICLY
-    	if(!accelgyro.testConnection());
-    	{
-    	    production = false;
-    	    emgStop = true;
-    	    accelgyro.initialize();
-    	    if(accelgyro.testConnection())
-    	    {
-    		production = true;
-    	    }
-    	}
-
-    	/*
-
-    	// SEND STATUT
-    	Serial.print("STAT x");
-    	Serial.print(x);
-    	Serial.print(" y");
-    	Serial.print(y);
-    	Serial.print(" i");
-    	Serial.print(invertXY);
-    	Serial.print(" j");
-    	Serial.print(invertX);
-    	Serial.print(" k");
-    	Serial.print(invertY);
-    	Serial.print(" m");
-    	Serial.print(multiplier);
-    	Serial.print(" z");
-    	Serial.print(Zangle);
-
-    	Serial.println(" ");
-
-    	*/
-    } // ENF OF PRODUCTION
-} // END OF LOOP
-
-// VOID FOR TAKE THE CURRENT
-int current(int Cpin)
-{
-    int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module
-    int RawValue= 0;
-    int ACSoffset = 2500;
-    double Voltage = 0;
-    double Amps = 0;
-
-    RawValue = analogRead(Cpin);
-    Voltage = (RawValue / 1024.0) * 5000; // Gets you mV
-    Amps = ((Voltage - ACSoffset) / mVperAmp);
-
-    return(Amps);
-}
-
-// VOID FOR TAKE THE BATTERY VOLTAGE
-int voltage(int Vpin)
-{
-    float vout = 0.0;
-    float vin = 0.0;
-    float R1 = 100000.0; // resistance of R1 (100K) -see text!
-    float R2 = 10000.0; // resistance of R2 (10K) - see text!
-    int value = 0;
-
-    value = analogRead(Vpin);
-    vout = (value * 5.0) / 1024.0;
-    vin = vout / (R2/(R1+R2));
-    if (vin<0.09) vin=0.0;
-
-    return(vin);
-}


Delete OttoDIY_avoid_mhs.ino

Delete OttoDIY_avoid_mhs.ino


chore: Remove unnecessary GettingStarted example of NRF24 lib

--- NRF24/GettingStarted/GettingStarted.ino
+++ NRF24/GettingStarted/GettingStarted.ino
@@ -1,142 +0,0 @@
-
-/*
-* Getting Started example sketch for nRF24L01+ radios
-* This is a very basic example of how to send data from one node to another
-* Updated: Dec 2014 by TMRh20
-*/
-
-#include <SPI.h>
-#include "RF24.h"
-
-/****************** User Config ***************************/
-/***      Set this radio as radio number 0 or 1         ***/
-bool radioNumber = 1;
-
-/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
-RF24 radio(7,8);
-/**********************************************************/
-
-byte addresses[][6] = {"1Node","2Node"};
-
-// Used to control whether this node is sending or receiving
-bool role = 0;
-
-void setup() {
-  Serial.begin(115200);
-  Serial.println(F("RF24/examples/GettingStarted"));
-  Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));
-
-  radio.begin();
-
-  // Set the PA Level low to prevent power supply related issues since this is a
- // getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
-  radio.setPALevel(RF24_PA_LOW);
-
-  // Open a writing and reading pipe on each radio, with opposite addresses
-  if(radioNumber){
-    radio.openWritingPipe(addresses[1]);
-    radio.openReadingPipe(1,addresses[0]);
-  }else{
-    radio.openWritingPipe(addresses[0]);
-    radio.openReadingPipe(1,addresses[1]);
-  }
-
-  // Start the radio listening for data
-  radio.startListening();
-}
-
-void loop() {
-
-
-/****************** Ping Out Role ***************************/
-if (role == 1)  {
-
-    radio.stopListening();                                    // First, stop listening so we can talk.
-
-
-    Serial.println(F("Now sending"));
-
-    unsigned long start_time = micros();                             // Take the time, and send it.  This will block until complete
-     if (!radio.write( &start_time, sizeof(unsigned long) )){
-       Serial.println(F("failed"));
-     }
-
-    radio.startListening();                                    // Now, continue listening
-
-    unsigned long started_waiting_at = micros();               // Set up a timeout period, get the current microseconds
-    boolean timeout = false;                                   // Set up a variable to indicate if a response was received or not
-
-    while ( ! radio.available() ){                             // While nothing is received
-      if (micros() - started_waiting_at > 200000 ){            // If waited longer than 200ms, indicate timeout and exit while loop
-          timeout = true;
-          break;
-      }
-    }
-
-    if ( timeout ){                                             // Describe the results
-        Serial.println(F("Failed, response timed out."));
-    }else{
-        unsigned long got_time;                                 // Grab the response, compare, and send to debugging spew
-        radio.read( &got_time, sizeof(unsigned long) );
-        unsigned long end_time = micros();
-
-        // Spew it
-        Serial.print(F("Sent "));
-        Serial.print(start_time);
-        Serial.print(F(", Got response "));
-        Serial.print(got_time);
-        Serial.print(F(", Round-trip delay "));
-        Serial.print(end_time-start_time);
-        Serial.println(F(" microseconds"));
-    }
-
-    // Try again 1s later
-    delay(1000);
-  }
-
-
-
-/****************** Pong Back Role ***************************/
-
-  if ( role == 0 )
-  {
-    unsigned long got_time;
-
-    if( radio.available()){
-                                                                    // Variable for the received timestamp
-      while (radio.available()) {                                   // While there is data ready
-        radio.read( &got_time, sizeof(unsigned long) );             // Get the payload
-      }
-
-      radio.stopListening();                                        // First, stop listening so we can talk
-      radio.write( &got_time, sizeof(unsigned long) );              // Send the final one back.
-      radio.startListening();                                       // Now, resume listening so we catch the next packets.
-      Serial.print(F("Sent response "));
-      Serial.println(got_time);
-   }
- }
-
-
-
-
-/****************** Change Roles via Serial Commands ***************************/
-
-  if ( Serial.available() )
-  {
-    char c = toupper(Serial.read());
-    if ( c == 'T' && role == 0 ){
-      Serial.println(F("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK"));
-      role = 1;                  // Become the primary transmitter (ping out)
-
-   }else
-    if ( c == 'R' && role == 1 ){
-      Serial.println(F("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"));
-       role = 0;                // Become the primary receiver (pong back)
-       radio.startListening();
-
-    }
-  }
-
-
-} // Loop
-


Set and clear /SS directly rather than using digitalWrite (didn't seem to speed anything up though

--- a3000_rom_emulator/firmware/rom_emulator.ino
+++ a3000_rom_emulator/firmware/rom_emulator.ino
@@ -53,6 +53,12 @@
 #define CPLD_SCK_PIN 23
 // PA10 / SERCOM2.2 (SERCOM-ALT) - D34 - cpld_SS
 #define CPLD_SS_PIN 34
+#define CPLD_SS_PORT (PORT->Group[0])
+#define CPLD_SS_PORT_BIT 10
+#define CPLD_SS_SET() do { CPLD_SS_PORT.OUTSET.reg = 1 << CPLD_SS_PORT_BIT; } while (0)
+#define CPLD_SS_CLEAR() do { CPLD_SS_PORT.OUTCLR.reg = 1 << CPLD_SS_PORT_BIT; } while (0)
+// #define CPLD_SS_CLEAR() digitalWrite(CPLD_SS_PIN, LOW)
+// #define CPLD_SS_SET() digitalWrite(CPLD_SS_PIN, HIGH)
 // PA11 / SERCOM2.3 (SERCOM-ALT) - D22 - cpld_MISO
 #define CPLD_MISO_PIN 22

@@ -111,7 +117,7 @@
 // Write a 32-bit word to the flash chips
 void flash_write(uint32_t A, uint32_t D) {
   // Write a 32-bit word to the flash, leaving allowing_arm_access == 0
-  digitalWrite(CPLD_SS_PIN, LOW);
+  CPLD_SS_CLEAR();
   spi_transfer((uint8_t)(0x00 | ((A & 0x3f0000L) >> 16L)));  // allowing_arm_access, rnw, A[21:16]
   spi_transfer((uint8_t)((A & 0xff00L) >> 8L));  // A[15:8]
   spi_transfer((uint8_t)(A & 0xffL));  // A[7:0]
@@ -120,7 +126,7 @@
   spi_transfer((uint8_t)((D & 0xff00L) >> 8L));  // D[15:8]
   spi_transfer((uint8_t)(D & 0xffL));  // D[7:0]
   spi_transfer(0);
-  digitalWrite(CPLD_SS_PIN, HIGH);
+  CPLD_SS_SET();
 #ifdef SHOW_ALL_FLASH_ACCESS
   Serial.print("Flash write *0x");
   Serial.print(A, HEX);
@@ -138,7 +144,7 @@
 // Read a 32-bit word from the flash chips
 uint32_t flash_read(uint32_t A) {
   // Read a 32-bit word from the flash, leaving allowing_arm_access == 0
-  digitalWrite(CPLD_SS_PIN, LOW);
+  CPLD_SS_CLEAR();
   spi_transfer((uint8_t)(0x40 | ((A & 0x3f0000) >> 16)));  // allowing_arm_access, rnw, A[21:16]
   spi_transfer((uint8_t)((A & 0xff00) >> 8));  // A[15:8]
   spi_transfer((uint8_t)(A & 0xff));  // A[7:0]
@@ -147,7 +153,7 @@
   D |= ((uint32_t)spi_transfer(0)) << 16;  // D[23:16]
   D |= ((uint32_t)spi_transfer(0)) << 8;  // D[15:8]
   D |= ((uint32_t)spi_transfer(0));  // D[7:0]
-  digitalWrite(CPLD_SS_PIN, HIGH);
+  CPLD_SS_SET();
 #ifdef SHOW_ALL_FLASH_ACCESS
   Serial.print("Flash read *0x");
   Serial.print(A, HEX);
@@ -160,9 +166,9 @@
 // Tell the CPLD to return control of the flash to the host machine
 void flash_unlock() {
   // Reset allowing_arm_access to 1 in the CPLD
-  digitalWrite(CPLD_SS_PIN, LOW);
+  CPLD_SS_CLEAR();
   spi_transfer(0xff);
-  digitalWrite(CPLD_SS_PIN, HIGH);
+  CPLD_SS_SET();
 }

 // Pulse NRESET on the flash chips
@@ -190,7 +196,7 @@

   // Set up fast SPI comms on SERCOM2 with CPLD
   pinMode(CPLD_SS_PIN, OUTPUT);
-  digitalWrite(CPLD_SS_PIN, HIGH);
+  CPLD_SS_SET();
   cpld_spi.begin();
   pinPeripheral(CPLD_MOSI_PIN, PIO_SERCOM_ALT);
   pinPeripheral(CPLD_SCK_PIN, PIO_SERCOM_ALT);


printando no meio do send NET

printando no meio do send NET

--- codigo.ino
+++ codigo.ino
@@ -167,7 +167,7 @@
 }
 void sendCodeNec(int repeat, int pressed_button)
 {
-
+    printDadosBotao(pressed_button);
     if (repeat)
     {
         irsend.sendNEC(REPEAT, buttons_list[pressed_button].codeLen);


Fixed the powercell configuration and added the abiltiy to offset the start led in the sequence.

My powercell can only fit 14 led's in the window so I had to add the
offset and fix the total so I can use only the middle 14 led's

--- Arduino/Neutrino_Wand/Neutrino_Wand.ino
+++ Arduino/Neutrino_Wand/Neutrino_Wand.ino
@@ -52,7 +52,7 @@
 // available options
 // ##############################
 const bool useGameCyclotronEffect = true;   // set this to true to get the fading previous cyclotron light in the idle sequence
-const bool useCyclotronFadeInEffect = true; // Instead of the yellow alternate flashing on boot/vent this fades the cyclotron in from off to red
+const bool useCyclotronFadeInEffect = false; // Instead of the yellow alternate flashing on boot/vent this fades the cyclotron in from off to red
 const bool useDialogTracks = true;          // set to true if you want the dialog tracks to play after firing for 5 seconds

 // Possible Pack states
@@ -523,13 +523,15 @@
 unsigned long prevFadeCycMillis = 0;    // last time we changed a cyclotron light in the idle sequence

 // LED tracking variables
-const int powerSeqTotal = 15;       // total number of led's for powercell 0 based
-int powerSeqNum = 0;                // current running powercell sequence led
-int powerShutdownSeqNum = 15;       // shutdown sequence counts down from 16
+const int powercellLedCount = 15;                                         // total number of led's in the animation
+const int powercellIndexOffset = 0;                                       // first led offset into the led chain for the animation
+const int powerSeqTotal = powercellLedCount;                              // total number of led's for powercell 0 based
+int powerSeqNum = powercellIndexOffset;                                   // current running powercell sequence led
+int powerShutdownSeqNum = powercellLedCount - powercellIndexOffset;       // shutdown sequence counts down

 // animation level trackers for the boot and shutdown
-int currentBootLevel = -1;          // current powercell boot level sequence led
-int currentLightLevel = 15;         // current powercell boot light sequence led
+int currentBootLevel = powercellIndexOffset;                              // current powercell boot level sequence led
+int currentLightLevel = powercellLedCount - powercellIndexOffset;         // current powercell boot light sequence led

 void setCyclotronLightState(int startLed, int endLed, int state ){
   switch ( state ) {
@@ -576,10 +578,10 @@
   // reset vars
   powerBooted = false;
   poweredDown = true;
-  powerSeqNum = 0;
-  powerShutdownSeqNum = 15;
-  currentLightLevel = 15;
-  currentBootLevel = -1;
+  powerSeqNum = powercellIndexOffset;
+  powerShutdownSeqNum = powercellLedCount - powercellIndexOffset;
+  currentLightLevel = powercellLedCount;
+  currentBootLevel = powercellIndexOffset;
   cyclotronRunningFadeIn = 0;

   // shutoff the leds
@@ -642,21 +644,24 @@
     // START POWERCELL
     if( currentBootLevel != powerSeqTotal ){
       if( currentBootLevel == currentLightLevel){
-        powerStick.setPixelColor(currentBootLevel, powerStick.Color(0, 0, 150));
+        if(currentLightLevel+1 <= powerSeqTotal){
+          powerStick.setPixelColor(currentLightLevel+1, 0);
+        }
+        powerStick.setPixelColor(currentBootLevel, powerStick.Color(0, 0, 255));
         currentLightLevel = powerSeqTotal;
         currentBootLevel++;
       }else{
         if(currentLightLevel+1 <= powerSeqTotal){
           powerStick.setPixelColor(currentLightLevel+1, 0);
         }
-        powerStick.setPixelColor(currentLightLevel, powerStick.Color(0, 0, 150));
+        powerStick.setPixelColor(currentLightLevel, powerStick.Color(0, 0, 255));
         currentLightLevel--;
       }
       doUpdate = true;
     }else{
       powerBooted = true;
-      currentBootLevel = -1;
-      currentLightLevel = 15;
+      currentBootLevel = powercellIndexOffset;
+      currentLightLevel = powercellLedCount - powercellIndexOffset;
     }
     // END POWERCELL
   }
@@ -790,7 +795,7 @@
     // save the last time you blinked the LED
     prevPwrMillis = currentMillis;

-    for ( int i = 0; i <= powerSeqTotal; i++) {
+    for ( int i = powercellIndexOffset; i <= powerSeqTotal; i++) {
       if ( i <= powerSeqNum ) {
         powerStick.setPixelColor(i, powerStick.Color(0, 0, 150));
       } else {
@@ -801,7 +806,7 @@
     if ( powerSeqNum <= powerSeqTotal) {
       powerSeqNum++;
     } else {
-      powerSeqNum = 0;
+      powerSeqNum = powercellIndexOffset;
     }

     doUpdate = true;
@@ -832,7 +837,7 @@
     // END CYCLOTRON

     // START POWERCELL
-    for ( int i = powerSeqTotal; i >= 0; i--) {
+    for ( int i = powerSeqTotal; i >= powercellIndexOffset; i--) {
       if ( i <= powerShutdownSeqNum ) {
         powerStick.setPixelColor(i, powerStick.Color(0, 0, 150));
       } else {
@@ -842,11 +847,11 @@

     powerStick.show();

-    if ( powerShutdownSeqNum >= 0) {
+    if ( powerShutdownSeqNum >= powercellIndexOffset) {
       powerShutdownSeqNum--;
     } else {
       poweredDown = true;
-      powerShutdownSeqNum = 15;
+      powerShutdownSeqNum = powercellLedCount - powercellIndexOffset;
       cyclotronFadeOut = 255;
     }
     // END POWERCELL


Renaming and commenting pattenrs

Renaming and commenting pattenrs

--- staff/staff.ino
+++ staff/staff.ino
@@ -15,7 +15,7 @@
 #define NIGHT_SPARKLES 2
 #define SINGLE_COLOR_SPARKLES 3
 #define DAVE 4
-#define WORMS 5
+#define SHOOTING_GRADIENTS 5
 #define DISCO_BARBER_1 6
 #define DISCO_TWIRL 7
 #define DISCO_BARBER_2 8
@@ -51,6 +51,7 @@
 int ms = 0;

 // Dave's pattern. By Dave Grijalva with love.
+// A gradient background, with rotating bright points and white sparkles.
 void dave() {
   for (int k=0; k<NUM_LEDS-1; k++) {
     uint8_t k8 = k;
@@ -128,7 +129,7 @@
 uint8_t wormsStartingHue = 180; // The current hue
 uint8_t wormsBaseBeat = 10; // Higher = faster movement.

-void worms() {
+void shootingGradients() {
   fadeToBlackBy(leds, NUM_LEDS, wormsFadeRate);
   for ( int i = 0; i < numberOfWorms; i++) {
     for ( int j = 0; j < 80; j++) {
@@ -146,7 +147,8 @@
 uint8_t discoBarberCutoff = 120;
 uint8_t discoBarberSaturation = 240;

-void discoBarber() {
+// This pattern is called for both Disco Barber and Disco Barber 2.
+void discoBarbers() {
   if (patternId == DISCO_BARBER_1) {
     discoBarberFrequency = 5;
     discoBarberPhase += 24;
@@ -263,9 +265,9 @@
   } else if (patternId == SINGLE_COLOR_SPARKLES) {
     sparkles();
   } else if (patternId == DISCO_BARBER_1 || patternId == DISCO_BARBER_2) {
-    discoBarber();
-  } else if (patternId == WORMS) {
-    worms();
+    discoBarbers();
+  } else if (patternId == SHOOTING_GRADIENTS) {
+    shootingGradients();
   } else if (patternId == DISCO_TWIRL) {
     discoTwirl();
   } else if (patternId == DISCO_TWIRL_2) {


20150217.1124

--- cmdMULTIsens/src/sketch.ino
+++ cmdMULTIsens/src/sketch.ino
@@ -59,7 +59,7 @@
         Serial.println(" ");
         Serial.println("cmdMULTIsens help is underway!");
         Serial.println(" ");
-        Serial.println("H | h : DHT22 humidity")
+        Serial.println("H | h : DHT22 humidity");
         Serial.println("T | t : TMP36 temperature");
         break;
       case 'H':


Fix imutesting.ino

Fix imutesting.ino

--- Kirbi/testing/imutesting/imutesting.ino
+++ Kirbi/testing/imutesting/imutesting.ino
@@ -4,14 +4,15 @@
 ICM20948 icm(Wire2, (uint8_t)0x68);

 void setup() {
+    delay(1000);
   // put your setup code here, to run once:
   pinMode(9, OUTPUT);
   digitalWrite(9, LOW);
   Serial.begin(115200);
-  //Wire with SDA 8 and SCL 7 for Kirbi. Wire2 with SDA 4 and SCL3
+  //Wire with SDA 8 and SCL 7 for Kirbi. Wire2 with SDA 4 and SCL3 for Gucci.
   Wire2.begin();
-  Wire2.setSDA(8);
-  Wire2.setSCL(7);
+  Wire2.setSDA(4);
+  Wire2.setSCL(3);
   Serial.print(icm.begin());
   icm.disableDataReadyInterrupt();
   icm.configAccel(ICM20948::ACCEL_RANGE_2G, ICM20948::ACCEL_DLPF_BANDWIDTH_6HZ);


Cleanup

Cleanup

--- autotop986.ino
+++ autotop986.ino
@@ -17,6 +17,18 @@

 #include "Switch.h"
 #include "SimpleTimer.h"
+
+// Start editable settings //
+
+// Edit these to your own liking...
+
+// time taken to open top
+#define openTime 15600
+// time taken to close top
+#define closeTime 16400
+
+// time to lock in manual mode once engaged
+#define manualModeLockTime 1000

 // pin definitions
 #define pinOpenBtnOut       2
@@ -25,15 +37,7 @@
 #define pinOpenBtnIn        8
 #define pinCloseBtnIn       9

-#define loopInterval 50
-
-// time taken to open top
-#define openTime 15600
-// time taken to close top
-#define closeTime 16400
-
-// time to lock in manual mode once engaged
-#define manualModeLockTime 1000
+// End editable settings //

 // operation modes
 #define modeWait 0
@@ -43,7 +47,7 @@
 #define modeManualClose 4
 #define modeHalt 5

-unsigned long ms, motorStartTime, manualModeReleaseTime;
+unsigned long ms, motorStartTime, manualModeLastMoveTime;
 bool outputRequired = false;
 bool manualModeLocked = false;
 bool openTimeComplete = false;
@@ -59,7 +63,7 @@

 void setup() {
   Serial.begin(9600);
-  Serial.println("setup");
+  log("setup");

   initInputPins();
   initOutputPins();
@@ -73,8 +77,6 @@
   updateTimers();
   updateMode();
   sendOutput();
-
-  //delay(loopInterval);
 }

@@ -103,7 +105,7 @@
 /** Timer Functions */

 void updateTimers() {
-  manualModeLocked = (ms - manualModeReleaseTime < manualModeLockTime);
+  manualModeLocked = (ms - manualModeLastMoveTime < manualModeLockTime);
   openTimeComplete = (ms - motorStartTime > openTime);
   closeTimeComplete = (ms - motorStartTime > closeTime);
 }
@@ -142,19 +144,29 @@
 void updateModeWait() {
   log("updateModeWait");
   if (manualModeLocked) {
-    //react to buttons locked in manual mode
-    if (openButtonIn.on()) {
-      currentMode = modeManualOpen;
-    } else if (closeButtonIn.on()) {
-      currentMode = modeManualClose;
-    }
+    updateModeWaitManual();
   } else {
-    //react to buttons in auto mode
-    if (openButtonIn.on()) {
-      currentMode = modeAutoOpen;
-    } else if (closeButtonIn.on()) {
-      currentMode = modeAutoClose;
-    }
+    updateModeWaitAuto();
+  }
+}
+
+void updateModeWaitManual() {
+  log("updateModeWaitManual");
+  //react to buttons while locked in manual mode
+  if (openButtonIn.on()) {
+    currentMode = modeManualOpen;
+  } else if (closeButtonIn.on()) {
+    currentMode = modeManualClose;
+  }
+}
+
+void updateModeWaitAuto() {
+  log("updateModeWaitAuto");
+  //react to buttons in auto mode
+  if (openButtonIn.on()) {
+    currentMode = modeAutoOpen;
+  } else if (closeButtonIn.on()) {
+    currentMode = modeAutoClose;
   }
 }

@@ -200,7 +212,7 @@
   //wait on button release
   if (!openButtonIn.on()) {
     currentMode = modeWait;
-    manualModeReleaseTime = millis();
+    manualModeLastMoveTime = millis();
   }
 }

@@ -209,7 +221,7 @@
   //wait on button release
   if (!closeButtonIn.on()) {
     currentMode = modeWait;
-    manualModeReleaseTime = millis();
+    manualModeLastMoveTime = millis();
   }
 }

@@ -225,8 +237,7 @@

 void sendOutput() {
   if (outputRequired) {
-    log("mode changed");
-    Serial.println(currentMode);
+    log("mode changed " + String(currentMode));

     if (currentMode == modeAutoOpen || currentMode == modeManualOpen) {
       sendOpen();


implement for accelerometer code

implement for accelerometer code

--- ScriptingAccessory/firmware/acc/acc.ino
+++ ScriptingAccessory/firmware/acc/acc.ino
@@ -1,4 +1,36 @@
+/* Copyright 2012 Google Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ *
+ * Project home page: http://code.google.com/p/usb-serial-for-android/
+ */
+
+#define STATE_INIT 0
+#define STATE_WRITE_FOR_CONNECT 1
+#define STATE_WRITE_FOR_DISCONNECT 2
+#define STATE_WRITE_DONE_FOR_CONNECT 3
+#define STATE_WRITE_DONE_FOR_DISCONNECT 4
+#define STATE_READ 5
+
+#define STRING_EOS "#_EOS_"
+#define COMMAND_START_TO_LOAD 0xFF
+
 #include <AcceleroMMA7361.h>
+
+static int state = STATE_INIT;

 AcceleroMMA7361 accelero;
 int x;
@@ -16,35 +48,83 @@

 void setup()
 {
-  Serial.begin(9600);
+  Serial.begin(115200);
   accelero.begin(13, 12, 11, 10, A0, A1, A2);
-  accelero.setARefVoltage(3.3);                   //sets the AREF voltage to 3.3V
-  accelero.setSensitivity(LOW);                   //sets the sensitivity to +/-6G
+  accelero.setARefVoltage(5.0);                   //sets the AREF voltage to 3.3V
+  accelero.setSensitivity(HIGH);                   //sets the sensitivity to +/-1.5G
   accelero.calibrate();
 }

 void loop()
 {
+  switch (state) {
+    case STATE_INIT:
+      if (Serial.peek() == 0xFF ) {
+        state = STATE_WRITE_FOR_CONNECT;
+      }
+      break;
+
+    case STATE_WRITE_FOR_CONNECT:
+      Serial.println("import android,time");
+      Serial.println("droid = android.Android()");
+      Serial.println("droid.makeToast('accelerometer')");
+      Serial.print("droid.makeToast('your steps are ");
+      Serial.print(cnt);
+      Serial.println("')");
+      state = STATE_WRITE_DONE_FOR_CONNECT;
+      break;
+
+    case STATE_WRITE_DONE_FOR_CONNECT:
+      Serial.print(STRING_EOS);
+      state = STATE_WRITE_FOR_DISCONNECT;
+      break;
+
+    case STATE_WRITE_FOR_DISCONNECT:
+      Serial.println("import android,time");
+      Serial.println("droid = android.Android()");
+      Serial.println("droid.makeToast('Hello, disconnnnnnnect')");
+      Serial.print("droid.makeToast('your steps are ");
+      Serial.print(cnt);
+      Serial.println("')");
+      state = STATE_WRITE_DONE_FOR_DISCONNECT;
+      break;
+
+    case STATE_WRITE_DONE_FOR_DISCONNECT:
+      Serial.print(STRING_EOS);
+      state = STATE_READ;
+      break;
+
+    case STATE_READ:
+    default:
+    break;
+  }
+//  delay(300);
+
+  updateAccelerometer();
+
+  delay(100);
+}
+
+void updateAccelerometer() {
   pre_x = x;
   x = accelero.getXRaw();
   checkWalking(x);
   y = accelero.getYRaw();
   z = accelero.getZRaw();
-  Serial.print("\nx: ");
-  Serial.print(x);
-  Serial.print("\ty: ");
-  Serial.print(y);
-  Serial.print("\tz: ");
-  Serial.print(z);
-  Serial.print("\tcnt: ");
-  Serial.print(cnt);
-  Serial.print("\tnum_data: ");
-  Serial.print(num_data);
-  Serial.print("\tindex: ");
-  Serial.print(index);
-  Serial.print("\tave: ");
-  Serial.print(ave);
-  delay(100);                                     //(make it readable)
+  //Serial.print("\nx: ");
+  //Serial.print(x);
+  //Serial.print("\ty: ");
+  //Serial.print(y);
+  //Serial.print("\tz: ");
+  //Serial.print(z);
+  //Serial.print("\tcnt: ");
+  //Serial.print(cnt);
+  //Serial.print("\tnum_data: ");
+  //Serial.print(num_data);
+  //Serial.print("\tindex: ");
+  //Serial.print(index);
+  //Serial.print("\tave: ");
+  //Serial.print(ave);
 }

 void checkWalking(int x) {
@@ -68,8 +148,6 @@
   for (int i = 0; i<= d; i++) {
     sum += history[i];
   }
-  Serial.print("\tsum: ");
-  Serial.print(sum);
   ave = sum / num_data;
   index++;
   if (index >= num_for_ave) {


[bugfix] copy 3 bytes for position data instead of 2

--- src/du.ino
+++ src/du.ino
@@ -35,7 +35,7 @@
   strncpy(val, messageBuffer + 4, 2);
   val[2] = '\0';
   strncpy(aux, messageBuffer + 6, 3);
-  aux[2] = '\0';
+  aux[3] = '\0';

   if (debug) {
     Serial.println(messageBuffer);


[major] add digitalRead, cleanup

[major] add digitalRead, cleanup

--- src/du.ino
+++ src/du.ino
@@ -66,8 +66,11 @@
 void sm(char *pin, char *val) {
   if (debug) Serial.println("sm");
   int p = atoi(pin);
-  if (strcmp(val, "00") == 0) pinMode(p, OUTPUT);
-  else pinMode(p, INPUT);
+  if (strcmp(val, "00") == 0) {
+    pinMode(p, OUTPUT);
+  } else {
+    pinMode(p, INPUT);
+  }
 }

 /*
@@ -77,12 +80,27 @@
   if (debug) Serial.println("dw");
   int p = atoi(pin);
   pinMode(p, OUTPUT);
-  if (strcmp(val, "00") == 0) digitalWrite(p, LOW);
-  else digitalWrite(p, HIGH);
+  if (strcmp(val, "00") == 0) {
+    digitalWrite(p, LOW);
+  } else {
+    digitalWrite(p, HIGH);
+  }
 }

 /*
  * Digital read
  */
-void dr(char *pin, char *val) {}
+void dr(char *pin, char *val) {
+  if (debug) Serial.println("dr");
+  int p = atoi(pin);
+  pinMode(p, INPUT);
+  int oraw = digitalRead(p);
+  char m[4];
+  char out[4];
+  sprintf(m, "%d", p);
+  sprintf(out, "%d", oraw);
+  strcat(m, "::");
+  strcat(m, out);
+  Serial.println(m);
+}


fixed def's

fixed def's

--- reciever/reciever.ino
+++ reciever/reciever.ino
@@ -13,7 +13,7 @@

 #define DATA_BITS_AMOUNT 36  //total amount of bits sent by BL999 sensor
 #define BITS_PER_PACKET 4 //36 bits are sent in packets by 4 bits (tetrads)
-#define DATA_ARRAY_SIZE 9 //totally we have 36/4 = 9 tetrads
+#define DATA_ARRAY_SIZE DATA_BITS_AMOUNT / BITS_PER_PACKET //totally we have 36/4 = 9 tetrads

 volatile unsigned int pwm_high_length = 0;
@@ -269,7 +269,3 @@
 void setState(byte st, boolean condition) {
     state = condition ? st : 0;
 }
-
-
-
-


Delete sketch.ino

Delete sketch.ino

--- sketch.ino
+++ sketch.ino
@@ -1,327 +0,0 @@
-
-// Neopixel Salt Lamp v2.0
-// By Chris Barrett - Polaris Interplanetary - Special Projects Division
-// Supports two modes; All pixel colour fade, and 8 pixel RGB mixer. All modes are asynchronous, and compartmentalized into functions.
-
-//  January 2017  - began to implement relative intervals to control the rate of colours firing and ensure better spacing and pacing.
-//  Dec  2016     - Changed shimmer to use a different array based system to try and finally end flickering.
-//  June 2016     - Re-implemented rotary encoder functions for brightness control
-//                - New timing function to space out updates
-//                - LIGHTNING FUNCTION
-//                - produces a quicker shimmer effect, may replace shimmer with it later.
-//  January 2016  - Shimmer has been overhauled. Cleaner, faster and more productive. NO MORE MID FADE FLICKER?
-//                - Collision detection has been implemented, not sure if it works, will need to check further.
-
-#include <Adafruit_NeoPixel.h>  //  Neopixel library
-//#include <avr/power.h>        //  Not sure why this is here, lol
-#include <Encoder.h>            //  Rotary encoder library.
-
-
-#define PIN            6        //  Which pin on the Arduino is connected to the NeoPixels
-
-
-#define NUMPIXELS      37      //  Highest pixel location.
-#define LOWPIXELS      0       //  Lowest pixel location This was helpful in prototyping because I could use a long strip of lights and only address the last few and stick them in the salt crystal.
-
-
-
-// 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);
-
-Encoder myEnc(2, 3);                                //  Encoder function variables
-
-//--------------------------------------------------//  TIMER STUFF
-
-
-/* These are from Blink without Delay
-Shows another way to execute delays. */
-unsigned long previousMillis = 0;
-unsigned long lastbolt = 0;
-unsigned long interval[30];
-int maxb;
-
-
-int butpin = 5;                                     //  integer to store button pin
-int butval;                                         //  Button digital read variable
-int butsel = 1;                                     //  Button mode selection variable.
-int butbounce;                                      //  button debounce
-int rcount;                                         //  Counter for red
-int gcount;                                         //  Counter for green
-int bcount;                                         //  Counter for blue
-int rval;                                           //  int stores red brightness
-int gval;                                           //  int stores green brightness
-int bval;                                           //  int stores blue brightness
-int rgo;                                            //  red go int, 0 for off, 1 for upwards, 2 for downwards
-int ggo;                                            //  green go int, 0 for off, 1 for upwards, 2 for downwards
-int bgo;                                            //  blue go int, 0 for off, 1 for upwards, 2 for downwards
-int magicnumber;                                    //  magic number determines when to fire colours
-int supbright;
-int interntimer;
-
-//--------------------------------------------------//  The following values are for the "Shimmer" routine
-int PixRay[NUMPIXELS][7];
-long oldPosition  = 255;                            //  integer to store encoder value
-int firstrun = 0;                                   //  array to write first run values to pixels
-int randosparkle =0;                                //  integer to hold the random number value
-
-//--------------------------------------------------// LIGHTNING
-int boltgo[8];
-int boltloc[8];
-int boltbright[8];
-int boltupdn[8];
-int boltready[8];
-
-void setup() {                                      //-----------------------------------------------(Setup)
-    pinMode(butpin, INPUT);                         //  Set buttonpin as input
- //   Serial.begin(9600);                           //  Initialize Serial Debug
-   pixels.begin();                                  //  This initializes the NeoPixel library.
-
-    for (int i=0; i <= (NUMPIXELS-1); i++){             //  set magic number for all pixray locations
-      PixRay[i][5] = {i};
-    }
-
-}
-
-void loop() {                                       //-----------------------------------------------(Main Loop)
-
-  if (firstrun == 0){
-  }
-
-  butcheck();
-
-unsigned int tnow = millis();
-
-   // some other logic here would decide when to change the LED state
-   // For this sample, just toggle every 4 seconds
-  if((tnow - previousMillis) >= interval[0]) {
-
-      if (oldPosition > 1 && oldPosition < 255){
-        supbright = oldPosition;
-      }
-
-      if (oldPosition < 0){
-        supbright = 0;
-      }
-
-      if (oldPosition > 255){
-        supbright = 255;
-      }
-
-
-      if (butsel == 1){
-          clearscreen();
-          shimmer();
-      }
-
-      if (butsel == 2){
-          clearscreen();
-          colourfade();
-      }
-
-      if (butsel == 3){
-          clearscreen();
-      }
-
-      pixels.show();                                  // This sends the updated pixel color to the hardware.
-    previousMillis = tnow;
-}
-
-}
-
-void clearscreen(){                                 //-----------------------------------------------(clears the strip)
-    for(int i=0;i<NUMPIXELS;i++){
-        pixels.setPixelColor(i, pixels.Color(0,0,0));
-    }
-}
-
-void butcheck(){                                    //-----------------------------------------------(Button Check Function)
-
-
-
-    long newPosition = myEnc.read();
-    if (newPosition != oldPosition) {
-
-
-    if (newPosition >= 100){
-      myEnc.write(100);
-    }
-    if (newPosition < 0){
-      myEnc.write(0);
-    }
-        oldPosition = newPosition;
-       // Serial.println(newPosition);
-    }
-
-    interval[0] = map(newPosition, 0, 100, 80, 0);
-    maxb = map(newPosition, 0, 100, 0, 255);
-
-    pinMode(butpin, INPUT);
-    butval = digitalRead(butpin);                   // check button pin for a high
-
-
-
-    if (butval == HIGH){                            // if high signal read add one to the button selection variable
-      butbounce = 1;
-    }
-
-    if (butbounce == 1 && butval == LOW){
-     butsel = butsel + 1;
-     butbounce = 0;
-    }
-
-    if (butsel > 2){                               //  resets the button value variable. I use this method so I can add more modes if I want later.
-    butsel = 1;
-    }
-}
-
-void colourfade(){                                  //-----------------------------------------------(Colour Fade Function)
-
-    magicnumber = random(0,30);                     //creates a magic number
-
-    if (magicnumber == 3 && rgo == 0){              //checks to see if magic number has selected red and red is not currently firing
-      rgo = 1;                                      //sets the red go bit to 1 meaning positive alternation
-    }
-
-    if (magicnumber == 10 && ggo == 0){              //checks to see if magic number has selected green
-      ggo = 1;
-    }
-
-    if (magicnumber == 20 && bgo == 0){             //checks to see if magic number has selected blue
-      bgo = 1;
-    }
-
-
-    // ---------------------------------------------// Write Red
-
-    if (rgo == 1){                                  // checks for ascent stage bit, adds one to red brightness
-      rval = rval + 1;
-    }
-
-    if (rgo == 2){                                  // checks for descent stage bit, subtracts one from brightness
-      rval = rval - 1;
-    }
-
-    if (rval >= maxb){                               // sets red bit to 2 meaning negative alternation
-      rgo = 2;
-    }
-
-    if (rval == 0 && rgo == 2){                     // when counter runs out and go bit is 2, reset everything.
-      rgo = 0;
-      rval = 0;
-    }
-
-    // ---------------------------------------------// Write Blue
-
-    if (bgo == 1){                                  // checks for ascent stage bit, adds one to blue brightness
-      bval = bval + 1;
-    }
-
-    if (bgo == 2){                                  // checks for descent stage bit, subtracts one from brightness
-      bval = bval - 1;
-    }
-
-    if (bval >= maxb){
-      bgo = 2;
-    }
-
-    if (bval == 0 && bgo == 2){
-      bgo = 0;
-      bval = 0;
-    }
-
-    // ---------------------------------------------// Write Green
-
-    if (ggo == 1){                                  // checks for ascent stage bit, adds one to green brightness
-      gval = gval + 1;
-    }
-
-    if (ggo == 2){                                  // checks for descent stage bit, subtracts one from brightness
-      gval = gval - 1;
-    }
-
-    if (gval >= maxb){
-      ggo = 2;
-    }
-
-    if (gval == 0 && ggo == 2){
-      ggo = 0;
-      gval = 0;
-    }
-
-
-
-
-    for(int i=LOWPIXELS;i<NUMPIXELS;i++){
-        pixels.setPixelColor(i, pixels.Color(rval,gval,bval));
-    }
-
-
-}
-
-void shimmer() {                                    //-----------------------------------------------(Shimmer Function)
-
-
-     randosparkle = random(0,(NUMPIXELS*10));                   //picks a random number
-
-
-
-    for (int i=0; i <= (NUMPIXELS-1); i++){                     //For loop to check random number against magic numbers and set the pixel for activation
-      if (PixRay[i][5] == randosparkle && PixRay[i][0] == 0){
-        PixRay[i][0] = 1;
-        PixRay[i][1] = random(0,3);
-      }
-    }
-
-//    unsigned int tnow = millis();
-
- //   if((tnow - previousMillis) >= interval[) {
-      for (int i=0; i <= (NUMPIXELS-1); i++){                     //For loop to activate a pixel
-          if (PixRay[i][0] == 1){
-              drawPixel(i);
-          }
-      }
-//      previousMillis = tnow;
-//    }
-}
-
-void drawPixel(int pixelv){              //-----------------------------------------------(Red Pixel Draw Function)
-
-
-
-    if (PixRay[pixelv][4] == 0){                      //check if counter is within envelope
-        PixRay[pixelv][2] = PixRay[pixelv][2] + 1;
-    }
-
-    if (PixRay[pixelv][4] == 1){                      //check if counter is within envelope
-        PixRay[pixelv][2] = PixRay[pixelv][2] - 1;
-    }
-
-    if (PixRay[pixelv][2] >= maxb){                    //check if counter is within second half of fade
-      PixRay[pixelv][4] = 1;
-      PixRay[pixelv][2] = maxb;
-    }
-
-    if (PixRay[pixelv][1] == 0){
-      pixels.setPixelColor(pixelv, pixels.Color(PixRay[pixelv][2],0,0));
-    }
-
-    if (PixRay[pixelv][1] == 1){
-      pixels.setPixelColor(pixelv, pixels.Color(0,PixRay[pixelv][2],0));
-    }
-
-    if (PixRay[pixelv][1] == 2){
-      pixels.setPixelColor(pixelv, pixels.Color(0,0,PixRay[pixelv][2]));
-    }
-
-
-    if (PixRay[pixelv][2] <= 0 && PixRay[pixelv][4] == 1){               //check if counter is done alternation
-       pixels.setPixelColor(pixelv, pixels.Color(0,0,0));                //turn selected pixel off
-       PixRay[pixelv][2] = 0;                                            //set brightness to zero
-       PixRay[pixelv][0] = 0;                                            //deactivate pixel activate bit
-       PixRay[pixelv][4] = 0;                                            //reset counter
-    }
-
-}
-


Fixed wrong return type of speed extractor

--- rover/rover.ino
+++ rover/rover.ino
@@ -58,8 +58,8 @@
   }
 }

-void jeepCommandInterpreter(uint8_t commandMovement, uint8_t commandSpeed) {
-  int vPower = motorProtection(commandSpeed);
+void jeepCommandInterpreter(uint8_t commandMovement, unsigned int commandSpeed) {
+  unsigned int vPower = motorProtection(commandSpeed);
   Serial.print("Required power: ");Serial.println(vPower);

   switch(commandMovement) {
@@ -138,7 +138,7 @@
 }

 // Emergency checks
-int motorProtection(int v) {
+unsigned int motorProtection(int v) {
   if (v >= 0 && v <= MAX_POWER) {
     return v;
   } else {
@@ -187,7 +187,7 @@
   return buffer[0] - 48;
 }

-uint8_t extractSpeed() {
+unsigned int extractSpeed() {
   uint8_t speedBuffer[3] = { 45, 45, 45 };

   int i = 0;


Geiger clicks can now be toggled through VariPass.

--- Alicorn.ino
+++ Alicorn.ino
@@ -33,6 +33,8 @@

 // Default Settings
 #define DEFAULT_LCD_BACKLIGHT    1
+#define DEFAULT_SCREEN_MAIN      0
+#define DEFAULT_SCREEN_SETT      0
 #define DEFAULT_REMOTE_BEEPS     1
 #define DEFAULT_GAS_SENSOR       1
 #define DEFAULT_GEIG_CLICKS      1
@@ -41,44 +43,47 @@
 #define DEFAULT_INT_MEASURE      10000
 #define DEFAULT_INT_PUSH         60000
 #define DEFAULT_INT_PULL         1000
+#define DEFAULT_INT_SYNC         1000
 #define DEFAULT_WIFI             0
-#define DEFAULT_SCREEN_MAIN      0
-#define DEFAULT_SCREEN_SETT      0

 // MinMaxStep Settings
 #define MIN_GEIG_SENSITIVITY 100
 #define MIN_INT_MEASURE      2000
 #define MIN_INT_PUSH         1000
 #define MIN_INT_PULL         1000
+#define MIN_INT_SYNC         1000

 #define MAX_GEIG_SENSITIVITY 10000
 #define MAX_INT_MEASURE      60000
 #define MAX_INT_PUSH         60000
 #define MAX_INT_PULL         60000
+#define MAX_INT_SYNC         60000

 #define STP_GEIG_SENSITIVITY 100
 #define STP_INT_MEASURE      1000
 #define STP_INT_PUSH         1000
 #define STP_INT_PULL         1000
+#define STP_INT_SYNC         1000

 // EEPROM Addresses
 #define EEPROM_SAVED            0
 #define EEPROM_LCD_BACKLIGHT    1
-#define EEPROM_REMOTE_BEEPS     2
-#define EEPROM_GAS_SENSOR       3
-#define EEPROM_GEIG_CLICKS      4
-#define EEPROM_GEIG_ALARM       5
-#define EEPROM_GEIG_SENSITIVITY 6
-#define EEPROM_INT_MEASURE      7
-#define EEPROM_INT_PUSH         8
-#define EEPROM_INT_PULL         9
-#define EEPROM_WIFI             10
-#define EEPROM_SCREEN_MAIN      11
-#define EEPROM_SCREEN_SETT      12
+#define EEPROM_SCREEN_MAIN      2
+#define EEPROM_SCREEN_SETT      3
+#define EEPROM_REMOTE_BEEPS     4
+#define EEPROM_GAS_SENSOR       5
+#define EEPROM_GEIG_CLICKS      6
+#define EEPROM_GEIG_ALARM       7
+#define EEPROM_GEIG_SENSITIVITY 8
+#define EEPROM_INT_MEASURE      9
+#define EEPROM_INT_PUSH         10
+#define EEPROM_INT_PULL         11
+#define EEPROM_INT_SYNC         12
+#define EEPROM_WIFI             13

 // Screens
 #define SCREENS_MAIN 7
-#define SCREENS_SETT 10
+#define SCREENS_SETT 11

 // Main Screens
 #define SCREEN_MAIN_TIME      0
@@ -98,8 +103,9 @@
 #define SCREEN_SETT_INT_MEASURE      5
 #define SCREEN_SETT_INT_PUSH         6
 #define SCREEN_SETT_INT_PULL         7
-#define SCREEN_SETT_WIFI             8
-#define SCREEN_SETT_TIME             9
+#define SCREEN_SETT_INT_SYNC         8
+#define SCREEN_SETT_WIFI             9
+#define SCREEN_SETT_TIME             10

 // Intervals
@@ -174,6 +180,8 @@
 // Structures
 struct SETTINGS {
     bool lcdBacklight;
+    int  screenMain;
+    int  screenSett;
     bool remoteBeeps;
     bool gasSensor;
     bool geigerClicks;
@@ -183,15 +191,15 @@
     long intervalGeiger;
     int  intervalPush;
     int  intervalPull;
+    int  intervalSync;
     int  wifi;
-    int  screenMain;
-    int  screenSett;
 } settings;

 struct STATES {
     bool screenSettings;
     bool alarm;
     bool alarmOn;
+    bool pushSync;
     int  wifi;
 } states;

@@ -201,6 +209,7 @@
     int cclock;
     int push;
     int pull;
+    int sync;
     int lcd;
 } counters;

@@ -210,6 +219,7 @@
     bool cclock;
     bool push;
     bool pull;
+    bool sync;
     bool lcd;
 } intervals;

@@ -274,11 +284,13 @@
 void processClock();
 void processPush();
 void processPull();
+void processSync();
 void processLCD();

 // VariPass
 void pullVariPass();
 void pushVariPass();
+void syncVariPass();

 // Remote
 void screenPrev();
@@ -453,6 +465,8 @@
     }
     else {
         settings.lcdBacklight      = DEFAULT_LCD_BACKLIGHT;
+        settings.screenMain        = DEFAULT_SCREEN_MAIN;
+        settings.screenSett        = DEFAULT_SCREEN_SETT;
         settings.remoteBeeps       = DEFAULT_REMOTE_BEEPS;
         settings.gasSensor         = DEFAULT_GAS_SENSOR;
         settings.geigerClicks      = DEFAULT_GEIG_CLICKS;
@@ -461,9 +475,8 @@
         settings.intervalMeasure   = DEFAULT_INT_MEASURE;
         settings.intervalPush      = DEFAULT_INT_PUSH;
         settings.intervalPull      = DEFAULT_INT_PULL;
+        settings.intervalSync      = DEFAULT_INT_SYNC;
         settings.wifi              = DEFAULT_WIFI;
-        settings.screenMain        = DEFAULT_SCREEN_MAIN;
-        settings.screenSett        = DEFAULT_SCREEN_SETT;

         Serial.println("\nCreated new settings. Saving...");
         saveSettings();
@@ -483,6 +496,7 @@
     counters.measure = 0;
     counters.push    = 0;
     counters.pull    = 0;
+    counters.sync    = 0;
 }

 void setupWiFi() {
@@ -528,6 +542,8 @@
     EEPROM.begin(512);
     EEPROM.write(EEPROM_SAVED,            1);
     EEPROM.write(EEPROM_LCD_BACKLIGHT,    settings.lcdBacklight);
+    EEPROM.write(EEPROM_SCREEN_MAIN,      settings.screenMain);
+    EEPROM.write(EEPROM_SCREEN_SETT,      settings.screenSett);
     EEPROM.write(EEPROM_REMOTE_BEEPS,     settings.remoteBeeps);
     EEPROM.write(EEPROM_GAS_SENSOR,       settings.gasSensor);
     EEPROM.write(EEPROM_GEIG_CLICKS,      settings.geigerClicks);
@@ -536,9 +552,8 @@
     EEPROM.write(EEPROM_INT_MEASURE,      settings.intervalMeasure   / 1000);
     EEPROM.write(EEPROM_INT_PUSH,         settings.intervalPush      / 1000);
     EEPROM.write(EEPROM_INT_PULL,         settings.intervalPull      / 1000);
+    EEPROM.write(EEPROM_INT_SYNC,         settings.intervalSync      / 1000);
     EEPROM.write(EEPROM_WIFI,             settings.wifi);
-    EEPROM.write(EEPROM_SCREEN_MAIN,      settings.screenMain);
-    EEPROM.write(EEPROM_SCREEN_SETT,      settings.screenSett);
     EEPROM.end();
     Serial.println("Saved settings to EEPROM.");
 }
@@ -546,6 +561,8 @@
 void loadSettings() {
     EEPROM.begin(512);
     settings.lcdBacklight      = (bool) EEPROM.read(EEPROM_LCD_BACKLIGHT);
+    settings.screenMain        = (int)  EEPROM.read(EEPROM_SCREEN_MAIN);
+    settings.screenSett        = (int)  EEPROM.read(EEPROM_SCREEN_SETT);
     settings.remoteBeeps       = (bool) EEPROM.read(EEPROM_REMOTE_BEEPS);
     settings.gasSensor         = (bool) EEPROM.read(EEPROM_GAS_SENSOR);
     settings.geigerClicks      = (bool) EEPROM.read(EEPROM_GEIG_CLICKS);
@@ -554,9 +571,8 @@
     settings.intervalMeasure   = (int)  EEPROM.read(EEPROM_INT_MEASURE)      * 1000;
     settings.intervalPush      = (int)  EEPROM.read(EEPROM_INT_PUSH)         * 1000;
     settings.intervalPull      = (int)  EEPROM.read(EEPROM_INT_PULL)         * 1000;
+    settings.intervalSync      = (int)  EEPROM.read(EEPROM_INT_SYNC)         * 1000;
     settings.wifi              = (int)  EEPROM.read(EEPROM_WIFI);
-    settings.screenMain        = (int)  EEPROM.read(EEPROM_SCREEN_MAIN);
-    settings.screenSett        = (int)  EEPROM.read(EEPROM_SCREEN_SETT);
     EEPROM.end();
     Serial.println("Loaded settings from EEPROM.");
 }
@@ -600,6 +616,9 @@

     if (checkInterval(&counters.pull,    settings.intervalPush))
         intervals.pull    = true;
+
+    if (checkInterval(&counters.sync,    settings.intervalSync))
+        intervals.sync    = true;

     if (checkInterval(&counters.lcd,     INTERVAL_LCD))
         intervals.lcd     = true;
@@ -673,7 +692,7 @@
                     case IR_S7:       screenSet(7);    break;
                     case IR_S8:       screenSet(8);    break;
                     case IR_S9:       screenSet(9);    break;
-                    //case IR_S10:      screenSet(10);   break;
+                    case IR_S10:      screenSet(10);   break;
                     //case IR_S11:      screenSet(11);   break;
                     case IR_DECREASE: valueDecrease(); break;
                     case IR_INCREASE: valueIncrease(); break;
@@ -780,6 +799,13 @@
     }
 }

+void processSync() {
+    if (intervals.sync) {
+        intervals.sync = false;
+        syncVariPass();
+    }
+}
+
 void processLCD() {
     if (intervals.lcd) {
         intervals.lcd = false;
@@ -832,6 +858,12 @@
                     drawScreen(
                         "> Pulling Inter.",
                         "Value: " + String(settings.intervalPull / 1000) + " s"
+                    );
+                    break;
+                case SCREEN_SETT_INT_SYNC:
+                    drawScreen(
+                        "> Syncing Inter.",
+                        "Value: " + String(settings.intervalSync / 1000) + " s"
                     );
                     break;
                 case SCREEN_SETT_WIFI: {
@@ -984,6 +1016,36 @@
     resetAverage();
 }

+void syncVariPass() {
+    if (WiFi.status() == WL_CONNECTED) {
+        int result;
+
+        if (states.pushSync) {
+            Serial.println("Syncing data to VariPass...");
+            varipassWriteBool(KEY1, ID_TGL_CLICKS, settings.geigerClicks, &result);
+            if (result == VARIPASS_RESULT_SUCCESS)
+                states.pushSync = false;
+            else
+                Serial.println("An error has occured! Code: " + String(result));
+        }
+        else {
+            bool value;
+            value = varipassReadBool(KEY1, ID_TGL_CLICKS, &result);
+            if (result == VARIPASS_RESULT_SUCCESS) {
+                if (value != settings.geigerClicks) {
+                    settings.geigerClicks = value;
+                    setRelays();
+                    saveSettings();
+                    counters.lcd = 0;
+                }
+            }
+            else {
+                Serial.println("An error has occured! Code: " + String(result));
+            }
+        }
+    }
+}
+
 /* ========
  *  Remote
  * ======== */
@@ -1060,6 +1122,7 @@
             case SCREEN_SETT_GEIG_CLICKS:
                 settings.geigerClicks = !settings.geigerClicks;
                 setRelays();
+                states.pushSync = true;
                 process = true;
                 break;
             case SCREEN_SETT_GEIG_ALARM:
@@ -1088,6 +1151,12 @@
                 settings.intervalPull -= STP_INT_PULL;
                 if (settings.intervalPull < MIN_INT_PULL)
                     settings.intervalPull = MIN_INT_PULL;
+                process = true;
+                break;
+            case SCREEN_SETT_INT_SYNC:
+                settings.intervalSync -= STP_INT_SYNC;
+                if (settings.intervalSync < MIN_INT_SYNC)
+                    settings.intervalSync = MIN_INT_SYNC;
                 process = true;
                 break;
             case SCREEN_SETT_WIFI:
@@ -1121,6 +1190,7 @@
             case SCREEN_SETT_GEIG_CLICKS:
                 settings.geigerClicks = !settings.geigerClicks;
                 setRelays();
+                states.pushSync = true;
                 process = true;
                 break;
             case SCREEN_SETT_GEIG_ALARM:
@@ -1149,6 +1219,12 @@
                 settings.intervalPull += STP_INT_PULL;
                 if (settings.intervalPull > MAX_INT_PULL)
                     settings.intervalPull = MAX_INT_PULL;
+                process = true;
+                break;
+            case SCREEN_SETT_INT_SYNC:
+                settings.intervalSync += STP_INT_SYNC;
+                if (settings.intervalSync > MAX_INT_SYNC)
+                    settings.intervalSync = MAX_INT_SYNC;
                 process = true;
                 break;
             case SCREEN_SETT_WIFI:
@@ -1203,6 +1279,7 @@
     processRemote();
     processSensors();
     processGeiger();
+    processSync();
     processPush();
     if (settings.lcdBacklight) {
         processPull();


Sketch: move card halt and add delay to fight hangup

--- sketchbook/thcheckinhw/thcheckinhw.ino
+++ sketchbook/thcheckinhw/thcheckinhw.ino
@@ -196,6 +196,7 @@

   //防冲撞，返回卡的序列号 4字节
   status = MFRC522_Anticoll(str);
+  MFRC522_Halt();			//命令卡片进入休眠状态
   memcpy(serNum, str, 5);
   if (status == MI_OK) {
     cardNumber += serNum[0];
@@ -217,8 +218,7 @@
       Serial.println(announce);
     }
   }
-  MFRC522_Halt();			//命令卡片进入休眠状态
-
+  delay(10);
 }

 int askCheckInOut(int timeoutms){


Removes trailing space and updates use of BatLog in status

--- status.ino
+++ status.ino
@@ -5,36 +5,36 @@

 void status_show() {
   uint8_t ypos = 0;
-
-  dtostrf(Xadow.getBatVol(), 1, 1, _sbuf2);
+
+  dtostrf(Xadow.getBatVol(), 1, 1, _sbuf2);
   sprintf(_sbuf, "Battery: %sV", _sbuf2);
   oled.drawString(_sbuf, 0, ypos, FONT_SIZE, STATUS_COLOR);
-
-  ypos += LINE_SPACING;
+
+  ypos += LINE_HEIGHT;

   char *s;
   switch(Xadow.getChrgState()) {
       case NOCHARGE:
         s = "Not Charging";
         break;
-
+
       case CHARGING:
         s = "Charging";
         break;
-
+
       case CHARGDONE:
         s = "Done Charging";
         break;
-
+
        default:
          s = "UNKNOWN";
   }
   oled.drawString(s, 0, ypos, FONT_SIZE, STATUS_COLOR);

-  ypos += LINE_SPACING;
+  ypos += LINE_HEIGHT;

-  if (logbat) s = "Logging Battery";
+  if (BatLog.logbat) s = "Logging Battery";
   else s = "Batt log exists";

   oled.drawString(s, 0, ypos, FONT_SIZE, STATUS_COLOR);
-}
+}


Add Hand Selector

Add Hand Selector

--- Software/HandModule/HandModule.ino
+++ Software/HandModule/HandModule.ino
@@ -32,6 +32,10 @@
 #include <RF24.h>
 #include <printf.h>

+#define RIGHT_HAND  "ArS01"
+#define LEFT_HAND   "ArS02"
+#define ADDRESS     LEFT_HAND
+
 class Motor
 {
   enum MotorStatus{OFF, ON};
@@ -112,7 +116,7 @@
 void setup()
 {
   /* Initialize RF Address */
-  byte address[6] = "ArS01";
+  byte address[6] = ADDRESS;

   /* Initialize serial communication */
   Serial.begin(9600);


version mergé avec bugeeprom

version mergé avec bugeeprom

--- calibrateur.ino
+++ calibrateur.ino
@@ -36,6 +36,7 @@
 #define TEMPO_STAT 200 // tempo pour laisser le servo avancr lors des mesures statistique à la fin de la calibration
 #define ADRESSE_EEPROM 42//position de leeprom ou la valeur de reglage de l potence est stocké

+//
 enum {
 		POTAR = 3,
 		MILIEU = 4,


send analog value by bluetooth

send analog value by bluetooth

--- capteurQ/capteurQ.ino
+++ capteurQ/capteurQ.ino
@@ -33,6 +33,8 @@
 SoftwareSerial mySerial(rxPin, txPin);
 char myChar;

+int mq135value;
+

 DigitalPin PowerLed(13, false, true); // initial state is off (false), invert true = high turns led off
 DigitalPin greenLed(2, false, true);  // initial state is off (false), invert true = high turns led off
@@ -50,6 +52,7 @@

 // the loop function runs over and over again forever
 void loop() {
+  //All words typed in the console will be send - This part is only needed to test data sending
   while(mySerial.available())
   {
     myChar = mySerial.read();
@@ -64,7 +67,9 @@

   // Wait a few seconds between measurements.
   delay(5000);
-
+  mq135value = analogRead(0);
+  mySerial.print(mq135value, DEC);                 //data will be send bluetooth by myserial
+
   // power led ON to indicate we start mesuring
   PowerLed.on();
   delay(100);


git-svn-id: svn://192.168.1.10/public/Zimodem@16089 0d6f1817-ed0e-0410-87c9-987e46238f29

--- zimodem/xmodem.ino
+++ zimodem/xmodem.ino
@@ -122,29 +122,23 @@
   this->blockNo = 1;
   this->blockNoExt = 1;
   this->retries = 0;
-debugPrintf("rf0\n");
   while (1) {
     char cmd = this->dataRead(100);
-debugPrintf("rf1:%d\n",cmd);
     switch(cmd){
       case XModem::SOH:
-debugPrintf("rf2:%d\n",cmd);
         if (!this->receiveFrameNo()) {
-debugPrintf("rf2.1:%d\n",cmd);
           if (this->sendNack())
             break;
           else
             return false;
         }
         if (!this->receiveData()) {
-debugPrintf("rf2.2:%d\n",cmd);
           if (this->sendNack())
             break;
           else
             return false;
         };
         if (transfer == Crc) {
-debugPrintf("rf2.3:%d\n",cmd);
           if (!this->checkCrc()) {
             if (this->sendNack())
               break;
@@ -153,7 +147,6 @@
           }
         } else {
           if(!this->checkChkSum()) {
-debugPrintf("rf2.4:%d\n",cmd);
             if (this->sendNack())
               break;
             else
@@ -161,27 +154,22 @@
           }
         }
         //callback
-debugPrintf("rf2.5:%d\n",cmd);
         if(this->dataHandler != NULL && this->repeatedBlock == false)
           if(!this->dataHandler(this->blockNoExt, this->buffer, 128)) {
             return false;
           }
         //ack
-debugPrintf("rf2.6:%d\n",cmd);
         this->dataWrite(XModem::ACK);
         if(this->repeatedBlock == false)
         {
           this->blockNo++;
           this->blockNoExt++;
         }
-debugPrintf("rf2.9:%d\n",cmd);
         break;
       case XModem::EOT:
-debugPrintf("rf3:%d\n",cmd);
         this->dataWrite(XModem::ACK);
         return true;
       case XModem::CAN:
-debugPrintf("rf4:%d\n",cmd);
         //wait second CAN
         if(this->dataRead(XModem::receiveDelay) ==XModem::CAN)
         {
@@ -195,7 +183,6 @@
         this->dataWrite(XModem::CAN);
         return false;
       default:
-debugPrintf("rf5:%d\n",cmd);
         //something wrong
         this->dataWrite(XModem::CAN);
         this->dataWrite(XModem::CAN);


Simplify the coding. Doh!

Simplify the coding. Doh!

--- Xmas2013/rainbowBands/rainbowBands.ino
+++ Xmas2013/rainbowBands/rainbowBands.ino
@@ -53,24 +53,19 @@
     wait = 100 + random(MAX_DELAY);
   }

-  #ifdef TWO_STRINGS
-    // Get first colour
-    byte first = counter % NCOLOURS;
-    // Loop over groups
-    for (int group=0; group < NUM_GROUPS; group++) {
-      byte colour = (group + first) % NCOLOURS;
+  // Get first colour
+  byte first = counter % NCOLOURS;
+
+  // Loop over groups
+  for (int group=0; group < NUM_GROUPS; group++) {
+    byte colour = (group + first) % NCOLOURS;
+    #ifdef TWO_STRINGS
       lights1.fill_color(group*NUM_BULBS, NUM_BULBS, G35::MAX_INTENSITY, COLOURS[colour]);
       lights2.fill_color(group*NUM_BULBS, NUM_BULBS, G35::MAX_INTENSITY, COLOURS[colour]);
+    #else
+      lights.fill_color(group*NUM_BULBS, NUM_BULBS, G35::MAX_INTENSITY, COLOURS[colour]);
+    #endif
     }
-  #else
-    // Get first colour
-    byte first = counter % NCOLOURS;
-    // Loop over groups
-    for (int group=0; group < NUM_GROUPS; group++) {
-      byte colour = (group + first) % NCOLOURS;
-      lights.fill_color(group*NUM_BULBS, NUM_BULBS, G35::MAX_INTENSITY, COLOURS[colour]);
-    }
-  #endif

   // Pause
   delay(wait);


Basic TLC5947 support, channel is selected with pin number, intensity is so far fixed to 1000

--- src/Full_decoder/Full_decoder.ino
+++ src/Full_decoder/Full_decoder.ino
@@ -23,6 +23,7 @@
 #include "decoder_conf.h"
 #include "configuredpins.h"
 #include "cvaccess.h"
+#include "bus_configuredpins.h"

 decoder_conf_t EEMEM _CV = {
 #include "default_conf.h"
@@ -30,6 +31,20 @@

 #define MAX 24
 ConfiguredPin* confpins[MAX];
+
+#include "Adafruit_TLC5947.h"
+
+// How many boards do you have chained?
+#define NUM_TLC5974 1
+
+#define data   4
+#define clock   5
+#define latch   6
+#define oe  -1  // set to -1 to not use the enable pin (its optional)
+
+Adafruit_TLC5947 tlc = Adafruit_TLC5947(NUM_TLC5974, clock, data, latch);
+int channel, pwm;
+

 void enableServos();
 void disableServos();
@@ -110,6 +125,10 @@
         confpins[slot] = new DualAction(slot, pin, address, pos1, pos2, speed, pin_config);
         confpins[slot]->restore_state(eeprom_read_word((uint16_t*)&(_CV.conf[slot].servo.state)));
         break;
+      case 101: // TLC5947 PWM LED Controller.
+        pin_config = ((eeprom_read_word((uint16_t*)&(_CV.conf[slot].output.options)) & 0x01) == 0x01);
+        confpins[slot] = new TLC5947pin(&tlc, slot, pin, address, pin_config, pin, 1000);
+        break;
       default:
         confpins[slot] = new ConfiguredPin(slot, pin, address);
         break;


General FMBeacon example sketch fixups. Raised morse audio freq to match conventional 600Hz. Increased morse speed a little. Shortened test message. Lengthened interval between transmissions.

--- examples/FMBeacon/FMBeacon.ino
+++ examples/FMBeacon/FMBeacon.ino
@@ -8,8 +8,8 @@
  * power and then to your computer via USB. After uploading
  * this program to your Arduino, open the Serial Monitor to
  * monitor the status of the beacon. To test, set a HandyTalkie
- * to 438MHz. You should hear the message " KC7IBT ARDUINO
- * HAMSHIELD" in morse code.
+ * to 438MHz. You should hear the message " KC7IBT HAMSHIELD"
+ * in morse code.

  * NOTE: Radio chip audio AGC too slow in responding to tones,
  * worked around by playing a 6khz tone between actual dits/dahs.
@@ -53,8 +53,8 @@
   radio.initialize();
   radio.setRfPower(0);

-  radio.setMorseFreq(400);
-  radio.setMorseDotMillis(200);
+  radio.setMorseFreq(600);
+  radio.setMorseDotMillis(100);

   // Configure the HamShield to transmit and recieve on 446.000MHz
   radio.frequency(438000);
@@ -74,20 +74,17 @@
     radio.setModeTransmit();

     // Send a message out in morse code
-    radio.morseOut(" KC7IBT ARDUINO HAMSHIELD");
+    radio.morseOut(" KC7IBT HAMSHIELD");

     // We're done sending the message, set the radio back into recieve mode.
     radio.setModeReceive();
     Serial.println("Done.");
-
-    // Wait a second before we send our beacon again.
-    delay(1000);
   } else {
     // If we get here, the channel is busy. Let's also print out the RSSI.
     Serial.print("The channel was busy. Waiting 10 seconds. RSSI: ");
     Serial.println(radio.readRSSI());
-
-    // Wait 10 seconds and check the channel again.
-    delay(10000);
-  }
+  }
+
+  // Wait 10 seconds before we send our beacon again.
+  delay(30000);
 }


Add SAMSUNG to IRRecord.ino

Add SAMSUNG to IRRecord.ino

It wasn't included and said: "Unexpected codeType 7"

--- examples/IRrecord/IRrecord.ino
+++ examples/IRrecord/IRrecord.ino
@@ -80,6 +80,9 @@
     else if (codeType == SONY) {
       Serial.print("Received SONY: ");
     }
+    else if (codeType == SAMSUNG) {
+      Serial.print("Received SAMSUNG: ");
+    }
     else if (codeType == PANASONIC) {
       Serial.print("Received PANASONIC: ");
     }


read memory pushbuttons

read memory pushbuttons

--- vfobox.ino
+++ vfobox.ino
@@ -41,6 +41,10 @@
 #define DATAPIN 6
 #define RESET 7

+// set up memory push buttons
+#define M1Sw 8
+#define M2Sw 9
+
 const double bandStart = 100000;  // start of Gnerator at 100 KHZ
 const double bandEnd = 40000000; // End of Generator at 40 MHz --signal will be a bit flaky!
 const double bandInit = 7150000; // where to initially set the frequency for tetsting Part II
@@ -53,13 +57,21 @@
 long lastBlink = 0;
 boolean blinkState = false;

+boolean m1armed = false;
+boolean m2armed = false;
+long lastM1 = 0;
+long lastM2 = 0;
+
 // Connect via i2c, default address #1 (nothing jumpered)
 Adafruit_LiquidCrystal lcd(0);

 void setup() {
   lcd.begin(16,2);
   lcd.setCursor(0,1); // This places a display on the LCD at turn on at the 2nd line
-  lcd.print(" 5R8SV Sig Gen "); //Any LCD message can be place here. Just make sure there are 16 spaces between the "" marks
+  lcd.print(" 5R8SV Sig Gen");
+  delay(250);
+  lcd.setCursor(0,1);
+  lcd.print("              ");

   // Set up DDS
   pinMode(FQ_UD, OUTPUT);
@@ -73,6 +85,10 @@
   attachInterrupt(0, evaluateRotary, CHANGE);
   attachInterrupt(1, evaluateRotary, CHANGE);
   pinMode(RotEncSwPin, INPUT_PULLUP);
+
+  // Set up memory buttons
+  pinMode(M1Sw, INPUT_PULLUP);
+  pinMode(M2Sw, INPUT_PULLUP);

  // start up the DDS...
   pulseHigh(RESET);
@@ -128,6 +144,45 @@
     lastBlink = millis();
   }

+  // handle memory buttons
+  if(!m1armed && !digitalRead(M1Sw) && millis() - lastM1 > 50) {
+    lastM1 = millis();
+    m1armed = true;
+  }
+  if(m1armed && digitalRead(M1Sw) && millis() - lastM1 > 50) {
+    //pushed, but for how long?
+    lcd.setCursor(0,1);
+    if(millis() - lastM1 > 500) {
+    // long push = commit to memory
+    lcd.print("m1 stored");
+    } else {
+    // short push = qsy to memory frequency
+    lcd.print("recall m1");
+    }
+    m1armed = false;
+    lastM1 = millis();
+  }
+
+//yes, duplicative code, could make an array of it...
+//maybe optimize later
+
+  if(!m2armed && !digitalRead(M2Sw) && millis() - lastM2 > 50) {
+    lastM2 = millis();
+    m2armed = true;
+  }
+  if(m2armed && digitalRead(M2Sw) && millis() - lastM2 > 50) {
+    //pushed, but for how long?
+    lcd.setCursor(0,1);
+    if(millis() - lastM2 > 500) {
+    // long push = commit to memory
+    lcd.print("m2 stored");
+    } else {
+    // short push = qsy to memory frequency
+    lcd.print("recall m2");
+    }
+    m2armed = false;
+    lastM2 = millis();
+  }
 }

 // subroutine to display the frequency...


[LogToCSV] Added support for logging intervals longer than a minute or two.

--- LogToCSV/LogToCSV.ino
+++ LogToCSV/LogToCSV.ino
@@ -1,22 +1,27 @@
 /*
   Log environmental data to CSV

-  This sketch sents values temperature, humidity, CO2 and the digital filter setting to the serial port in CSV format.
-  After uploading, open the serial monitor (ctrl+shift+m) and follow instructions. The CSV data can be copied and pasted into a spreadsheet.
-  In order to keep memory and storage consumption low, but not average out extremes, the sketch polls more frequently than it logs.
-  As the log is kept in RAM, only a around 9 data points can be recorded. As opening the serial monitor resets the Arduino, logs can only be read if the computer is connected the whole logging period. Until I have a datalogger shield, it's something at least.
-  When memory is full, logs are no longer saved. Some messy last entries may show up.
+  This sketch sents values temperature, humidity, CO2 and the digital filter
+  setting to the serial port in CSV format. After uploading, open the serial
+  monitor (ctrl+shift+m) and follow instructions. The CSV data can be copied
+  and pasted into a spreadsheet. In order to keep memory and storage
+  consumption low, but not average out extremes, the sketch polls more
+  frequently than it logs. As the log is kept in RAM, only a around 9 data
+  points can be recorded. As opening the serial monitor resets the Arduino,
+  logs can only be read if the computer is connected during the whole logging
+  period. Depending on your computer, you may put it on standby. Just don't
+  reset the serial connection. When memory is full, logs are no longer saved.
+  Some messy last entries may show up.

   created 13 Feb 2015
   by Koos Looijesteijn

   This code is in the public domain.

-  Upon first use, the sensor must be calibrated. If you don't get proper readings, do this:
-  1) Upload the SetToPolling sketch - Because the library is made for polling.
-  2) Move the sensor to an area with fresh air
-  3) Upload the Calibrate sketch
-  4) Upload this sketch again.
+  Upon first use, the sensor must be calibrated. If you don't get proper
+  readings, do this: 1) Upload the SetToPolling sketch - Because the library
+  is made for polling. 2) Move the sensor to an area with fresh air 3) Upload
+  the Calibrate sketch 4) Upload this sketch again.

   For logging in Fahrenheit, just replace all instances of 'Celsius'.
 */
@@ -38,17 +43,14 @@
 COZIR czr(nss);

 // We poll more often than we log, so we can register some extremes occurring during the logging intervals without having to log huge amounts of data.
-const int LOG_INTERVAL = 60; // In seconds. This defines how much time is between each log. It's not accurate.
-const byte MEASUREMENTS_PER_LOG = 10;
-// Set measure and log intervals
-const int POLLING_INTERVAL = LOG_INTERVAL / MEASUREMENTS_PER_LOG; // In seconds. This number can stay high. It takes about 30s for big changes even to be picked up as a small difference by the sensor.
-byte pollingLoopCounter = 0;
-byte logLoopCounter = 0;
+const int LOG_INTERVAL = 60*60; // Seconds between each log.
+const byte POLLS_PER_LOG = 5; // Number of polls per logged entry.
+const int POLLING_INTERVAL = LOG_INTERVAL / POLLS_PER_LOG; // In seconds. This number can stay high. It takes about 30s for big changes even to be picked up as a small difference by the sensor.

 // Special declaration for variables that are averaged with the Average library.
-Average<float> temperatures(MEASUREMENTS_PER_LOG);
-Average<float> humidity(MEASUREMENTS_PER_LOG);
-Average<int> CO2(MEASUREMENTS_PER_LOG);
+Average<float> temperatures(POLLS_PER_LOG);
+Average<float> humidity(POLLS_PER_LOG);
+Average<int> CO2(POLLS_PER_LOG);

 // This will contain the log:
 String sLog;
@@ -58,7 +60,6 @@
 /****************************/
 void setup(){
   Serial.begin(9600); // Start communication over serial port.
-  //setSyncProvider( requestSync );  //set function to call when sync required
   Serial.println("\r\n> Please enter the current Unix time, for instance: 1420070400\r\n");// You can find the current time stamp on unixtimestamp.com
 }

@@ -66,28 +67,29 @@
  Loop
 /****************************/
 void loop(){
+  static unsigned long pollMoment;
+  static byte polls;

-  if (timeStatus() == timeSet) {
-    if ( pollingLoopCounter == POLLING_INTERVAL ){
+  if (timeStatus() == timeSet) { // Wait for time stamp before doing anything else
+    if ( millis() >= pollMoment + (unsigned long)POLLING_INTERVAL * 1000UL) { // Checking clock with millis() is more accurate than counting loops. Because the numbers can get large, they are converted to UL.
+      pollMoment = millis(); // millis() returns the number of milliseconds that passed since the processor started.
       pollData();
-      pollingLoopCounter = 0;
+      polls++;
     }
-    pollingLoopCounter++;
-    if ( logLoopCounter == LOG_INTERVAL ){
+    if ( polls == POLLS_PER_LOG ){
       logData();
-      logLoopCounter = 0;
+      polls = 0;
     }
-    logLoopCounter++;
     if (Serial.available()) {
       processSerialCommandInput();
     }
   }
-  else {
+  else {
     if (Serial.available()) {
       processDateInput();
     }
   }
-  delay(1000);
+  delay(100); // Delay prevents serial commands getting chopped up in separate characters.
 }

 /****************************
@@ -101,10 +103,12 @@
   Serial.println("- " + String(pctime) + "\r\n");
   if( pctime >= DEFAULT_TIME ){ // check the integer is a valid time (greater than Jan 1 2013)
     setTime(pctime); // Sync Arduino clock to the time received on the serial port
-    Serial.println("> Tnx, logging will start. Type 'csv' to get the log data.\r\n");
+    Serial.println("> Thanks. I believe you when you say it's " + getTimeString() +".");
+    delay(4000); // Sensor needs a couple of seconds to calibrate.
+    Serial.println("> Logging will start now.\r\n");
   }
   else{
-    Serial.println("> What?");
+    Serial.println("> Is that a time stamp?");
   }
 }
 // Process serial monitor commands
@@ -125,7 +129,7 @@
       Serial.println(sLog);
     }
     else{
-      Serial.println("> No log yet.");
+      Serial.println("> No log yet.\r\n");
     }
   }
 }
@@ -138,6 +142,10 @@
 }
 // Logging of measurements
 void logData(){
+  // Give feedback when first log is made and can be requsted.
+  if (sLog.length() == 0){
+    Serial.println("> Type 'csv' to get the log data.\r\n");
+  }
   String sTime = getTimeString();
   // Get for temperature, humidity and CO2 the lowest, average and highest measurements of the last logging interval:
   String sTemperatureMin = floatToString( temperatures.minimum() );


Smoother walking with decaseconds, but the walkers don't complete their lap...

--- countdown/countdown.ino
+++ countdown/countdown.ino
@@ -125,82 +125,31 @@
 }

 #define UPDATE_TIME 20
-#define WALKER_TIMESTEP 100
+#define WALKER_TIMESTEP 25
 uint16_t step_period = 1;
 uint8_t leds_index = 0;
 uint8_t colour_counter=0; //keep track of the remaining colours in led (100-leds_left)
 uint8_t step_counter=0; //keep track of the remaining steps of the currently-moving colour

-const CRGB moving_colours[] = {CRGB::Red, CRGB::Green, CRGB::Blue};
-
-void seed_walker(uint8_t start=0){
-  //restart the walker
-  step_period = 1;
-  leds_index = min(start,NUM_LEDS-1);
-  colour_counter = 0;
-  step_counter = 0;
-  // Initialise the white leds
-  for(uint8_t i_led=0; i_led != NUM_LEDS; ++i_led){
-    walker_leds[i_led] = (i_led>=start) ? CRGB::White : CRGB::Black;
-    walker_leds[i_led]/= 2;
-  }
-}
-
-void step_led(){
-  // First, turn off completely the led at step_counter (the light will leave this spot)
-  walker_leds[step_counter] = CRGB::Black;
-  // Re-set the step period 'countdown timer'
-  step_period = 1000/(1+leds_index);
-
-  // Then, check whether we still have steps left on the current led
-  if(step_counter==0){
-    // the current moving led has left the grid -> find a new led to move out
-    if(colour_counter==0){
-      // it was the last led for this starting position: find a new starting position
-      leds_index++;
-      colour_counter = 3; //3 colours to move out
-      // TODO: leds_index = 100 -> what to do?
-    }
-    colour_counter--;
-    step_counter = leds_index;
-    // Pause 1 step before moving out this new led
-    return;
-  }
-
-  if(step_counter==leds_index){
-    // Turn off the current colour in the current 'source' led
-    if(colour_counter==2){
-      // moved out blue
-      walker_leds[leds_index] = CRGB::Yellow;
-    } else if(colour_counter==1) {
-      // moved out green as well
-      walker_leds[leds_index] = CRGB::Red;
-    } else if(colour_counter==0){
-      walker_leds[leds_index] = CRGB::Black;
-    }
-  }
-
-  step_counter--;
-  // Light up the properly-coloured led in the current position
-  walker_leds[step_counter] = moving_colours[colour_counter];
-}
-
+const CRGB moving_colours[] = {CRGB::Blue, CRGB::Green, CRGB::Red};

 #define TOTAL_SECONDS ((uint16_t)(90*60))
 #define SECONDS_PER_LED ((uint16_t)TOTAL_SECONDS/NUM_LEDS)
 #define SECONDS_PER_COLOUR ((uint16_t) SECONDS_PER_LED/3)
-
-void draw_walker(uint16_t s){
+#define DECASECONDS_PER_LED (10*SECONDS_PER_LED)
+#define DECASECONDS_PER_COLOUR (10*SECONDS_PER_COLOUR)
+
+void draw_walker(uint16_t decasecs){
   // Draw the complete walker for the current amount of seconds left

   // 1: determine the led that is currently 'walking out'
   //    Since each led should take equal time to walk out, this is simply 100*s/T
-  uint8_t current_led = 100-(s / SECONDS_PER_LED);
+  uint8_t current_led = 100-(decasecs / DECASECONDS_PER_LED);
   // 2: determine which of the three colours is moving out
-  uint8_t secs_in_led = SECONDS_PER_LED-s%SECONDS_PER_LED;
-  uint8_t current_colour = ((uint16_t) secs_in_led * 3) / SECONDS_PER_LED;
+  uint8_t decasecs_in_led = DECASECONDS_PER_LED - decasecs % DECASECONDS_PER_LED;
+  uint8_t current_colour = ((uint16_t) decasecs_in_led * 3) / DECASECONDS_PER_LED;
   // 3: determine the position of the current colour
-  uint8_t current_pos = current_led-1 - ((secs_in_led % SECONDS_PER_COLOUR) * current_led) / SECONDS_PER_COLOUR;
+  uint8_t current_pos = current_led-1 - ((decasecs_in_led % DECASECONDS_PER_COLOUR) * current_led) / DECASECONDS_PER_COLOUR;

   // The following happens at the very end of the last led
   if(current_colour==3){
@@ -212,7 +161,7 @@
     // these are all black
     walker_leds[i_led] = CRGB::Black;
   }
-  for(uint8_t i_led= max(current_led+1,NUM_LEDS-1); i_led < NUM_LEDS; ++i_led){
+  for(uint8_t i_led= min(current_led+1,NUM_LEDS-1); i_led < NUM_LEDS; ++i_led){
     // these are white
     walker_leds[i_led] = CRGB::White;
   }
@@ -228,10 +177,9 @@
     // TODO: default case?
   }
   // Finally, the walking led
-  // TODO: if this works, reverse moving_colours and remove 2- in the index below
-  walker_leds[current_pos] = moving_colours[2-current_colour];
-
-  Serial << "s: " << s << "; led: " << current_led << "; c: " << current_colour << "; p: " << current_pos << endl;
+  walker_leds[current_pos] = moving_colours[current_colour];
+
+  Serial << "s: " << decasecs << "; led: " << current_led << "; c: " << current_colour << "; p: " << current_pos << endl;
 }

 void update(){
@@ -254,12 +202,10 @@

   LEDS.show();
   Serial.begin(57600);
-
-  seed_walker(1);
-}
-
-
-uint16_t seconds_left = TOTAL_SECONDS;
+}
+
+
+uint16_t decaseconds_left = 10*TOTAL_SECONDS/8;

 unsigned long prevStepTime = 0;
@@ -275,7 +221,7 @@
       // step_period is reset inside step_led();
       step_led();
     }*/
-    draw_walker(seconds_left--);
+    draw_walker(decaseconds_left--);
   }
   /*
   if(millis()-prevCounterTime >= 500){


Removed client.available() check.

Removed client.available() check.

--- esp8266-weather-station.ino
+++ esp8266-weather-station.ino
@@ -131,7 +131,7 @@
     // check clients for data
     for (int i = 0; i < MAX_SRV_CLIENTS; ++i)
     {
-        if (telnetClients[i] && telnetClients[i].connected() && telnetClients[i].available())
+        if (telnetClients[i] && telnetClients[i].connected())
         {
             // get data from the telnet client and push it to output
             while (telnetClients[i].available())


Update modeline to add sw=2

Update modeline to add sw=2

--- lcd_temperature_display.ino
+++ lcd_temperature_display.ino
@@ -1,4 +1,4 @@
-// vim: ts=2 et
+// vim: sw=2 ts=2 et
 /*
  *
  *  LCD Temperature Display


Allow movement buffering

Allow movement buffering


Fix for esp12e :(

Fix for esp12e :(

git-svn-id: d8bfcd070c2c81762cca1b3912331324182919ba@17198 0d6f1817-ed0e-0410-87c9-987e46238f29

--- zimodem/zimodem.ino
+++ zimodem/zimodem.ino
@@ -194,7 +194,7 @@
 #ifdef ZIMODEM_ESP32
   return DEFAULT_PIN_CTS;
 #else
-  if((ESP.getFlashChipSize()/1024)>=4096) // assume this is a striketerm/esp12e
+  if((ESP.getFlashChipRealSize()/1024)>=4096) // assume this is a striketerm/esp12e
     return DEFAULT_PIN_CTS;
   else
     return 0;
@@ -340,7 +340,7 @@
 #else
   pinSupport[0]=true;
   pinSupport[2]=true;
-  if((ESP.getFlashChipSize()/1024)>=4096) // assume this is a strykelink/esp12e
+  if((ESP.getFlashChipRealSize()/1024)>=4096) // assume this is a strykelink/esp12e
   {
     pinSupport[4]=true;
     pinSupport[5]=true;