Updated fade method to shrink it

Updated fade method to shrink it

--- SerialRGB_UNO/SerialRGB_UNO.ino
+++ SerialRGB_UNO/SerialRGB_UNO.ino
@@ -179,190 +179,43 @@
 	}
 }

-void fade(int strand, int delayVal, int brightness){
+void fade(int strand, int delayVal, int brightness) {
 	int r, g, b;
 	constrain(brightness, 1, 255);
 	while (getOut != true){
-		if (Serial.available()>0){
+		if (Serial.available() > 0){
 			getOut = true;
 			break;
 		}
-		if (strand == 1){
-
-			// fade from blue to violet
-			for (r = 0; r <= brightness; r++) {
-				analogWrite(red1, r);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-			// fade from violet to red
-			for (b = brightness; b >= 0; b--) {
-				analogWrite(blue1, b);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-			// fade from red to yellow
-			for (g = 0; g <= brightness; g++) {
-				analogWrite(green1, g);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-			// fade from yellow to green
-			for (r = brightness; r >= 0; r--) {
-				analogWrite(red1, r);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-			// fade from green to teal
-			for (b = 0; b <= brightness; b++) {
-				analogWrite(blue1, b);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-			// fade from teal to blue
-			for (g = brightness; g >= 0; g--) {
-				analogWrite(green1, g);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-		}
-		else if (strand == 2){
-
-			// fade from blue to violet
-			for (r = 0; r <= brightness; r++) {
-				analogWrite(red2, r);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-			// fade from violet to red
-			for (b = brightness; b >= 0; b--) {
-				analogWrite(blue2, b);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-			// fade from red to yellow
-			for (g = 0; g <= brightness; g++) {
-				analogWrite(green2, g);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-			// fade from yellow to green
-			for (r = brightness; r >= 0; r--) {
-				analogWrite(red2, r);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-			// fade from green to teal
-			for (b = 0; b <= brightness; b++) {
-				analogWrite(blue2, b);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-			// fade from teal to blue
-			for (g = brightness; g >= 0; g--) {
-				analogWrite(green2, g);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-		}
-		else if (strand == 3){
-
-			// fade from blue to violet
-			for (r = 0; r <= brightness; r++) {
-				analogWrite(red1, r);
-				analogWrite(red2, r);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-			// fade from violet to red
-			for (b = brightness; b >= 0; b--) {
-				analogWrite(blue1, b);
-				analogWrite(blue2, b);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-			// fade from red to yellow
-			for (g = 0; g <= brightness; g++) {
-				analogWrite(green1, g);
-				analogWrite(green2, g);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-			// fade from yellow to green
-			for (r = brightness; r >= 0; r--) {
-				analogWrite(red1, r);
-				analogWrite(red2, r);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-			// fade from green to teal
-			for (b = 0; b <= brightness; b++) {
-				analogWrite(blue1, b);
-				analogWrite(blue2, b);
-				delay(delayVal);
-			}
-			if (Serial.available()>0){
-				getOut = true;
-				break;
-			}
-			// fade from teal to blue
-			for (g = brightness; g >= 0; g--) {
-				analogWrite(green1, g);
-				analogWrite(green2, g);
-				delay(delayVal);
-			}
-		}
-		if (Serial.available()>0){
-			getOut = true;
-			break;
-		}
-	}
-}
+		// blue to violet
+		for (r = 0; r <= brightness; r++) {
+			setColor(strand, r, g, b);
+			delay(delayVal);
+		}
+		// violet to red
+		for (b = brightness; b >= 0; b--) {
+			setColor(strand, r, g, b);
+			delay(delayVal);
+		}
+		// red to yellow
+		for (g = 0; g <= brightness; g++) {
+			setColor(strand, r, g, b);
+			delay(delayVal);
+		}
+		// yellow to green
+		for (r = brightness; r >= 0; r--) {
+			setColor(strand, r, g, b);
+			delay(delayVal);
+		}
+		// green to teal
+		for (b = 0; b <= brightness; b++) {
+			setColor(strand, r, g, b);
+			delay(delayVal);
+		}
+		// teal to blue
+		for (g = brightness; g >= 0; g--) {
+			setColor(strand, r, g, b);
+			delay(delayVal);
+		}
+	}
+}


Added pixels to the receive test

Added pixels to the receive test

--- HMTL_Modules/HMTL_Recv_Test/HMTL_Recv_Test.ino
+++ HMTL_Modules/HMTL_Recv_Test/HMTL_Recv_Test.ino
@@ -18,18 +18,40 @@
 #include "RS485Utils.h"
 #include "MPR121.h"

-#define PIN_RS485_1  2 // 2 on board v1, 4 on board v2
-#define PIN_RS485_2  7
-#define PIN_RS485_3  4 // 4 on board v1, 5 on board v2
+#define HMTL_VERSION 1

-#define RED_LED      9 // 10 on board v2
-#define GREEN_LED   10 // 11 on board v2
-#define BLUE_LED    11 // 13 on board v2
+#if HMTL_VERSION == 1
+  #define RED_LED      9
+  #define GREEN_LED   10
+  #define BLUE_LED    11
+
+  #define PIN_RS485_1  2
+  #define PIN_RS485_2  7
+  #define PIN_RS485_3  4

-#define RCV_LED     13 // Only three LEDs on v2
+  #define PIN_PIXEL_DATA 12
+  #define PIN_PIXEL_CLOCK 8
+
+  #define RCV_LED     13 // Only three LEDs on v2
+#elif HMTL_VERSION == 2
+  #define RED_LED     10
+  #define GREEN_LED   11
+  #define BLUE_LED    13
+
+  #define PIN_RS485_1  4
+  #define PIN_RS485_2  7
+  #define PIN_RS485_3  5
+#endif
+
+#define PIXELS
+#ifdef PIXELS
+  Adafruit_WS2801 strip = Adafruit_WS2801(105, PIN_PIXEL_DATA, PIN_PIXEL_CLOCK);
+#else
+  #define OUTPIN_1     8
+  #define OUTPIN_2    12
+#endif

 #define MY_ADDR   0x01 // Socket receive address
-

 RS485Socket rs485(PIN_RS485_1, PIN_RS485_2, PIN_RS485_3, (DEBUG_LEVEL != 0));

@@ -39,13 +61,27 @@
   pinMode(RED_LED, OUTPUT);
   pinMode(GREEN_LED, OUTPUT);
   pinMode(BLUE_LED, OUTPUT);
+
+#ifdef RCV_LED
   pinMode(RCV_LED, OUTPUT);
+#endif
+
+#ifdef PIXELS
+  strip.begin();
+  for (int i = 0; i < strip.numPixels(); i++) {
+    strip.setPixelColor(i, 0);
+  }
+  strip.show();
+#else
+  pinMode(OUTPIN_1, OUTPUT);
+#endif

   /* Setup the RS485 connection */
   rs485.setup();

-  DEBUG_PRINTLN(DEBUG_LOW, "RS485 socket initialized");
+  DEBUG_VALUELN(DEBUG_LOW, "RS485 socket initialized. address=", MY_ADDR);
 }
+

 void loop() {
   unsigned int msglen;
@@ -53,34 +89,65 @@
   const byte *data = rs485.getMsg(MY_ADDR, &msglen);
   if (data != NULL) {
     int value = (data[0] << 8) | data[1];
-    DEBUG_VALUELN(0, "value=", value);
+    DEBUG_HEXVALLN(0, "value=", value);
+#ifdef RCV_LED
     digitalWrite(RCV_LED, HIGH);
+#endif
     if (value == 0) {
       DEBUG_PRINTLN(0, "Recieved reset");
       digitalWrite(RED_LED, LOW);
       digitalWrite(GREEN_LED, LOW);
       digitalWrite(BLUE_LED, LOW);
+#ifdef PIXELS
+      setAllPixels(0, 0, 0);
+#else
+      digitalWrite(OUTPIN_1, LOW);
+#endif
     } else {
       switch (value % 3) {
       case 0:
 	digitalWrite(RED_LED, HIGH);
 	digitalWrite(GREEN_LED, LOW);
 	digitalWrite(BLUE_LED, LOW);
+#ifdef PIXELS
+	setAllPixels(255, 0, 0);
+#else
+	digitalWrite(OUTPIN_1, HIGH);
+#endif
 	break;
       case 1:
 	digitalWrite(RED_LED, LOW);
 	digitalWrite(GREEN_LED, HIGH);
 	digitalWrite(BLUE_LED, LOW);
+#ifdef PIXELS
+	setAllPixels(0, 255, 0);
+#endif
 	break;
       case 2:
 	digitalWrite(RED_LED, LOW);
 	digitalWrite(GREEN_LED, LOW);
 	digitalWrite(BLUE_LED, HIGH);
+#ifdef PIXELS
+	setAllPixels(0, 0, 255);
+#endif
 	break;
       }
     }
+#ifdef PIXELS
+    strip.show();
+#endif
   } else {
     delay(20);
+#ifdef RCV_LED
     digitalWrite(RCV_LED, LOW);
+#endif
   }
 }
+
+#ifdef PIXELS
+void setAllPixels(byte r, byte g, byte b) {
+  for (unsigned int i=0; i < strip.numPixels(); i++)
+    strip.setPixelColor(i, r, g, b);
+  strip.show();
+}
+#endif


tidyup

tidyup

--- V0p2_Main/V0p2_Main.ino
+++ V0p2_Main/V0p2_Main.ino
@@ -155,7 +155,7 @@
   '\0'
   };
 // Version (code/board) information printed as one line to serial (with line-end, and flushed); machine- and human- parseable.
-// Format: "board VXXXX REVY; YYYY/Mmm/DD HH:MM:SS".
+// Format: "board VX.X REVY YYYY/Mmm/DD HH:MM:SS".
 void serialPrintlnBuildVersion()
   {
   OTV0P2BASE::serialPrintAndFlush(F("board V0.2 REV"));


end json with newline

end json with newline

--- Wikiduino/Wikiduino.ino
+++ Wikiduino/Wikiduino.ino
@@ -289,6 +289,7 @@
       sa();
       ea();
   eh();
+  n(F(""));
 }

 void errorReport () {


Edited comments

Edited comments

--- watermeter/watermeter.ino
+++ watermeter/watermeter.ino
@@ -124,7 +124,7 @@
 /* Counter of water for interrupts */
 volatile unsigned long counterHotWater, counterColdWater;

-/* Timer for debounce */
+/* Timers for debounce */
 os_timer_t hotTimer;
 os_timer_t coldTimer;


Fixed key press scan error in 2nd part key matrix ( Pin30~37 )

--- arduino/CVP_JoystickController/CVP_JoystickController.ino
+++ arduino/CVP_JoystickController/CVP_JoystickController.ino
@@ -1,7 +1,3 @@
-/* Arduino USB Joystick HID demo */
-/* Author: Darran Hunt,
-*/
-
 /*
 Mega2560 R3, digitalPin 22~ 37 used as row0 ~ row 15,
 digital pin 38~53 used as column 0 ~ 15,
@@ -97,7 +93,7 @@
 // Send an HID report to the USB interface
 void sendJoyReport(struct joyReport_t *report)
 {
-	//check if time has elapsed more then 5mS since last report sent.
+	//check if time has elapsed enough time since last report sent.
 	long static prevMillis;
 	if ( millis() - prevMillis >= 10 )
 	{
@@ -111,8 +107,6 @@
 		prevMillis = millis();
 	}
 }
-
-char oldMsg[10];

 void loop()
 {
@@ -120,55 +114,61 @@
 	//loopTime = millis();

 	//scan rotary encoder
+
+	PORTC = 0xFF;
 	for ( int rowid = 0; rowid < 4; rowid ++ )
 	{
-		//turn off all rows first
-		PORTA = 0xFF;  PORTC = 0xFF;
 		//turn on the current row
-		PORTA &= ~(0x1 << rowid);
+		PORTA = ~( B00000001 << rowid);
+
+		//we must have such a delay so the digital pin output can go LOW steadily,
+		//without this delay, the row PIN will not 100% at LOW during yet,
+		//so check the first column pin's value will return incorrect result.
+		delayMicroseconds(3);

 		byte colResult[16];

-		//	//pin 38, PD7
-		//	colResult[0] = (PIND & B10000000 )== 0 ? 1 : 0;
-		//	//pin 39, PG2
-		//	colResult[1] = (PING & B00000100 )== 0 ? 1 : 0;
-		//	//pin 40, PG1
-		//	colResult[2] = (PING & B00000010 )== 0 ? 1 : 0;
-		//	//pin 41, PG0
-		//	colResult[3] = (PING & B00000001 )== 0 ? 1 : 0;
-
-		//	//pin 42, PL7
-		//	colResult[4] = (PINL & B10000000 )== 0 ? 1 : 0;
-		//	//pin 43, PL6
-		//	colResult[5] = (PINL & B01000000 )== 0 ? 1 : 0;
-		//	//pin 44, PL5
-		//	colResult[6] = (PINL & B00100000 )== 0 ? 1 : 0;
-		//	//pin 45, PL4
-		//	colResult[7] = (PINL & B00010000 )== 0 ? 1 : 0;
-
-		//	//pin 46, PL3
-		//	colResult[8] = (PINL & B00001000 )== 0 ? 1 : 0;
-		//	//pin 47, PL2
-		//	colResult[9] = (PINL & B00000100 )== 0 ? 1 : 0;
-		//	//pin 48, PL1
-		//	colResult[10] =( PINL & B00000010)== 0 ? 1 : 0;
-		//	//pin 49, PL0
-		//	colResult[11] =( PINL & B00000001)== 0 ? 1 : 0;
-
-		//	//pin 50, PB3
-		//	colResult[12] =( PINB & B00001000)== 0 ? 1 : 0;
-		//	//pin 51, PB2
-		//	colResult[13] =( PINB & B00000100)== 0 ? 1 : 0;
-		//	//pin 52, PB1
-		//	colResult[14] =( PINB & B00000010)== 0 ? 1 : 0;
-		//	//pin 53, PB0
-		//	colResult[15] =( PINB & B00000001)== 0 ? 1 : 0;
+			//pin 38, PD7
+			colResult[0] = (PIND & B10000000 )== 0 ? 1 : 0;
+			//pin 39, PG2
+			colResult[1] = (PING & B00000100 )== 0 ? 1 : 0;
+			//pin 40, PG1
+			colResult[2] = (PING & B00000010 )== 0 ? 1 : 0;
+			//pin 41, PG0
+			colResult[3] = (PING & B00000001 )== 0 ? 1 : 0;
+
+			//pin 42, PL7
+			colResult[4] = (PINL & B10000000 )== 0 ? 1 : 0;
+			//pin 43, PL6
+			colResult[5] = (PINL & B01000000 )== 0 ? 1 : 0;
+			//pin 44, PL5
+			colResult[6] = (PINL & B00100000 )== 0 ? 1 : 0;
+			//pin 45, PL4
+			colResult[7] = (PINL & B00010000 )== 0 ? 1 : 0;
+
+			//pin 46, PL3
+			colResult[8] = (PINL & B00001000 )== 0 ? 1 : 0;
+			//pin 47, PL2
+			colResult[9] = (PINL & B00000100 )== 0 ? 1 : 0;
+			//pin 48, PL1
+			colResult[10] =( PINL & B00000010)== 0 ? 1 : 0;
+			//pin 49, PL0
+			colResult[11] =( PINL & B00000001)== 0 ? 1 : 0;
+
+			//pin 50, PB3
+			colResult[12] =( PINB & B00001000)== 0 ? 1 : 0;
+			//pin 51, PB2
+			colResult[13] =( PINB & B00000100)== 0 ? 1 : 0;
+			//pin 52, PB1
+			colResult[14] =( PINB & B00000010)== 0 ? 1 : 0;
+			//pin 53, PB0
+			colResult[15] =( PINB & B00000001)== 0 ? 1 : 0;
+

 		for ( int colid = 0; colid < 16; colid += 2 )
 		{
-			//byte encoderValue = colResult[colid] << 1 | colResult[colid + 1];
-			byte encoderValue = digitalRead(colid+38) << 1 | digitalRead(colid + 39);
+			byte encoderValue = colResult[colid] << 1 | colResult[colid + 1];
+			//byte encoderValue = digitalRead(colid+38) << 1 | digitalRead(colid + 39);
 			byte encoderId = rowid * 8 + colid / 2;
 			//int encoderState = encoderTable[ prevEncoderValue[ encoderId ] << 2 | encoderValue ];

@@ -224,20 +224,23 @@
 		}
 	}

+	//turn off all rows first
 	for ( int rowid = 4; rowid < 16; rowid ++ )
 	{
-		//turn off all rows first
-		PORTA = 0xFF;  PORTC = 0xFF;
 		//turn on the current row
 		if (rowid < 8)
 		{
-			PORTA &= ~(0x1 << rowid);
+			PORTA = ~(0x1 << rowid);
 		}
 		else
 		{
-			PORTC &= ~(0x1 << (16 - rowid) );
-		}
-		//digitalWrite( rowid + 22, LOW );
+			PORTC = ~(0x1 << (15 - rowid) );
+		}
+		//we must have such a delay so the digital pin output can go LOW steadily,
+		//without this delay, the row PIN will not 100% at LOW during yet,
+		//so check the first column pin's value will return incorrect result.
+		delayMicroseconds(3);
+
 		byte colResult[16];
 		//pin 38, PD7
 		colResult[0] = (PIND & B10000000)== 0 ? 1 : 0;
@@ -278,7 +281,7 @@
 		for ( int colid = 0; colid < 16; colid ++ )
 		{
 			if ( colResult[ colid ] == 1 )
-				//if ( digitalRead( colid + 38 ) == HIGH )
+			//if ( digitalRead( colid + 38 ) == LOW )
 			{
 				joyReport.button[ rowid * 2 + colid / 8 ] |= (0x1 << ( colid % 8 ));
 			}
@@ -289,7 +292,6 @@
 		}
 	}

-	/* Move all of the axes */
 	for (uint8_t ind=0; ind< NUM_AXES; ind++) {
 		//joyReport.axis[ind] = map(analogRead(54+ind), 0, 1023, -32768,32767 );
 	}


Switch functions to zero-indexed

Switch functions to zero-indexed

--- Guzheng/Guzheng.ino
+++ Guzheng/Guzheng.ino
@@ -7,7 +7,8 @@
 /* Uncomment the define if you are using a wind instrument, such
  * as a trumpet or flute. It will disable several things that
  * are specific to string and percussion instruments. DO NOT
- * uncomment it if you are using a piano or string instrument! */
+ * uncomment it if you are using a piano or string instrument!
+ */
 // #define WIND

 // Port I/O defines
@@ -73,28 +74,28 @@
 // Function for playing note based on ID
 void musicOn(int ID) {
   switch (ID) {
-  case 1:
+  case 0:
     noteOn(NOTEON, note1, VOLUME);
     break;
-  case 2:
+  case 1:
     noteOn(NOTEON, note2, VOLUME);
     break;
-  case 3:
+  case 2:
     noteOn(NOTEON, note3, VOLUME);
     break;
-  case 4:
+  case 3:
     noteOn(NOTEON, note4, VOLUME);
     break;
-  case 5:
+  case 4:
     noteOn(NOTEON, note5, VOLUME);
     break;
-  case 6:
+  case 5:
     noteOn(NOTEON, note6, VOLUME);
     break;
-  case 7:
+  case 6:
     noteOn(NOTEON, note7, VOLUME);
     break;
-  case 8:
+  case 7:
     noteOn(NOTEON, note8, VOLUME);
     break;
   default:
@@ -107,28 +108,28 @@
 // Just a slightly modified version of musicOn()
 void musicOff(int ID) {
   switch (ID) {
-  case 1:
+  case 0:
     noteOn(NOTEOFF, note1, 0x7F);
     break;
-  case 2:
+  case 1:
     noteOn(NOTEOFF, note2, 0x7F);
     break;
-  case 3:
+  case 2:
     noteOn(NOTEOFF, note3, 0x7F);
     break;
-  case 4:
+  case 3:
     noteOn(NOTEOFF, note4, 0x7F);
     break;
-  case 5:
+  case 4:
     noteOn(NOTEOFF, note5, 0x7F);
     break;
-  case 6:
+  case 5:
     noteOn(NOTEOFF, note6, 0x7F);
     break;
-  case 7:
+  case 6:
     noteOn(NOTEOFF, note7, 0x7F);
     break;
-  case 8:
+  case 7:
     noteOn(NOTEOFF, note8, 0x7F);
     break;
   default:
@@ -148,7 +149,7 @@
 #endif
         // Beam has been cut
         // i+1 is because i is 0 indexed, but the ID starts with 1
-        musicOn(i + 1);
+        musicOn(i);
 #ifndef WIND
         lastNote |= (laserArray[i]);
       }
@@ -160,7 +161,7 @@
       }
 #endif
       // Hand is gone. Stop the sound
-      musicOff(i + 1);
+      musicOff(i);
     }
     // Delay 10 to prevent weird analog readings
     delay(DELAY);


roulettfunction implemented

roulettfunction implemented

--- HumanRoulette.ino
+++ HumanRoulette.ino
@@ -19,13 +19,14 @@

 char sendStrings[4][13] = {
   "FFFFFFFF0rgb",
-  "FFFFFFFF0rgb",
-  "FFFFFFFF0rgb",
-  "FFFFFFFF0rgb"
+  "1FFFFFFF0rgb",
+  "F1FFFFFF0rgb",
+  "FF1FFFFF0rgb"
 };

+int winningHat;
 unsigned long lastTime = 0;
-Roulette_Step currentStep = Waiting;
+Roulette_Step currentStep = Start;

 void setup() {

@@ -34,6 +35,7 @@
   // while the serial stream is not open, do nothing:
   while (!Serial)
     ;
+

   Serial.println("----- Setup -----");
   Serial.print("Transmit pin: ");
@@ -71,7 +73,7 @@

   //for(int i=140; i<180; i+=2)
   {
-  //Serial.println("Sending...");
+//  Serial.println("test...");
   //Serial.println(i);
     //mySwitch.setPulseLength(i);
       //mySwitch.setPulseLength(PULSE_LENGTH);
@@ -84,7 +86,7 @@
   }

   NextStep();
-
+  delay(200);

 }

@@ -103,8 +105,11 @@
       currentStep = Waiting;
       lastTime = newTime;
       break;
+
     case Waiting:
-      if(elapsedTime > 15000)
+      Serial.print("Waiting......elapsed: ");
+      Serial.println(elapsedTime);
+      if(elapsedTime > 5000)
       {
         lastTime = newTime;
         currentStep = SendingRed;
@@ -112,36 +117,46 @@
       break;

     case SendingRed:
+      Serial.print("Red......elapsed: ");
+      Serial.println(elapsedTime);
       if(elapsedTime > 1000)
       {
         if(Step_Sending(true, false, false))
         {
-          lastTime = newTime;
           currentStep = SendingGreen;
         }
+        lastTime = newTime;
       }
       break;
     case SendingGreen:
+      Serial.print("Green......elapsed: ");
+      Serial.println(elapsedTime);
       if(elapsedTime > 1000)
       {
         if(Step_Sending(false, true, false))
         {
-          lastTime = newTime;
           currentStep = SendingBlue;
         }
+      lastTime = newTime;
       }
       break;
     case SendingBlue:
+      Serial.print("Blue......elapsed: ");
+      Serial.println(elapsedTime);
       if(elapsedTime > 1000)
       {
         if(Step_Sending(false, false, true))
         {
-          lastTime = newTime;
           currentStep = ShowResult;
+          winningHat = random(0,3);
         }
+        lastTime = newTime;
       }
       break;
     case ShowResult:
+      Serial.println("Finished");
+      lastTime = newTime;
+      currentStep = Start;
       break;
   }
 }
@@ -159,8 +174,11 @@
       SetColor(i, false, false, false);
   }

+  Send();
+
   hat++;
-
+  Serial.print("Hat: ");
+  Serial.println(hat);
   if(hat>3)
   {
     hat = 0;
@@ -177,14 +195,14 @@
     case 0:
     case 1:
     case 2:
-      sendStrings[hatNo][10] = red ? '1' : '0';
-      sendStrings[hatNo][11] = green ? '1' : '0';
-      sendStrings[hatNo][12] = blue ? '1' : '0';
+      sendStrings[hatNo][9] = red ? '1' : '0';
+      sendStrings[hatNo][10] = green ? '1' : '0';
+      sendStrings[hatNo][11] = blue ? '1' : '0';
       break;
     case 3:
-      sendStrings[hatNo][10] = red ? '1' : '0';
-      sendStrings[hatNo][11] = green ? '1' : '0';
-      sendStrings[hatNo][12] = blue ? '1' : '0';
+      sendStrings[hatNo][9] = red ? '1' : '0';
+      sendStrings[hatNo][10] = green ? '1' : '0';
+      sendStrings[hatNo][11] = blue ? '1' : '0';
       break;
   }
 }
@@ -197,7 +215,8 @@
     Serial.print("Sending: ");
     Serial.println(sendStrings[i]);

-//    mySwitch.sendTriState("FFFFFFFF1111");
-  }
-
-}
+    mySwitch.sendTriState(sendStrings[i]);
+    delay(100);
+  }
+
+}


v4.0 Add mode to displayFileName

v4.0 Add mode to displayFileName

--- PictureViewer.ino
+++ PictureViewer.ino
@@ -357,8 +357,21 @@
   lastRandomNumber = randomColor;
   tft.setTextWrap(false);
   tft.fillScreen(ST7735_BLACK);
+  tft.setTextColor(textColor[randomColor]);
+  tft.setTextSize(1);
+  if (digitalRead(TEST_PIN)) {
+    tft.setCursor(50, 0);
+    tft.println("Test");
+  }
+  else if (digitalRead(MODE_PIN)) {
+    tft.setCursor(40, 0);
+    tft.println("Random");
+  }
+  else {
+    tft.setCursor(30, 0);
+    tft.println("Sequential");
+  }
   tft.setCursor(0, 50);
-  tft.setTextColor(textColor[randomColor]);
   tft.setTextSize(2);
   tft.println("File Name:");
   tft.setCursor(10, 80);


Stop the song on reset, make sure song can play again

--- Pingduino/Pingduino.ino
+++ Pingduino/Pingduino.ino
@@ -74,26 +74,25 @@
     return;
   }

+  _initialized = true;
+}
+
+void VictorySong::play()
+{
+  if (!_initialized)
+    return;
+
+  _played = true;
+
+  // Grab the first wav file and play it
+  FatReader file;
+
   if (!root.openRoot(vol)) {
     Serial.println("Can't open root directory");
-    _initialized = false;
-    return;
-  }
-  _initialized = true;
-}
-
-void VictorySong::play()
-{
-  if (!_initialized)
-    return;
-
-  _played = true;
-
-  // Grab the first wav file and play it
-  FatReader file;
+    return;
+  }
+
   while (root.readDir(dirBuf) > 0) {
-    Serial.println(*dirBuf.name);
-
     if (dirBuf.name[0] == '.')
       continue;

@@ -108,8 +107,7 @@
         while(wave.isplaying) {
           delay(100);
         }
-      } else {
-        Serial.println("Failed to create wav");
+        return;
       }
     }
   }
@@ -118,6 +116,7 @@
 void VictorySong::stop()
 {
   _stop = true;
+  wave.stop();
 }

 bool VictorySong::played() { return _played; }
@@ -179,9 +178,11 @@
     unsigned long now = millis();
     if ((now - p1ButtonChangeMillis) <= LONGPRESS_TIME) {
       // Short press, score
+      Serial.println("Score p1");
       p1Score++;
     } else {
       // Long press, reset
+      Serial.println("Reset p1");
       victorySong.stop();
       requestReset = 1;
     }


Another version.

Another version.

--- linefollow/linefollow.ino
+++ linefollow/linefollow.ino
@@ -1,21 +1,6 @@

 /***********************************************************************
  * Adapted from Exp6_2_LineFollowing_IRSensors -- RedBot Experiment 6
- *
- * This code reads the three line following sensors on A3, A6, and A7
- * and prints them out to the Serial Monitor. Upload this example to your
- * RedBot and open up the Serial Monitor by clicking the magnifying glass
- * in the upper-right hand corner.
- *
- * This is a real simple example of a line following algorithm. It has
- * a lot of room for improvement, but works fairly well for a curved track.
- * It does not handle right angles reliably -- maybe you can come up with a
- * better solution?
- *
- * This sketch was written by SparkFun Electronics,with lots of help from
- * the Arduino community. This code is completely free for any use.
- *
- * 18 Reb 2015 B. Huang
  ***********************************************************************/

 #include <RedBot.h>
@@ -23,30 +8,32 @@
 RedBotSensor center = RedBotSensor(A6); // initialize a center sensor object on A6
 RedBotSensor right = RedBotSensor(A7);  // initialize a right sensor object on A7

-// constants that are used in the code. LINETHRESHOLD is the level to detect
-// if the sensor is on the line or not. If the sensor value is greater than this
-// the sensor is above a DARK line.
-//
-// SPEED sets the nominal speed
+#define SPEED 120  // sets the nominal speed. Set to any number from 0 - 255.

-//#define LINETHRESHOLD 200
-#define SPEED 120  // sets the nominal speed. Set to any number from 0 - 255.
+#define SPEED_ADJUSTMENT 30
+
+#define COUNTER_MAX 20
+
+// These thresholds are manually configured.
+#define TAPE_THRESHOLD  600 // below this value, we are looking at the tape
+#define BLUE_THRESHOLD  750 // above the TAPE_THRESHOLD and below this threshold, we are looking at blue carpet
+#define BLACK_THRESHOLD 850 // above this threshold, we are looking at black carpet
+
+#define NOT_SET 0
+#define TAPE_STATE 1
+#define NOT_TAPE_STATE 2

 RedBotMotors motors;
 int leftSpeed;   // variable used to store the leftMotor speed
 int rightSpeed;  // variable used to store the rightMotor speed

-int LINETHRESHOLD = 0;
+bool driftingRight = false;
+bool driftingLeft = false;

 void setup()
 {
   Serial.begin(9600);
-  Serial.println("Welcome to experiment 6.2 - Line Following");
-
-  Serial.println("Calibration begin");
-  calibrate();
-  Serial.println("Calibration end");
-
+  Serial.println("Line Following Startup");
   Serial.println("------------------------------------------");
   delay(2000);
   Serial.println("IR Sensor Readings: ");
@@ -55,67 +42,92 @@

 void loop()
 {
-  Serial.print(left.read());
-  Serial.print("\t");  // tab character
-  Serial.print(center.read());
-  Serial.print("\t");  // tab character
-  Serial.print(right.read());
-  Serial.println();
-
-  // if on the line drive left and right at the same speed (left is CCW / right is CW)
-  if(center.read() < LINETHRESHOLD)
-  {
-    leftSpeed = -SPEED;
-    rightSpeed = SPEED;
+  int leftReading = left.read();
+  int centerReading = center.read();
+  int rightReading = right.read();
+
+  // reset speeds to base speed
+  leftSpeed =  SPEED;
+  rightSpeed = SPEED;
+
+  // no drift
+  if((onTape(centerReading) && !onTape(leftReading) && !onTape(rightReading)) ||
+     (onTape(centerReading) && onTape(leftReading) && onTape(rightReading))) {
+    driftingLeft = false;
+    driftingRight = false;
   }

-  // if the line is under the right sensor,
-  // adjust relative speeds to turn to the right
-  else if(right.read() < LINETHRESHOLD)
+  // drifting left
+  if((onTape(rightReading) && onTape(centerReading) && !onTape(leftReading)) ||
+     (onTape(rightReading) && !onTape(centerReading) && !onTape(leftReading)))
   {
-    leftSpeed = -(SPEED + 50);
-    rightSpeed = SPEED - 50;
+    driftingLeft = true;
+    driftingRight = false;
+
+    rightSpeed -= SPEED_ADJUSTMENT;
   }

-  // if the line is under the left sensor, adjust relative speeds to turn to the left
-  else if(left.read() < LINETHRESHOLD)
+  // drift right
+  if((onTape(leftReading) && onTape(centerReading) && !onTape(rightReading)) ||
+     (onTape(leftReading) && !onTape(centerReading) && !onTape(rightReading)))
   {
-    leftSpeed = -(SPEED - 50);
-    rightSpeed = SPEED + 50;
+    driftingRight = true;
+    driftingLeft = false;
+
+    leftSpeed -= SPEED_ADJUSTMENT;
   }

-  // if all sensors are on black or up in the air, stop the motors.
-  // otherwise, run motors given the control speeds above.
-  if((left.read() < LINETHRESHOLD) &&
-     (center.read() < LINETHRESHOLD) && (right.read() < LINETHRESHOLD) )
+  // recovery
+  if(!onTape(leftReading) && !onTape(centerReading) && !onTape(rightReading))
   {
-    motors.stop();
+    if(driftingLeft) {
+      leftSpeed = SPEED;
+      rightSpeed = 70;
+    }
+    else if(driftingRight) {
+      rightSpeed = SPEED;
+      leftSpeed = 70;
+    }
   }
-  else
-  {
-    motors.leftMotor(leftSpeed);
-    motors.rightMotor(rightSpeed);
-  }
+
+  driveRightForward(rightSpeed);
+  driveLeftForward(leftSpeed);
+
   delay(0);  // add a delay to decrease sensitivity.
+
+  Serial.print(leftReading);
+  Serial.print("\t");  // tab character
+  Serial.print(centerReading);
+  Serial.print("\t");  // tab character
+  Serial.print(rightReading);
+  Serial.print("\t");
+  Serial.print("\t|\t");
+  if(driftingLeft) { Serial.print("DRIFT LEFT"); }
+  Serial.print("\t");
+  if(driftingRight) { Serial.print("DRIFT RIGHT"); }
+  Serial.print("\t");
+  Serial.print(leftSpeed);
+  Serial.print("\t");
+  Serial.print(rightSpeed);
+  Serial.println();
 }

-void calibrate () {
-  double l_accum;
-  double c_accum;
-  double r_accum;
-  double avg;
+void driveLeftForward(int speed) {
+  motors.leftMotor(-1 * speed);
+}

-  for (int i = 0; i<5000; i++){
-    l_accum += left.read();
-    c_accum += center.read();
-    r_accum += right.read();
-  }
+void driveLeftBackward(int speed) {
+  motors.leftMotor(speed);
+}

-  avg = (l_accum + c_accum + r_accum)/15000;
-  Serial.println(avg);
-  LINETHRESHOLD = avg * 1/2;
-  Serial.println(LINETHRESHOLD);
-  motors.drive(255);
-  delay(10);
-  motors.stop();
+void driveRightForward(int speed) {
+  motors.rightMotor(speed);
 }
+
+void driveRightBackward(int speed) {
+  motors.rightMotor(-1 * speed);
+}
+
+bool onTape(int sensorReading) {
+  return sensorReading < TAPE_THRESHOLD;
+}


Update Serre_menuLCD.ino

Update Serre_menuLCD.ino

Prototype v.1

--- Serre_menuLCD.ino
+++ Serre_menuLCD.ino
@@ -127,12 +127,12 @@
   //defineProgram(2, SR, 0, 20, 21);
   //defineProgram(3, CLOCK, 11, 10, 22);
   //defineProgram(4, SS, 0, -60, 28);
-  //defineProgram(5, SS, 0, -2, 18);
-
-  //defineRollup(1, 5, 1, 1, 0, 1, false);
-  //defineFan(1, 2, 1, false);
+  //defineProgram(5, SS, 0, 0, 18);
+
+  //defineRollup(1, 5, 5, 1, 0, 1, true);
+  //defineFan(1, 2, 1, true);
   //defineHeater(1, -3, 1);
-  //defineRamping(5);
+  defineRamping(10);

   initVariables();
   initOutputs();
@@ -228,7 +228,6 @@
   //Définition de la température cible
   setTempCible();
   //Définition de la température d'activation des sorties
-  //getTemperature();
 }

 void getDateAndTime(){
@@ -400,8 +399,8 @@

   if (newTempCible > tempCible){
     unsigned long rampingCounter = millis();
-    Serial.println(rampingCounter);
-    Serial.println(rampingCounter - lastCount);
+    //Serial.println(rampingCounter);
+    //Serial.println(rampingCounter - lastCount);
     if(rampingCounter - lastCount > rampingE()) {
       lastCount = rampingCounter;
       tempCible += 0.5;
@@ -543,16 +542,17 @@
     lcd.setCursor(5, 1); lcd.print(incrementCounter[0]);
  }
 void lcdPrintTemp(){
+    float temperature = greenhouseTemperature();
     lcd.setCursor(0,0); lcd.print(F("         "));
     if(failedSensor == false){
-      lcd.setCursor(0,0); lcd.print(F("T:")); lcd.print(greenhouseTemperature()); lcd.print(F("C"));
+      lcd.setCursor(0,0); lcd.print(F("T:")); lcd.print(temperature); lcd.print(F("C"));
     }
     else{
       lcd.setCursor(0,0); lcd.print(F("T:")); lcd.print("!!!"); lcd.print(F("("));lcd.print((int)greenhouseTemperature());lcd.print(F(")"));
     }
 }
 void lcdPrintTempCible(){
-    lcd.setCursor(9,0);lcd.print("|TC:");lcd.print(tempCible); lcd.print(F("C"));
+    lcd.setCursor(9,0);lcd.print("|TC:");lcd.print(tempCible); lcd.print(F("C "));
 }
 void lcdPrintTime(){
     lcd.setCursor(9,1); lcd.print(F("|(P")); lcd.print(program); lcd.print(F(":"));
@@ -608,7 +608,7 @@
   }

   int a = analogRead(A0);
-  Serial.println(a);
+  //Serial.println(a);
   buttonState(a);

   if ((state == 3) && (state != laststate)) {
@@ -779,7 +779,7 @@
     case 5: Scrollingmenu("PROG*", 3, "Timezones", "setTimezones", "back", "", "", "", "",  "", "", "", currentMenuItem); break;
     case 51: Scrollingnumbers("TIMZ*",(nbPrograms+1),currentMenuItem, 1, 1);break;
     case 52: Scrollingnumbers("TIMZ*",(nbPrograms+1),currentMenuItem, 1, 1);break;
-    case 521: Scrollingmenu("ITEM*", 3,"SR", "MANUAL", "SS", "", "", "", "",  "", "", "", currentMenuItem);break;
+    case 521: Scrollingmenu("ITEM*", 4,"SR", "MANUAL", "SS", "back", "", "", "",  "", "", "", currentMenuItem);break;
     case 5221: Scrollingnumbers("HOUR*",25, currentMenuItem, 1, 1); break;
     case 5222: Scrollingnumbers("MOD***",122, currentMenuItem, -60 , 1); break;
     case 523: Scrollingnumbers("MIN***",62, currentMenuItem, 0 , 1); break;
@@ -799,8 +799,6 @@
 }

 void selectMenu(int x, int y) {
-
-  int P[nbPrograms][3];

   switch (x) {
     //------------------------------SelectrootMenu-------------------------------------
@@ -1226,22 +1224,8 @@
           case 1:
             switchmenu(51); break;
           case 2:
-            if (NBPROGRAMS >= 2){switchmenu(52);}
-            else{switchmenu(0);}
-            break;
-          case 3:
-            if (NBPROGRAMS >= 3){switchmenu(52);}
-            else{switchmenu(0);}
-            break;
-          case 4:
-            if (NBPROGRAMS >= 4){switchmenu(52);}
-            else{switchmenu(0);}
-            break;
-          case 5:
-            if (NBPROGRAMS >= 5){switchmenu(52);}
-            else{switchmenu(0);}
-            break;
-          case 6: switchmenu(0); break;
+            switchmenu(52); break;
+          case 3: switchmenu(0); break;
         }
       break;

@@ -1338,6 +1322,7 @@
       if (y < Nbitems) {
         mn = y - 1;
         switchmenu(524);
+        Serial.println(mn);
       }
       else {
         switchmenu(5);


convert to local timer based radio power management

--- Wikiduino/Wikiduino.ino
+++ Wikiduino/Wikiduino.ino
@@ -9,6 +9,9 @@
 #include <OneWire.h>
 #define num(array) (sizeof(array)/sizeof(array[0]))

+// pin assignments
+byte radioPowerPin = 2;
+
 // Ethernet Configuration

 byte mac[] = { 0xEE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED   };
@@ -22,6 +25,8 @@
 EthernetClient client(255);

 unsigned long requests = 0;
+unsigned long lastRequest = 0; // records the request number at time of the most recent radio powerup
+unsigned byte radioPowerMode = 1; // indicates which power management algorith to use

 // Sensor Configuration

@@ -34,9 +39,10 @@
 } temp[4] = {{0,0}};

 unsigned long lastSample = 100;
-unsigned int powersave = 0;
+unsigned long lastRadioOn = 0; // records time the radio was last powered on
 unsigned long now = 0;
 unsigned long topOfHour = 0;
+boolean radioOn = false; // status of radio power
 unsigned long crc_errs = 0;

 // Arduino Setup and Loop
@@ -45,6 +51,9 @@
   Serial.begin(115200L);
   Ethernet.begin(mac, ip, gateway, subnet);
   server.begin();
+  // configure radio power control pin
+  pinMode(radioPowerPin,OUTPUT);
+  powerRadio(true);
 }

 void loop() {
@@ -68,14 +77,41 @@
 }

 void manageRadioPower() {
-  boolean poweron = powersave == 0;
-  pinMode(2,OUTPUT);
-  digitalWrite(2,poweron);
-  if (!poweron) {
-    powersave--;
-  }
-}
-
+  if(radioOn && (lastRequest == requests) && (now-lastRadioOn >= 3600*1000))) {
+    // radio has been on for a while, but received no requests, may be wedged, try rebooting
+    powerRadio(false);
+    delay(2000);
+    powerRadio(true);
+  } else {
+    if(radioPowerMode == 0 || !topOfHour { // stay on
+      if(!radioOn) {
+        powerRadio(true);
+      }
+    } else if(radioPowerMode == 1) { // on at 58m30s, off at 4m15s after hour
+      // remove integer hours from time, just interested in phase ... not needed if we get a sync often enough relative to wrapping
+      while(now-topOfHour > (3600*1000)) {
+        topOfHour += 3600*1000;
+      }
+      unsigned long time_after_hour = (now-topOfHour) % (3600*1000);
+      if(radioOn && (time_after_hour > (4*60+15)*1000)) {
+        powerRadio(false);
+      } else if (!radioOn && (time_after_hour > (58*60+30)*1000)) {
+        powerRadio(true);
+    }
+  }
+}
+
+void powerRadio(boolean power) {
+  digitalWrite(radioPowerPin,power);
+  radioOn = power;
+  if(power && !lastRadioOn) {
+    lastRadioOn = now;
+    lastRequest = requests;
+  } else if(!power && lastRadioOn) {
+    lastRadioOn = 0;
+  }
+}
+
 void analogSample() {
   for (int i = 0; i < num(analog); i++) {
     analog[i] = analogRead(i);
@@ -185,8 +221,10 @@
     faviconReport();
   } else if (code == 's') {
     topOfHour = now = millis();
-  } else if (code == 'p') {
-    powersave = 55*60;
+  } else if (code == '0') {
+    radioPowerMode = 0;
+  } else if (code == '1') {
+    radioPowerMode = 1;
   } else {
     errorReport();
   }


Added green on D#.  Added started test sequence

--- VisualMetronome.ino
+++ VisualMetronome.ino
@@ -2,103 +2,110 @@
 #include <Adafruit_NeoPixel.h>

 // Which pin on the Arduino is connected to the NeoPixels?
-#define PIN            6
+#define PIN 6

 // How many NeoPixels are attached to the Arduino?
-#define NUMPIXELS      40
+#define NUMPIXELS 40

 Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

 MIDI_CREATE_DEFAULT_INSTANCE();

-// -----------------------------------------------------------------------------
-
-// This function will be automatically called when a NoteOn is received.
-// It must be a void-returning function with the correct parameters,
-// see documentation here:
-// http://arduinomidilib.fortyseveneffects.com/a00022.html
-
-void handleNoteOn(byte channel, byte pitch, byte velocity)
+void handleNoteOn(byte channel, byte note, byte velocity)
 {
   int r = 0;
   int g = 0;
   int b = 0;

-  switch( pitch )
+  int pitch = note % 12;
+
+  switch (pitch)
   {
-    case 60:
-      r = 255;
-      g = 0;
-      b = 0;
-      break;
+  // C - Red
+  case 0:
+    r = 255;
+    g = 0;
+    b = 0;
+    break;

-   case 61:
-      r = 0;
-      g = 0;
-      b = 255;
-      break;
-
-    case 62:
-      r = 255;
-      g = 255;
-      b = 255;
-      break;
+  // C# - Blue
+  case 1:
+    r = 0;
+    g = 0;
+    b = 255;
+    break;

-    case 63: //green
-      r = 119;
-      g = 244;
-      b = 66;
-
-    default:
-      break;
+  // D - White
+  case 2:
+    r = 255;
+    g = 255;
+    b = 255;
+    break;
+
+  // D# - Green
+  case 3:
+    r = 119;
+    g = 244;
+    b = 66;
+
+  default:
+    break;
   }

-  for(int i=0;i<NUMPIXELS;i++){
-
-    pixels.setPixelColor(i, pixels.Color(r,g,b)); // Moderately bright green color.
-    pixels.setBrightness((velocity * 2) + 1 );
-    pixels.show(); // This sends the updated pixel color to the hardware.
+  for (int i = 0; i < NUMPIXELS; i++)
+  {
+    pixels.setPixelColor(i, pixels.Color(r, g, b));
   }
+  pixels.setBrightness((velocity * 2) + 1);
+  pixels.show(); // This sends the updated pixel color to the hardware.
 }

 void handleNoteOff(byte channel, byte pitch, byte velocity)
 {
-    // Do something when the note is released.
-    // Note that NoteOn messages with 0 velocity are interpreted as NoteOffs.
-  for(int i=0;i<NUMPIXELS;i++){
-
-
-    pixels.setPixelColor(i, pixels.Color(0,0,0));
-
-    pixels.show(); // This sends the updated pixel color to the hardware.
+  // Do something when the note is released.
+  // Note that NoteOn messages with 0 velocity are interpreted as NoteOffs.
+  for (int i = 0; i < NUMPIXELS; i++)
+  {
+    pixels.setPixelColor(i, pixels.Color(0, 0, 0));
   }
+  pixels.show(); // This sends the updated pixel color to the hardware.
 }

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

 void setup()
 {
-    //Serial.begin(9600);
-    pixels.begin();
-
-    // Connect the handleNoteOn function to the library,
-    // so it is called upon reception of a NoteOn.
-    MIDI.setHandleNoteOn(handleNoteOn);  // Put only the name of the function
+  //Serial.begin(9600);
+  pixels.begin();

-    // Do the same for NoteOffs
-    MIDI.setHandleNoteOff(handleNoteOff);
+  // First let's test the LEDs by "playing" MIDI notes 0 thru 11"
+  // This gives a some feedback that the hardware is all working
+  for (int i = 0; i < 12; i++)
+  {
+    handleNoteOn(0, i, 127);
+    delay(250);
+    handleNoteOff(0, i, 0);
+  }

-    // Initiate MIDI communications, listen to all channels
-    MIDI.begin(MIDI_CHANNEL_OMNI);
+  // Connect the handleNoteOn function to the library,
+  // so it is called upon reception of a NoteOn.
+  MIDI.setHandleNoteOn(handleNoteOn); // Put only the name of the function
+
+  // Connect the handleNoteOff function to the library,
+  // so it is called upon reception of a NoteOff.
+  MIDI.setHandleNoteOff(handleNoteOff);
+
+  // Initiate MIDI communications, listen to all channels
+  MIDI.begin(MIDI_CHANNEL_OMNI);
 }

 void loop()
 {
-    // Call MIDI.read the fastest you can for real-time performance.
-    MIDI.read();
+  // Call MIDI.read the fastest you can for real-time performance.
+  MIDI.read();

-    // There is no need to check if there are messages incoming
-    // if they are bound to a Callback function.
-    // The attached method will be called automatically
-    // when the corresponding message has been received.
+  // There is no need to check if there are messages incoming
+  // if they are bound to a Callback function.
+  // The attached method will be called automatically
+  // when the corresponding message has been received.
 }


This demo is not for Xadow Edison

This demo is not for Xadow Edison

--- Seeed_QTouch/examples/Grove_QTouch_demoCode_v_1_0/Grove_QTouch_demoCode_v_1_0.ino
+++ Seeed_QTouch/examples/Grove_QTouch_demoCode_v_1_0/Grove_QTouch_demoCode_v_1_0.ino
@@ -1,34 +0,0 @@
-#include <Wire.h>
-#include <Seeed_QTouch.h>
-
-#define led  3
-#define key0 0
-int lastKeySignal = 0;
-char nthr = 0;
-
-void setup()
-{
-  pinMode(led,OUTPUT);
-  digitalWrite(led,LOW);
-  Wire.begin();
-  Serial.begin(9600);
-
- //the value determines how long any key can be in touch before it recalibrates itself.160ms * 62 = 9.92s.
-  QTouch.setMaxDuration(62);
-
- //set the threshold value for key0 to register a detection.If the hit pan is bigger, you should increase this Value.This Value should not be less than 20.
-  QTouch.setNTHRForKey(60,key0);
-}
-
-void loop()
-{
-
-  if(QTouch.isTouch(0)) {
-    digitalWrite(led, HIGH);
-  }
-  else {    digitalWrite(led,LOW);
-  }
-}
-
-
-


Restored includes, fixes #20

Restored includes, fixes #20

--- firmware/Nanpy/Nanpy.ino
+++ firmware/Nanpy/Nanpy.ino
@@ -4,6 +4,38 @@
 # if USE_Counter
 #  error "USE_Tone conflicts with USE_Counter!"
 # endif
+#endif
+
+#if USE_EEPROM
+#include <EEPROM.h>
+#endif
+
+#if USE_Servo
+#include <Servo.h>
+#endif
+
+#if USE_LiquidCrystal
+#include <LiquidCrystal.h>
+#endif
+
+#if USE_Stepper
+#include <Stepper.h>
+#endif
+
+#if USE_OneWire
+#include <OneWire.h>
+#endif
+
+#if USE_DallasTemperature
+#include <DallasTemperature.h>
+#endif
+
+#if USE_CapacitiveSensor
+#include <CapacitiveSensor.h>
+#endif
+
+#if USE_DHT
+#include <DHT.h>
 #endif

 #include "BaseClass.h"


Added ENCRYPT_KEY requirements

Added ENCRYPT_KEY requirements

--- Arduino-Code/RF_Blinds.ino
+++ Arduino-Code/RF_Blinds.ino
@@ -1,297 +1,298 @@
-#include <RFM69.h>
-#include <SPI.h>
-#include <LowPower.h>
-#include <Servo.h>
-
-// Uncomment the appropriate frequency for your hardware
-//#define FREQUENCY     RF69_433MHZ
-//#define FREQUENCY     RF69_868MHZ
-#define FREQUENCY     RF69_915MHZ
-//#define IS_RFM69HW    //uncomment only for RFM69HW! Leave out if you have RFM69W!
-
-#define ENCRYPT_KEY "sampleEncryptKey"
-#define ADDRESS 1
-#define NETWORK_ID 1
-#define BLINDS_1   0b00000001
-//#define BLINDS_2   0b00000010
-//#define BLINDS_3   0b00000100
-//#define BLINDS_4   0b00001000
-//#define BLINDS_5   0b00010000
-//#define BLINDS_6   0b00100000
-//#define BLINDS_7   0b01000000
-#define MY_NODE_FLAG BLINDS_1
-
-struct PACKET
-{
-  uint8_t percent;
-  uint8_t voltage1;
-  uint8_t voltage2;
-  char charger;
-} packetOut;
-
-struct inPACKET
-{
-  uint8_t
-  group,
-  value;
-} packetIn;
-
-RFM69 radio;
-const int wakeUpPin = 3;
-const int moveUpPin = 4;
-const int servoPowerPin = 5;
-const int moveDownPin = 7;
-const int servoPin = 6;
-//const uint8_t boostPin = 'D15';
-const int okStatus = 16;
-const int chStatus = 15;
-int currentAngle = 0;
-Servo blindServo;
-
-//Voltage Meter correction value: (Measured Voltage of Input) / (Voltage Reading when correctionValue = 1)
-float correctionValue = 1.0000;
-
-void setup() {
-  Serial.begin(115200);
-
-  radio.initialize(FREQUENCY, ADDRESS, NETWORK_ID);
-  radio.encrypt(ENCRYPT_KEY);
-  radio.listenModeEnd();
-  //Serial.print("Network ID: ");
-  //Serial.print(NETWORK_ID);
-  //Serial.print(", Address: ");
-  //Serial.println(ADDRESS);
-  pinMode(wakeUpPin, INPUT);
-  pinMode(moveUpPin, INPUT);
-  pinMode(moveDownPin, INPUT);
-  pinMode(servoPowerPin, OUTPUT);
-  //pinMode(boostPin, OUTPUT);
-  pinMode(A0, INPUT);
-  pinMode(okStatus, INPUT_PULLUP);
-  pinMode(chStatus, INPUT_PULLUP);
-  blindServo.attach(servoPin);
-  //digitalWrite(boostPin, HIGH);
-
-}
-
-void loop() {
-  int angle;
-
-  attachInterrupt(1, wakeUpSwitch, HIGH);
-
-  if (digitalRead(moveUpPin) == HIGH) {
-    while(digitalRead(moveUpPin) == HIGH){
-    //digitalWrite(boostPin, HIGH);
-    digitalWrite(servoPowerPin, HIGH);
-    delay(75);
-    currentAngle = blindServo.read();
-    if (currentAngle < 175) {
-      currentAngle += 5;
-      blindServo.write(currentAngle);
-      delay(50);
-      //Serial.print("Opening, Setting servo angle to: ");
-      //Serial.println(blindServo.read());
-    }
-    else if (currentAngle < 180 && currentAngle > 175) {
-      currentAngle += 1;
-      blindServo.write(currentAngle);
-      delay(50);
-      //Serial.print("Opening, Setting servo angle to: ");
-      //Serial.println(blindServo.read());
-    }
-    else {
-      blindServo.write(180);
-      //Serial.println("Opening, Setting servo angle to: 180");
-    }
-  }
-  }
-  else if (digitalRead(moveDownPin) == HIGH) {
-    while(digitalRead(moveDownPin) == HIGH){
-    //digitalWrite(boostPin, HIGH);
-    digitalWrite(servoPowerPin, HIGH);
-    delay(75);
-    currentAngle = blindServo.read();
-    if (currentAngle > 5) {
-      currentAngle -= 5;
-      blindServo.write(currentAngle);
-      delay(50);
-      //Serial.print("Closing, Setting servo angle to: ");
-      //Serial.println(blindServo.read());
-    }
-    else if (currentAngle > 0 && currentAngle < 5) {
-      currentAngle -= 1;
-      blindServo.write(currentAngle);
-      delay(50);
-      //Serial.print("Closing, Setting servo angle to: ");
-      //Serial.println(blindServo.read());
-    }
-    else {
-      blindServo.write(0);
-      //Serial.println("Closing, Setting servo angle to: 0");
-    }
-  }
-  }
-  else {
-    if (radio.receiveDone()) {
-      if (radio.ACKRequested()) {
-        radio.sendACK();
-      }
-      //Serial.println("Received a normal message");
-      //Serial.println((char*)radio.DATA);
-      Serial.flush();
-    }
-
-    radio.listenModeStart();
-    if (digitalRead(wakeUpPin) == LOW) {
-      //digitalWrite(boostPin, LOW);
-      digitalWrite(servoPowerPin, LOW);
-      delay(5);
-      //Serial.println("Entering low-power listen mode...");
-      Serial.flush();
-      LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
-      // Woke up, check for a message
-      //delay(2000);
-      //Serial.println("Woke up!");
-      //delay(25);
-      //digitalWrite(boostPin, HIGH);
-      detachInterrupt(1);
-    }
-
-    int sensorValue = analogRead(A0);
-    ////Serial.println(sensorValue);
-    //      delay(1);
-    sensorValue = analogRead(A0);
-//    //Serial.println(sensorValue);
-    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
-    float voltage = ((sensorValue * (3.3 / 1023.0)) * 2);
-    voltage *=  correctionValue;
-//    //Serial.println(voltage);
-    voltage *= 1000;
-//    //Serial.println(voltage);
-    float percent = (((voltage / 1000) - 3.3) / 0.9125) * 100;
-//    //Serial.print("Battery Voltage: ");
-//    //Serial.println(voltage);
-//    //Serial.print("Battery Percent: ");
-//    //Serial.println(percent);
-    packetOut.percent = (int)percent;
-    packetOut.voltage1 = (int)(voltage / 100);
-    packetOut.voltage2 = (int)(voltage - (packetOut.voltage1 * 100));
-//    //Serial.print("Battery Percent: ");
-//    //Serial.println(packetOut.percent);
-//    //Serial.print("Battery Voltage1: ");
-//    //Serial.println(packetOut.voltage1);
-//    //Serial.print("Battery Voltage2: ");
-//    //Serial.println(packetOut.voltage2);
-
-
-    //Check the status of the solar charger
-    if (digitalRead(okStatus) == LOW && digitalRead(chStatus) == HIGH) {
-      packetOut.charger = 'O';
-//      //Serial.println(digitalRead(okStatus));
-//      //Serial.println(digitalRead(chStatus));
-//      //Serial.println("Solar: Fully Charged");
-    }
-    else if (digitalRead(okStatus) == HIGH && digitalRead(chStatus) == LOW) {
-      packetOut.charger = 'C';
-//      //Serial.println(digitalRead(okStatus));
-//      //Serial.println(digitalRead(chStatus));
-//      //Serial.println("Solar: Charging");
-    }
-    else if (digitalRead(okStatus) == LOW && digitalRead(chStatus) == LOW) {
-      packetOut.charger = 'E';
-//      //Serial.println(digitalRead(okStatus));
-//      //Serial.println(digitalRead(chStatus));
-//      //Serial.println("Solar: ERROR");
-    }
-    else {
-      packetOut.charger = 'N';
-//      //Serial.println(digitalRead(okStatus));
-//      //Serial.println(digitalRead(chStatus));
-//      //Serial.println("Solar: Not Charging");
-//      //Serial.println(packetOut.charger);
-    }
-
-    int initialPosition = blindServo.read();
-
-    uint8_t from = 0;
-    long burstRemaining = 0;
-    if (radio.DATALEN > 0) {
-      ////Serial.println("Received a message in listen mode");
-      ////Serial.println((char*)radio.DATA);
-
-      if (radio.TARGETID == 255)
-      {
-        struct inPACKET
-        *myPacket = (struct inPACKET *)radio.DATA;
-        angle = (myPacket->value);
-        if (myPacket->group & MY_NODE_FLAG)
-        {
-          digitalWrite(servoPowerPin, HIGH);
-          delay(75);
-          currentAngle = blindServo.read();
-          //Serial.print("Angle: ");
-          //Serial.println(angle);
-          while (currentAngle != angle) {
-            if (currentAngle > angle) {
-              currentAngle -= 1;
-              blindServo.write(currentAngle);
-              delay(15);
-            }
-
-            else if (currentAngle < angle) {
-              currentAngle += 1;
-              blindServo.write(currentAngle);
-              delay(15);
-            }
-          }
-        }
-      }
-      else if ( radio.DATA != null && radio.TARGETID == ADDRESS) {
-        struct inPACKET
-        *myPacket = (struct inPACKET *)radio.DATA;
-        angle = (myPacket->value);
-        if ( angle != 0 ) {
-          digitalWrite(servoPowerPin, HIGH);
-          delay(75);
-          currentAngle = blindServo.read();
-          //Serial.print("Angle: ");
-          //Serial.println(angle);
-          while (currentAngle != angle) {
-            if (currentAngle > angle) {
-              currentAngle -= 1;
-              blindServo.write(currentAngle);
-              delay(15);
-            }
-            else if (currentAngle < angle) {
-              currentAngle += 1;
-              blindServo.write(currentAngle);
-              delay(15);
-            }
-          }
-        }
-      }
-      delay(125);
-      Serial.flush();
-      from = radio.SENDERID;
-      burstRemaining = radio.LISTEN_BURST_REMAINING_MS;
-    }
-
-    // Radio goes back to standby, ready for normal operations
-    radio.listenModeEnd();
-
-    if (from) {
-      while (burstRemaining > 0) {
-        LowPower.powerDown(SLEEP_60MS, ADC_OFF, BOD_OFF);
-        burstRemaining -= 60;
-      }
-      LowPower.powerDown(SLEEP_30MS, ADC_OFF, BOD_OFF);
-      radio.send(from, &packetOut, sizeof(packetOut));
-    }
-  }
-}
-
-
-void wakeUpSwitch() {
-  //Serial.println("Waking up due to switch.");
-}
-
+#include <RFM69.h>
+#include <SPI.h>
+#include <LowPower.h>
+#include <Servo.h>
+
+// Uncomment the appropriate frequency for your hardware
+//#define FREQUENCY     RF69_433MHZ
+//#define FREQUENCY     RF69_868MHZ
+#define FREQUENCY     RF69_915MHZ
+//#define IS_RFM69HW    //uncomment only for RFM69HW! Leave out if you have RFM69W!
+
+//ENCRYPT_KEY must match gateway value and must be exactly 16 characters
+#define ENCRYPT_KEY "sampleEncryptKey"
+#define ADDRESS 1
+#define NETWORK_ID 1
+#define BLINDS_1   0b00000001
+//#define BLINDS_2   0b00000010
+//#define BLINDS_3   0b00000100
+//#define BLINDS_4   0b00001000
+//#define BLINDS_5   0b00010000
+//#define BLINDS_6   0b00100000
+//#define BLINDS_7   0b01000000
+#define MY_NODE_FLAG BLINDS_1
+
+struct PACKET
+{
+  uint8_t percent;
+  uint8_t voltage1;
+  uint8_t voltage2;
+  char charger;
+} packetOut;
+
+struct inPACKET
+{
+  uint8_t
+  group,
+  value;
+} packetIn;
+
+RFM69 radio;
+const int wakeUpPin = 3;
+const int moveUpPin = 4;
+const int servoPowerPin = 5;
+const int moveDownPin = 7;
+const int servoPin = 6;
+//const uint8_t boostPin = 'D15';
+const int okStatus = 16;
+const int chStatus = 15;
+int currentAngle = 0;
+Servo blindServo;
+
+//Voltage Meter correction value: (Measured Voltage of Input) / (Voltage Reading when correctionValue = 1)
+float correctionValue = 1.0000;
+
+void setup() {
+  Serial.begin(115200);
+
+  radio.initialize(FREQUENCY, ADDRESS, NETWORK_ID);
+  radio.encrypt(ENCRYPT_KEY);
+  radio.listenModeEnd();
+  //Serial.print("Network ID: ");
+  //Serial.print(NETWORK_ID);
+  //Serial.print(", Address: ");
+  //Serial.println(ADDRESS);
+  pinMode(wakeUpPin, INPUT);
+  pinMode(moveUpPin, INPUT);
+  pinMode(moveDownPin, INPUT);
+  pinMode(servoPowerPin, OUTPUT);
+  //pinMode(boostPin, OUTPUT);
+  pinMode(A0, INPUT);
+  pinMode(okStatus, INPUT_PULLUP);
+  pinMode(chStatus, INPUT_PULLUP);
+  blindServo.attach(servoPin);
+  //digitalWrite(boostPin, HIGH);
+
+}
+
+void loop() {
+  int angle;
+
+  attachInterrupt(1, wakeUpSwitch, HIGH);
+
+  if (digitalRead(moveUpPin) == HIGH) {
+    while(digitalRead(moveUpPin) == HIGH){
+    //digitalWrite(boostPin, HIGH);
+    digitalWrite(servoPowerPin, HIGH);
+    delay(75);
+    currentAngle = blindServo.read();
+    if (currentAngle < 175) {
+      currentAngle += 5;
+      blindServo.write(currentAngle);
+      delay(50);
+      //Serial.print("Opening, Setting servo angle to: ");
+      //Serial.println(blindServo.read());
+    }
+    else if (currentAngle < 180 && currentAngle > 175) {
+      currentAngle += 1;
+      blindServo.write(currentAngle);
+      delay(50);
+      //Serial.print("Opening, Setting servo angle to: ");
+      //Serial.println(blindServo.read());
+    }
+    else {
+      blindServo.write(180);
+      //Serial.println("Opening, Setting servo angle to: 180");
+    }
+  }
+  }
+  else if (digitalRead(moveDownPin) == HIGH) {
+    while(digitalRead(moveDownPin) == HIGH){
+    //digitalWrite(boostPin, HIGH);
+    digitalWrite(servoPowerPin, HIGH);
+    delay(75);
+    currentAngle = blindServo.read();
+    if (currentAngle > 5) {
+      currentAngle -= 5;
+      blindServo.write(currentAngle);
+      delay(50);
+      //Serial.print("Closing, Setting servo angle to: ");
+      //Serial.println(blindServo.read());
+    }
+    else if (currentAngle > 0 && currentAngle < 5) {
+      currentAngle -= 1;
+      blindServo.write(currentAngle);
+      delay(50);
+      //Serial.print("Closing, Setting servo angle to: ");
+      //Serial.println(blindServo.read());
+    }
+    else {
+      blindServo.write(0);
+      //Serial.println("Closing, Setting servo angle to: 0");
+    }
+  }
+  }
+  else {
+    if (radio.receiveDone()) {
+      if (radio.ACKRequested()) {
+        radio.sendACK();
+      }
+      //Serial.println("Received a normal message");
+      //Serial.println((char*)radio.DATA);
+      Serial.flush();
+    }
+
+    radio.listenModeStart();
+    if (digitalRead(wakeUpPin) == LOW) {
+      //digitalWrite(boostPin, LOW);
+      digitalWrite(servoPowerPin, LOW);
+      delay(5);
+      //Serial.println("Entering low-power listen mode...");
+      Serial.flush();
+      LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
+      // Woke up, check for a message
+      //delay(2000);
+      //Serial.println("Woke up!");
+      //delay(25);
+      //digitalWrite(boostPin, HIGH);
+      detachInterrupt(1);
+    }
+
+    int sensorValue = analogRead(A0);
+    ////Serial.println(sensorValue);
+    //      delay(1);
+    sensorValue = analogRead(A0);
+//    //Serial.println(sensorValue);
+    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
+    float voltage = ((sensorValue * (3.3 / 1023.0)) * 2);
+    voltage *=  correctionValue;
+//    //Serial.println(voltage);
+    voltage *= 1000;
+//    //Serial.println(voltage);
+    float percent = (((voltage / 1000) - 3.3) / 0.9125) * 100;
+//    //Serial.print("Battery Voltage: ");
+//    //Serial.println(voltage);
+//    //Serial.print("Battery Percent: ");
+//    //Serial.println(percent);
+    packetOut.percent = (int)percent;
+    packetOut.voltage1 = (int)(voltage / 100);
+    packetOut.voltage2 = (int)(voltage - (packetOut.voltage1 * 100));
+//    //Serial.print("Battery Percent: ");
+//    //Serial.println(packetOut.percent);
+//    //Serial.print("Battery Voltage1: ");
+//    //Serial.println(packetOut.voltage1);
+//    //Serial.print("Battery Voltage2: ");
+//    //Serial.println(packetOut.voltage2);
+
+
+    //Check the status of the solar charger
+    if (digitalRead(okStatus) == LOW && digitalRead(chStatus) == HIGH) {
+      packetOut.charger = 'O';
+//      //Serial.println(digitalRead(okStatus));
+//      //Serial.println(digitalRead(chStatus));
+//      //Serial.println("Solar: Fully Charged");
+    }
+    else if (digitalRead(okStatus) == HIGH && digitalRead(chStatus) == LOW) {
+      packetOut.charger = 'C';
+//      //Serial.println(digitalRead(okStatus));
+//      //Serial.println(digitalRead(chStatus));
+//      //Serial.println("Solar: Charging");
+    }
+    else if (digitalRead(okStatus) == LOW && digitalRead(chStatus) == LOW) {
+      packetOut.charger = 'E';
+//      //Serial.println(digitalRead(okStatus));
+//      //Serial.println(digitalRead(chStatus));
+//      //Serial.println("Solar: ERROR");
+    }
+    else {
+      packetOut.charger = 'N';
+//      //Serial.println(digitalRead(okStatus));
+//      //Serial.println(digitalRead(chStatus));
+//      //Serial.println("Solar: Not Charging");
+//      //Serial.println(packetOut.charger);
+    }
+
+    int initialPosition = blindServo.read();
+
+    uint8_t from = 0;
+    long burstRemaining = 0;
+    if (radio.DATALEN > 0) {
+      ////Serial.println("Received a message in listen mode");
+      ////Serial.println((char*)radio.DATA);
+
+      if (radio.TARGETID == 255)
+      {
+        struct inPACKET
+        *myPacket = (struct inPACKET *)radio.DATA;
+        angle = (myPacket->value);
+        if (myPacket->group & MY_NODE_FLAG)
+        {
+          digitalWrite(servoPowerPin, HIGH);
+          delay(75);
+          currentAngle = blindServo.read();
+          //Serial.print("Angle: ");
+          //Serial.println(angle);
+          while (currentAngle != angle) {
+            if (currentAngle > angle) {
+              currentAngle -= 1;
+              blindServo.write(currentAngle);
+              delay(15);
+            }
+
+            else if (currentAngle < angle) {
+              currentAngle += 1;
+              blindServo.write(currentAngle);
+              delay(15);
+            }
+          }
+        }
+      }
+      else if ( radio.DATA != null && radio.TARGETID == ADDRESS) {
+        struct inPACKET
+        *myPacket = (struct inPACKET *)radio.DATA;
+        angle = (myPacket->value);
+        if ( angle != 0 ) {
+          digitalWrite(servoPowerPin, HIGH);
+          delay(75);
+          currentAngle = blindServo.read();
+          //Serial.print("Angle: ");
+          //Serial.println(angle);
+          while (currentAngle != angle) {
+            if (currentAngle > angle) {
+              currentAngle -= 1;
+              blindServo.write(currentAngle);
+              delay(15);
+            }
+            else if (currentAngle < angle) {
+              currentAngle += 1;
+              blindServo.write(currentAngle);
+              delay(15);
+            }
+          }
+        }
+      }
+      delay(125);
+      Serial.flush();
+      from = radio.SENDERID;
+      burstRemaining = radio.LISTEN_BURST_REMAINING_MS;
+    }
+
+    // Radio goes back to standby, ready for normal operations
+    radio.listenModeEnd();
+
+    if (from) {
+      while (burstRemaining > 0) {
+        LowPower.powerDown(SLEEP_60MS, ADC_OFF, BOD_OFF);
+        burstRemaining -= 60;
+      }
+      LowPower.powerDown(SLEEP_30MS, ADC_OFF, BOD_OFF);
+      radio.send(from, &packetOut, sizeof(packetOut));
+    }
+  }
+}
+
+
+void wakeUpSwitch() {
+  //Serial.println("Waking up due to switch.");
+}
+


Fixed comment on which board pin to connect in CosaVWIreceiver demo.

--- examples/VWI/CosaVWIreceiver/CosaVWIreceiver.ino
+++ examples/VWI/CosaVWIreceiver/CosaVWIreceiver.ino
@@ -48,7 +48,7 @@
 // Block4B5BCodec codec;
 // BitstuffingCodec codec;

-// Virtual Wire Interface Receiver connected to pin D9
+// Virtual Wire Interface Receiver connected to pin D8
 VWI::Receiver rx(Board::D8, &codec);
 const uint16_t SPEED = 4000;


Cleaning up error handling.

Cleaning up error handling.

--- examples/VWI/CosaVWIreceiver/CosaVWIreceiver.ino
+++ examples/VWI/CosaVWIreceiver/CosaVWIreceiver.ino
@@ -76,10 +76,7 @@
   cnt += 1;

   // Check that the correct messaage size was received
-  if (len != sizeof(msg)) {
-    err += 1;
-    return;
-  }
+  if (len != sizeof(msg)) return;

   // Check message number
   if (msg.nr != next) {


Cleanup ex24_ard_tabs

Cleanup ex24_ard_tabs

--- examples/arduino/ex24_ard_tabs/ex24_ard_tabs.ino
+++ examples/arduino/ex24_ard_tabs/ex24_ard_tabs.ino
@@ -26,7 +26,7 @@
 // Defines for resources

 // Enumerations for pages, elements, fonts, images
-enum { E_PG_GLOBAL, E_PG_MAIN, E_PG_CONFIG, E_PG_ALERT };
+enum { E_PG_BASE, E_PG_MAIN, E_PG_CONFIG, E_PG_ALERT };
 enum {
   E_ELEM_BTN_QUIT, E_ELEM_TAB_MAIN, E_ELEM_TAB_CONFIG, E_ELEM_BTN_ALERT,
   E_ELEM_TXT_COUNT, E_ELEM_PROGRESS,
@@ -46,11 +46,11 @@
 #define MAX_FONT                3

 // Define the maximum number of elements per page
-#define MAX_ELEM_PG_GLOBAL      8                  // # Elems total on Global page
+#define MAX_ELEM_PG_BASE      8                  // # Elems total on Global page
 #define MAX_ELEM_PG_MAIN        3                  // # Elems total on Main page
 #define MAX_ELEM_PG_CONFIG      6                  // # Elems total on Extra page
 #define MAX_ELEM_PG_ALERT       4                  // # Elems total on Alert popup page
-#define MAX_ELEM_PG_GLOBAL_RAM  MAX_ELEM_PG_GLOBAL // # Elems in RAM
+#define MAX_ELEM_PG_BASE_RAM  MAX_ELEM_PG_BASE // # Elems in RAM
 #define MAX_ELEM_PG_MAIN_RAM    MAX_ELEM_PG_MAIN   // # Elems in RAM
 #define MAX_ELEM_PG_CONFIG_RAM  MAX_ELEM_PG_CONFIG // # Elems in RAM
 #define MAX_ELEM_PG_ALERT_RAM   MAX_ELEM_PG_ALERT  // # Elems in RAM
@@ -59,8 +59,8 @@
 gslc_tsDriver               m_drv;
 gslc_tsFont                 m_asFont[MAX_FONT];
 gslc_tsPage                 m_asPage[MAX_PAGE];
-gslc_tsElem                 m_asGlbElem[MAX_ELEM_PG_GLOBAL_RAM];
-gslc_tsElemRef              m_asGlbElemRef[MAX_ELEM_PG_GLOBAL];
+gslc_tsElem                 m_asGlbElem[MAX_ELEM_PG_BASE_RAM];
+gslc_tsElemRef              m_asGlbElemRef[MAX_ELEM_PG_BASE];
 gslc_tsElem                 m_asMainElem[MAX_ELEM_PG_MAIN_RAM];
 gslc_tsElemRef              m_asMainElemRef[MAX_ELEM_PG_MAIN];
 gslc_tsElem                 m_asConfigElem[MAX_ELEM_PG_CONFIG_RAM];
@@ -97,8 +97,9 @@
 // - Show example of common callback function
 bool CbBtnCommon(void* pvGui, void *pvElemRef, gslc_teTouch eTouch, int16_t nX, int16_t nY)
 {
-  gslc_tsElemRef* pElemRef = (gslc_tsElemRef*)(pvElemRef);
-  gslc_tsElem* pElem = pElemRef->pElem;
+  gslc_tsGui*     pGui      = (gslc_tsGui*)(pvGui);
+  gslc_tsElemRef* pElemRef  = (gslc_tsElemRef*)(pvElemRef);
+  gslc_tsElem*    pElem     = gslc_GetElemFromRef(pGui,pElemRef);
   int16_t nElemId = pElem->nId;
   if (eTouch == GSLC_TOUCH_UP_IN) {
     if (nElemId == E_ELEM_BTN_QUIT) {
@@ -138,61 +139,55 @@
 {
   gslc_tsElemRef*  pElemRef = NULL;

-  gslc_PageAdd(&m_gui, E_PG_GLOBAL, m_asGlbElem, MAX_ELEM_PG_GLOBAL_RAM, m_asGlbElemRef, MAX_ELEM_PG_GLOBAL);
+  gslc_PageAdd(&m_gui, E_PG_BASE, m_asGlbElem, MAX_ELEM_PG_BASE_RAM, m_asGlbElemRef, MAX_ELEM_PG_BASE);
   gslc_PageAdd(&m_gui, E_PG_MAIN, m_asMainElem, MAX_ELEM_PG_MAIN_RAM, m_asMainElemRef, MAX_ELEM_PG_MAIN);
   gslc_PageAdd(&m_gui, E_PG_CONFIG, m_asConfigElem, MAX_ELEM_PG_CONFIG_RAM, m_asConfigElemRef, MAX_ELEM_PG_CONFIG);
   gslc_PageAdd(&m_gui, E_PG_ALERT, m_asAlertElem, MAX_ELEM_PG_ALERT_RAM, m_asAlertElemRef, MAX_ELEM_PG_ALERT);

   // Note that the current page defaults to the first page added, which in the
-  // above sequence is E_PG_GLOBAL. Therefore, we should explicitly ensure
+  // above sequence is E_PG_BASE. Therefore, we should explicitly ensure
   // that the main page is the current page.
   gslc_SetPageCur(&m_gui, E_PG_MAIN);
-  // Now mark the E_PG_GLOBAL as a "base" page which means that it's elements
+  // Now mark the E_PG_BASE as a "base" page which means that it's elements
   // are always visible. This is useful for common page elements.
-  gslc_SetPageBase(&m_gui, E_PG_GLOBAL);
+  gslc_SetPageBase(&m_gui, E_PG_BASE);

   // -----------------------------------
-  // PAGE: GLOBAL
+  // PAGE: BASE
   // Create title
-  pElemRef = gslc_ElemCreateTxt(&m_gui, GSLC_ID_AUTO, E_PG_GLOBAL, (gslc_tsRect) { 10, 10, 100, 20 },
+  pElemRef = gslc_ElemCreateTxt(&m_gui, GSLC_ID_AUTO, E_PG_BASE, (gslc_tsRect) { 10, 10, 100, 20 },
     (char*)"GUIslice Demo", 0, E_FONT_TITLE);
   gslc_ElemSetTxtAlign(&m_gui, pElemRef, GSLC_ALIGN_MID_LEFT);
   gslc_ElemSetFillEn(&m_gui, pElemRef, false);
   gslc_ElemSetTxtCol(&m_gui, pElemRef, GSLC_COL_WHITE);

-  pElemRef = gslc_ElemCreateBtnTxt(&m_gui, E_ELEM_BTN_QUIT, E_PG_GLOBAL,
-    (gslc_tsRect) {
-    240, 5, 50, 25
-  }, (char*)"Quit", 0, E_FONT_BTN, &CbBtnCommon);
+  pElemRef = gslc_ElemCreateBtnTxt(&m_gui, E_ELEM_BTN_QUIT, E_PG_BASE,
+    (gslc_tsRect) { 240, 5, 50, 25 }, (char*)"Quit", 0, E_FONT_BTN, &CbBtnCommon);
   gslc_ElemSetCol(&m_gui, pElemRef, GSLC_COL_RED_DK2, GSLC_COL_RED_DK4, GSLC_COL_RED_DK1);

-  pElemRef = gslc_ElemCreateLine(&m_gui, GSLC_ID_AUTO, E_PG_GLOBAL, 0, 35, 320, 35);
+  pElemRef = gslc_ElemCreateLine(&m_gui, GSLC_ID_AUTO, E_PG_BASE, 0, 35, 320, 35);
   gslc_ElemSetCol(&m_gui, pElemRef, GSLC_COL_BLACK, GSLC_COL_GRAY, GSLC_COL_GRAY);

   // Create counter
-  pElemRef = gslc_ElemCreateTxt(&m_gui, GSLC_ID_AUTO, E_PG_GLOBAL, (gslc_tsRect) { 110, 10, 50, 20 },
+  pElemRef = gslc_ElemCreateTxt(&m_gui, GSLC_ID_AUTO, E_PG_BASE, (gslc_tsRect) { 110, 10, 50, 20 },
     (char*)"Count:", 0, E_FONT_TXT);
   static char mstr1[8] = "";
-  pElemRef = gslc_ElemCreateTxt(&m_gui, E_ELEM_TXT_COUNT, E_PG_GLOBAL, (gslc_tsRect) { 170, 10, 50, 20 },
+  pElemRef = gslc_ElemCreateTxt(&m_gui, E_ELEM_TXT_COUNT, E_PG_BASE, (gslc_tsRect) { 170, 10, 50, 20 },
     mstr1, sizeof(mstr1), E_FONT_TXT);
   gslc_ElemSetTxtCol(&m_gui, pElemRef, GSLC_COL_PURPLE);
   m_pElemCnt = pElemRef; // Save for quick access

   // Create Tab label buttons, start with main with framed highlight
-  m_pElemTabMain = gslc_ElemCreateBtnTxt(&m_gui, E_ELEM_TAB_MAIN, E_PG_GLOBAL,
-    (gslc_tsRect) {
-    30, 50, 50, 20
-  }, (char*)"Main", 0, E_FONT_BTN, &CbBtnCommon);
-  m_pElemTabConfig = gslc_ElemCreateBtnTxt(&m_gui, E_ELEM_TAB_CONFIG, E_PG_GLOBAL,
-    (gslc_tsRect) {
-    90, 50, 50, 20
-  }, (char*)"Extra", 0, E_FONT_BTN, &CbBtnCommon);
+  m_pElemTabMain = gslc_ElemCreateBtnTxt(&m_gui, E_ELEM_TAB_MAIN, E_PG_BASE,
+    (gslc_tsRect) { 30, 50, 50, 20 }, (char*)"Main", 0, E_FONT_BTN, &CbBtnCommon);
+  m_pElemTabConfig = gslc_ElemCreateBtnTxt(&m_gui, E_ELEM_TAB_CONFIG, E_PG_BASE,
+    (gslc_tsRect) { 90, 50, 50, 20 }, (char*)"Extra", 0, E_FONT_BTN, &CbBtnCommon);
   SetTabHighlight(E_ELEM_TAB_MAIN);

   // Create tab box
-  pElemRef = gslc_ElemCreateBox(&m_gui, GSLC_ID_AUTO, E_PG_GLOBAL, (gslc_tsRect) { 20, 70, 200, 150 });
+  pElemRef = gslc_ElemCreateBox(&m_gui, GSLC_ID_AUTO, E_PG_BASE, (gslc_tsRect) { 20, 70, 200, 150 });
   gslc_ElemSetCol(&m_gui, pElemRef, GSLC_COL_WHITE, GSLC_COL_BLACK, GSLC_COL_BLACK);

   // -----------------------------------
@@ -208,18 +203,14 @@

   // Checkbox element
   pElemRef = gslc_ElemXCheckboxCreate(&m_gui, E_ELEM_CHECK1, E_PG_MAIN, &m_asXCheck[0],
-    (gslc_tsRect) {
-    100, 160, 30, 30
-  }, false, GSLCX_CHECKBOX_STYLE_X, GSLC_COL_BLUE_LT2, false);
+    (gslc_tsRect) { 100, 160, 30, 30 }, false, GSLCX_CHECKBOX_STYLE_X, GSLC_COL_BLUE_LT2, false);

   // -----------------------------------
   // PAGE: CONFIG

   // Create Dummy button
   pElemRef = gslc_ElemCreateBtnTxt(&m_gui, E_ELEM_BTN_ALERT, E_PG_CONFIG,
-    (gslc_tsRect) {
-    60, 170, 50, 20
-  }, (char*)"Alert", 0, E_FONT_BTN, &CbBtnCommon);
+    (gslc_tsRect) { 60, 170, 50, 20 }, (char*)"Alert", 0, E_FONT_BTN, &CbBtnCommon);
   gslc_ElemSetCol(&m_gui, pElemRef, GSLC_COL_GREEN_DK2, GSLC_COL_GREEN_DK4, GSLC_COL_GREEN_DK1);

   // Create a few labels & checkboxes
@@ -227,17 +218,13 @@
   int16_t    nSpaceY = 30;

   pElemRef = gslc_ElemXCheckboxCreate(&m_gui, E_ELEM_CHECK2, E_PG_CONFIG, &m_asXCheck[1],
-    (gslc_tsRect) {
-    60, nPosY, 20, 20
-  }, false, GSLCX_CHECKBOX_STYLE_X, GSLC_COL_RED_LT2, false);
+    (gslc_tsRect) { 60, nPosY, 20, 20 }, false, GSLCX_CHECKBOX_STYLE_X, GSLC_COL_RED_LT2, false);
   pElemRef = gslc_ElemCreateTxt(&m_gui, GSLC_ID_AUTO, E_PG_CONFIG, (gslc_tsRect) { 100, nPosY, 50, 10 },
     (char*)"Data 1", 0, E_FONT_TXT);
   nPosY += nSpaceY;

   pElemRef = gslc_ElemXCheckboxCreate(&m_gui, E_ELEM_CHECK3, E_PG_CONFIG, &m_asXCheck[2],
-    (gslc_tsRect) {
-    60, nPosY, 20, 20
-  }, false, GSLCX_CHECKBOX_STYLE_X, GSLC_COL_RED_LT2, false);
+    (gslc_tsRect) { 60, nPosY, 20, 20 }, false, GSLCX_CHECKBOX_STYLE_X, GSLC_COL_RED_LT2, false);
   pElemRef = gslc_ElemCreateTxt(&m_gui, GSLC_ID_AUTO, E_PG_CONFIG, (gslc_tsRect) { 100, nPosY, 50, 10 },
     (char*)"Data 2", 0, E_FONT_TXT);
   nPosY += nSpaceY;
@@ -262,16 +249,12 @@

   // Create OK button
   pElemRef = gslc_ElemCreateBtnTxt(&m_gui, E_ELEM_ALERT_OK, E_PG_ALERT,
-    (gslc_tsRect) {
-    160 - 40 - 30, 120 + 30, 2 * 30, 2 * 10
-  }, (char*)"OK", 0, E_FONT_BTN, &CbBtnCommon);
+    (gslc_tsRect) { 160 - 40 - 30, 120 + 30, 2 * 30, 2 * 10 }, (char*)"OK", 0, E_FONT_BTN, &CbBtnCommon);
   gslc_ElemSetCol(&m_gui, pElemRef, GSLC_COL_BLUE_DK2, GSLC_COL_BLUE_DK4, GSLC_COL_BLUE_DK1);

   // Create Cancel button
   pElemRef = gslc_ElemCreateBtnTxt(&m_gui, E_ELEM_ALERT_CANCEL, E_PG_ALERT,
-    (gslc_tsRect) {
-    160 + 40 - 30, 120 + 30, 2 * 30, 2 * 10
-  }, (char*)"Cancel", 0, E_FONT_BTN, &CbBtnCommon);
+    (gslc_tsRect) { 160 + 40 - 30, 120 + 30, 2 * 30, 2 * 10 }, (char*)"Cancel", 0, E_FONT_BTN, &CbBtnCommon);
   gslc_ElemSetCol(&m_gui, pElemRef, GSLC_COL_BLUE_DK2, GSLC_COL_BLUE_DK4, GSLC_COL_BLUE_DK1);

@@ -321,7 +304,7 @@
   gslc_ElemXGaugeUpdate(&m_gui, m_pElemProgress, ((m_nCount / 2) % 100));

   // We can change or disable the global page as needed:
-  //   gslc_SetPageGlobal(&m_gui, E_PG_GLOBAL);    // Set to E_PG_GLOBAL
+  //   gslc_SetPageGlobal(&m_gui, E_PG_BASE);    // Set to E_PG_BASE
   //   gslc_SetPageGlobal(&m_gui, GSLC_PAGE_NONE); // Disable

   // Periodically call GUIslice update function


V2.2

V2.2

Added /log page for latest visitors log
code reviewed

--- esp32LightServerRGB.ino
+++ esp32LightServerRGB.ino
@@ -19,9 +19,9 @@
 // end of sensors

 // Settings you should check/change
-String resetpass = "YourWifiResetPassword"; // password to reset wifimanager when allready connected
+const String resetpass = "YourWifiResetPassword"; // password to reset wifimanager when allready connected
 const String thingkey = "YourThingSpeakKey"; //your thingspeak API key
-const String thingchanel = "000000"; //your thingspeak Chanel #
+const String thingchanel = "YourThingspeakChanel#"; //your thingspeak Chanel #
 const long interval = 60000; // interval in ms for sending temperature data to thingspeak
 const String liens = "Acceuil - Température - Version - Reset - Temp stats\n"; // html/links shown at bottom of pages
 String dernadd = "Fraichement booté"; //variable for ip logging (you can put your fresh boot mesage here in text/html)
@@ -53,6 +53,7 @@
 unsigned long flashrendu = 0;
 int roulepastusuite = 0;
 int flashoufade = 0;
+String logs[51];
 // end of internally used vars

 // stylesheet for web pages
@@ -90,6 +91,13 @@
                    "transition-duration: 0.4s; width: 80%;\n}\n"
                    "button:hover {\n"
                    "box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);\n}\n"
+                   "div#logs {"
+                   "width: 100%;"
+                   "height: 450px;"
+                   "font-size: 12px;"
+                   "overflow: auto;"
+                   "text-align:left;"
+                   "}"
                    "</style>\n";
 // end of stylesheet for web pages

@@ -163,18 +171,44 @@
   }
 }

+// log rotator
+void logtourne() {
+  for (int i = 49; i > 0; i--) {
+    int l = i;
+    l = l + 1;
+    logs[l] = logs[i];
+  }
+}
+
+// web page to handle flashing of leds (color/delay/number of flashes)
+void handleLog() {
+  String addy = server.client().remoteIP().toString();
+  String contenu = "";
+  for (int i = 1; i < 51; i++) {
+    if (logs[i] != "♥ vide") {
+      contenu += logs[i];
+      contenu += "\n
";
+    }
+  }
+  server.send(200, "text/plain", contenu);
+  Serial.println("");
+  Serial.println(addy);
+  Serial.println("Logs");
+  videCoeur();
+}
+
 // web page to handle flashing of leds (color/delay/number of flashes)
 void handleFlash() {
   String addy = server.client().remoteIP().toString();
-  Serial.println("");
-  Serial.println(addy);
-  Serial.println("Flash");
   String testteu = server.arg("COULEUR");
   String attend = server.arg("DELAIS");
   attendF = attend.toInt();
   String flashnombre = server.arg("FOIS");
   flashfois = flashnombre.toInt();
   flashfois = flashfois * 2;
+  Serial.println("");
+  Serial.println(addy);
+  Serial.println("Flash");
   Serial.println(testteu);
   Serial.print("Delais - ");
   Serial.println(attendF);
@@ -210,14 +244,52 @@
   contenu += "\n\n"
              "Merci\n";
   server.send(200, "text/html", contenu);
+  logtourne();
+  logs[1] = addy;
+  logs[1] += " : Flash : Couleur=";
+  logs[1] += testteu;
+  logs[1] += " : Delais=";
+  logs[1] += attend;
+  logs[1] += " : Fois=";
+  logs[1] += flashnombre;
+  logs[1].replace("<", "</"); //prevent html tags in logs so hackers cant code in log page lol
 }

 // web page for flash mode
+void handlePitoune() {
+  String addy = server.client().remoteIP().toString();
+  String contenu = "<!DOCTYPE html>\n\n\n";
+  contenu += "<meta charset=\"UTF-8\" />\n<title>Que la lumiere log</title>\n"
+             "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
+  contenu += css;
+  contenu += "\n";
+  contenu += "\n\n"
+             "
\n"
+             "
Les visiteurs
\n"
+             "

\nDernier IP à avoir changé la couleur : ";
+  contenu += dernadd;
+  contenu += "
\n";
+  contenu += liens;
+  contenu += "\n"
+             "
\n";
+  server.send(200, "text/html", contenu);
+  Serial.println("");
+  Serial.println(addy);
+  Serial.println("Page logs");
+  logtourne();
+  logs[1] = addy;
+  logs[1] += " : Page logs";
+}
+
 void handleClignote() {
   String addy = server.client().remoteIP().toString();
-  Serial.println("");
-  Serial.println(addy);
-  Serial.println("Page flash");
   String contenu = "<!DOCTYPE html>\n\n\n";
   contenu += "<meta charset=\"UTF-8\" />\n<title>Que la lumiere flash</title>\n"
              "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
@@ -272,6 +344,12 @@
              "</script>\n"
              "
\n";
   server.send(200, "text/html", contenu);
+  Serial.println("");
+  Serial.println(addy);
+  Serial.println("Page flash");
+  logtourne();
+  logs[1] = addy;
+  logs[1] += " : Page Flash";
 }

 // web page to handle leds fading
@@ -314,14 +392,16 @@
   contenu += "\n\n"
              "Merci\n";
   server.send(200, "text/html", contenu);
+  logtourne();
+  logs[1] = addy;
+  logs[1] += " : Fade : Couleur=";
+  logs[1] += testteu;
+  logs[1].replace("<", "</"); //prevent html tags in logs so hackers cant code in log page lol
 }

 // index page
 void handleRoot() {
   String addy = server.client().remoteIP().toString();
-  Serial.println("");
-  Serial.println(addy);
-  Serial.println("Page acceuil");
   String contenu = "<!DOCTYPE html>\n\n\n";
   contenu += "<meta charset=\"UTF-8\" />\n<title>Que la lumiere soit</title>\n"
              "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
@@ -372,6 +452,12 @@
              "</script>\n"
              "
\n";
   server.send(200, "text/html", contenu);
+  Serial.println("");
+  Serial.println(addy);
+  Serial.println("Page acceuil");
+  logtourne();
+  logs[1] = addy;
+  logs[1] += " : Acceuil";
 }

 //reset page
@@ -422,6 +508,11 @@
   contenu += liens;
   contenu += "\n

\n";
   server.send(200, "text/html", contenu);
+  logtourne();
+  logs[1] = addy;
+  logs[1] += " : Reset : Password=";
+  logs[1] += passme;
+  logs[1].replace("<", "</"); //prevent html tags in logs so hackers cant code in log page lol
   if (ouireset == 1) {
     Serial.println("Reset dans 10 secondes");
     delay(10000);
@@ -459,16 +550,29 @@
   server.send(404, "text/html", htmlmessage);
   String message = "404 File Not Found\n";
   message += "URI: ";
-  message += server.uri();
+  String uriL = server.uri();
+  message += uriL;
   message += "\nMethod: ";
-  message += (server.method() == HTTP_GET) ? "GET" : "POST";
+  String methodeL = (server.method() == HTTP_GET) ? "GET" : "POST";
+  message += methodeL;
   message += "\nArguments: ";
   message += server.args();
   message += "\n";
+  String argsL;
   for (uint8_t i = 0; i < server.args(); i++) {
+    argsL += ": " + server.argName(i) + "=" + server.arg(i) + " ";
     message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
   }
   Serial.print(message);
+  logtourne();
+  logs[1] = addy;
+  logs[1] += " : 404 : URI=";
+  logs[1] += uriL;
+  logs[1] += " : Methode=";
+  logs[1] += methodeL;
+  logs[1] += " ";
+  logs[1] += argsL;
+  logs[1].replace("<", "</"); //prevent html tags in logs so hackers cant code in log page lol
 }

 // function executed in main loop every minute to update sensors data to thingspeak.com
@@ -514,10 +618,6 @@
     latemp = sensors.getTempCByIndex(0);
   }
   String addy = server.client().remoteIP().toString();
-  Serial.println("");
-  Serial.println(addy);
-  Serial.print("Temperature : ");
-  Serial.println(latemp);
   String contenu = "<!DOCTYPE html>\n\n\n";
   contenu += "<meta charset=\"UTF-8\" />\n<title>Quel chaleur</title>\n"
              "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
@@ -547,12 +647,24 @@
   contenu += liens;
   contenu += "\n

\n";
   server.send(200, "text/html", contenu);
+  Serial.println("");
+  Serial.println(addy);
+  Serial.print("Temperature : ");
+  Serial.println(latemp);
+  Serial.print("Humidite : ");
+  Serial.println(h);
+  logtourne();
+  logs[1] = addy;
+  logs[1] += " : Temp : Temp=";
+  logs[1] += latemp;
+  logs[1] += " : Humidite=";
+  logs[1] += h;
 }

 int fadecomment(int claire) {
   int combien = 70;
   if (claire > 0)
-    combien = 100;
+    combien = 90;
   if (claire > 40)
     combien = 80;
   if (claire > 80)
@@ -564,11 +676,18 @@
   if (claire > 140)
     combien = 20;
   if (claire > 180)
-    combien = 10;
+    combien = 9;
   return combien;
 }

+void videCoeur(){
+    for (int i = 50; i > 0; i--) {
+    logs[i] = "♥ vide";
+  }
+}
+
 void setup() {
+  videCoeur();
   Serial.begin(115200);
   dht.begin();
   ledcAttachPin(pinRouge, 1); // assign RGB led pins to channels
@@ -590,14 +709,13 @@
   server.on("/leds", handleLeds);
   server.on("/flash", handleFlash);
   server.on("/reset", handleReset);
+  server.on("/logs", handleLog);
+  server.on("/log", handlePitoune);
   server.on("/temp", handleTemp);
   server.on("/party", handleClignote);
   server.on("/version", []() {
     String addy = server.client().remoteIP().toString();
-    Serial.println("");
-    Serial.println(addy);
-    Serial.println("Version request");
-    server.send(200, "text/html", "V2.1, Steve Olmstead sansillusion@gmail.com\n\n

"
+    server.send(200, "text/html", "V2.2, Steve Olmstead sansillusion@gmail.com\n\n

"
                 "Added fader function\nRemoved connection watchdog (better have good signal)\n
"
                 "Removed mDns (did not work anyway)\n\n

"
                 "Added smoother fading\n\n

"
@@ -619,7 +737,14 @@
                 "Cleaned code\n\n

"
                 "Added Flashing function and page for smart widget usage\n
"
                 "Added var to show your thingspeak channel in /temp iframes\n\n

"
-                "Added /party page for easy control of flash mode\n\n

" + liens);
+                "Added /party page for easy control of flash mode\n\n

"
+                "Added /log page to see latest ~50 visits\n\n

" + liens);
+    Serial.println("");
+    Serial.println(addy);
+    Serial.println("Version request");
+    logtourne();
+    logs[1] = addy;
+    logs[1] += " : Version request";
   });
   server.onNotFound(handleNotFound);
   server.begin();
@@ -639,8 +764,8 @@
   if (flashoufade == 1) {
     currentMillis = millis();
     if (currentMillis - previousMillisf >= attendF) {
+      flashfunk();
       previousMillisf = currentMillis;
-      flashfunk();
     }
   } else {
     if (r != rouge) {
@@ -649,7 +774,6 @@
         fadeR();
         previousMillisr = currentMillis;
         attendR = fadecomment(rouge);
-
       }
     }
     if (g != vert) {
@@ -658,7 +782,6 @@
         fadeG();
         previousMillisg = currentMillis;
         attendG = fadecomment(vert);
-
       }
     }
     if (b != bleu) {
@@ -671,5 +794,4 @@
     }
   }
 }
-
-
+


Removed old moveLeft and moveRight functions

These are replaced by the new and improved turn function

--- 2018-Firefighter/2018-Firefighter.ino
+++ 2018-Firefighter/2018-Firefighter.ino
@@ -61,16 +61,6 @@
   rightServo.write(180);
 }

-void moveLeft() {
-  leftServo.write(180);
-  rightServo.write(180);
-}
-
-void moveRight() {
-  leftServo.write(0);
-  rightServo.write(0);
-}
-
 void stopRobot() {
   leftServo.write(90);
   rightServo.write(90);


fix indent

fix indent

--- examples/RoseBot/RoseBotFirmata/RoseBotFirmata.ino
+++ examples/RoseBot/RoseBotFirmata/RoseBotFirmata.ino
@@ -1044,8 +1044,7 @@
 /*==============================================================================
  * LOOP()
  *============================================================================*/
-void loop()
-{
+void loop() {
   byte pin, analogPin;
   int pingResult = 0;
   byte pixyBlockIndex, numPixyBlocks;
@@ -1129,21 +1128,19 @@
     if (pixyIsReporting && pixyPtr != NULL) {
       numPixyBlocks = pixyPtr->getBlocks();
       // Only send Pixy data if a block was found.
-
-        if (samplingInterval < MINIMUM_SAMPLING_INTERVAL_WITH_PIXY) {
-          samplingInterval = MINIMUM_SAMPLING_INTERVAL_WITH_PIXY;
-        }
-        if (numPixyBlocks > pixyMaxBlocks) {
-          numPixyBlocks = pixyMaxBlocks;
-        }
-        Firmata.write(START_SYSEX);
-        Firmata.write(PIXY_DATA);
-        Firmata.write(numPixyBlocks);
-        for (pixyBlockIndex = 0; pixyBlockIndex < numPixyBlocks; pixyBlockIndex++) {
-          writePixyBlock(pixyBlockIndex);
-        }
-        Firmata.write(END_SYSEX);
-
+      if (samplingInterval < MINIMUM_SAMPLING_INTERVAL_WITH_PIXY) {
+        samplingInterval = MINIMUM_SAMPLING_INTERVAL_WITH_PIXY;
+      }
+      if (numPixyBlocks > pixyMaxBlocks) {
+        numPixyBlocks = pixyMaxBlocks;
+      }
+      Firmata.write(START_SYSEX);
+      Firmata.write(PIXY_DATA);
+      Firmata.write(numPixyBlocks);
+      for (pixyBlockIndex = 0; pixyBlockIndex < numPixyBlocks; pixyBlockIndex++) {
+        writePixyBlock(pixyBlockIndex);
+      }
+      Firmata.write(END_SYSEX);
     }
   }
   if (keepAliveInterval) {


M5Stack UI Config menu value accelerator WiFi ON/OFF

--- ANI_CameraRemote/ANI_CameraRemote.ino
+++ ANI_CameraRemote/ANI_CameraRemote.ino
@@ -13,14 +13,17 @@
   20170724 Calculate remaining time
   20180506 Preparatory work for M5Stack (display and keyboard)
   20180506 Hint: Use ESP8266 V2.4.0 since V2.4.1 has problems
-  20180510 First Version for M5Stack
+  20180510 First Version for M5Stack
+  20180511 M5Stack: WiFi OFF by default, config menu, C button as value accelerator
   --------------------------------------------------*/
 #ifdef ESP32
 #include <M5Stack.h>
 #include <WiFi.h>
 #include <Free_Fonts.h>
+#define SWITCH_WIFI_ON false
 #else
 #include <ESP8266WiFi.h>
+#define SWITCH_WIFI_ON true
 #endif

 //--------------------------------------------------
@@ -51,6 +54,7 @@
 // Global variables
 const String prgTitle = "ANI Camera Remote";
 const String prgVersion = "1.3";
+const String screenHeaderLine = prgTitle + " " + prgVersion;
 const int versionMonth = 5;
 const int versionYear = 2018;

@@ -73,12 +77,16 @@
 unsigned long timeSlotCounter = 0; // count the timeslots since start of timelapse

 int highlightLine = 2;
+int lastDialogLine = 8;
 unsigned long inactivityCounter = 0;
 unsigned long previousMilliseconds = millis();
+bool wifiON = SWITCH_WIFI_ON;

 String myIPStr = "";

-enum lcdState { LCDOFF, LCDON };
+enum lcdScreens { MAINSCREEN, CONFIGSCREEN };
+lcdScreens actuScreen = MAINSCREEN;
+enum lcdStates { LCDOFF, LCDON };
 bool lcdIsON = true;
 enum triggerModes { ON = 0, OFF = 1 };
 triggerModes currentTriggerMode = OFF;
@@ -109,16 +117,20 @@
   process();
   checkAndProcessStartPin();
   processKeyboard();
-  processWebClient();
+  if (wifiON)
+    processWebClient();
 }

 void setupWiFi()
 {
-  WiFi.mode(WIFI_AP); // AP mode for connections
-  WiFi.softAP(ssid, password);
-  server.begin();
-  IPAddress ip = WiFi.softAPIP();
-  myIPStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
+  if (wifiON)
+  {
+    WiFi.mode(WIFI_AP); // AP mode for connections
+    WiFi.softAP(ssid, password);
+    server.begin();
+    IPAddress ip = WiFi.softAPIP();
+    myIPStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
+  }
 }

 void processWebClient()
@@ -234,7 +246,7 @@
       if (currentDelayToStart > 0) // Start delay
       {
         currentDelayToStart--;
-        onDisplay();
+        onDisplay(MAINSCREEN);
       }
       else if (currentDelayBetweenShots > 0)
         if ((secCounter % currentDelayBetweenShots ) == 0) // Delay between shots
@@ -246,7 +258,7 @@
             currentNShots--;
             NumberOfShotsSinceStart++;
           }
-          onDisplay();
+          onDisplay(MAINSCREEN);
         }
     }
   }
@@ -492,26 +504,75 @@
 void displaySetup()
 {
   M5.begin();
-  onDisplay();
-}
-
-void onDisplay()
+  onDisplay(MAINSCREEN);
+}
+
+void onDisplay(lcdScreens screen)
 {
   int actuLine = 0;
   M5.Lcd.fillScreen(TFT_BLACK);
   M5.Lcd.setFreeFont(FF9);
-  outLCD(1, prgTitle + " " + prgVersion, TFT_BLUE);
-  outLCD(2, "Delay to Start: " + String(delayToStart), TFT_WHITE);
-  outLCD(3, "Number of Shots: " + String(numberOfShots), TFT_WHITE);
-  outLCD(4, "Interval: " + String(delayBetweenShots), TFT_WHITE);
-  if (startPin > -1)
-    outLCD(5, "Wait for GPIO" + String(startPin), TFT_WHITE);
-  outLCD(6, "START", TFT_YELLOW);
-  outLCD(7, "STOP", TFT_YELLOW);
-  outLCD(8, "ONE SHOT", TFT_YELLOW);
-  outLCD(9, "RESET", TFT_YELLOW);
-  outLCD(10, "Remaining delay: " + String(currentDelayToStart), TFT_GREEN);
-  outLCD(11, "Remaining shots: " + String(currentNShots), TFT_GREEN);
+  outLCD(1, screenHeaderLine, TFT_BLUE);
+  actuScreen = screen;
+  switch (screen)
+  {
+    case MAINSCREEN:
+      {
+        outLCD(2, "Delay to Start: " + String(delayToStart), TFT_WHITE);
+        outLCD(3, "Number of Shots: " + String(numberOfShots), TFT_WHITE);
+        outLCD(4, "Interval: " + String(delayBetweenShots), TFT_WHITE);
+        if (startPin > -1)
+          outLCD(5, "Wait for GPIO" + String(startPin), TFT_WHITE);
+        outLCD(6, "START", TFT_YELLOW);
+        outLCD(7, "STOP", TFT_YELLOW);
+        outLCD(8, "ONE SHOT", TFT_YELLOW);
+        outLCD(9, "RESET", TFT_YELLOW);
+        outLCD(10, "Remaining delay: " + String(currentDelayToStart), TFT_GREEN);
+        outLCD(11, "Remaining shots: " + String(currentNShots), TFT_GREEN);
+        lastDialogLine = 9;
+        break;
+      }
+    case CONFIGSCREEN:
+      {
+        outLCD(2, "WIFI ON", TFT_YELLOW);
+        outLCD(3, "WIFI OFF", TFT_YELLOW);
+        outLCD(4, "EXIT Configuration", TFT_YELLOW);
+        lastDialogLine = 4;
+        break;
+      }
+  }
+}
+
+void changeValueOrExecFunction(int upDownFactor, lcdScreens screen, int lineNumber)
+{
+  switch (screen)
+  {
+    case MAINSCREEN:
+      {
+        switch (lineNumber)
+        {
+          case 2: delayToStart = limitsUpDown(upDownFactor, delayToStart, 0, LONG_MAX); break;
+          case 3: numberOfShots = limitsUpDown(upDownFactor, numberOfShots, 1, LONG_MAX) ; break;
+          case 4: delayBetweenShots = limitsUpDown(upDownFactor, delayBetweenShots, 1, LONG_MAX); break;
+          case 5: setAndDoProcessMode(WAITFORGPIO); break;
+          case 6: setAndDoProcessMode(TIMELAPSESTART); break;
+          case 7: setAndDoProcessMode(TIMELAPSESTOP); break;
+          case 8: setAndDoProcessMode(ONESHOT); break;
+          case 9: setAndDoProcessMode(RESET); break;
+        }
+        break;
+      }
+    case CONFIGSCREEN:
+      {
+        switch (lineNumber)
+        {
+          case 2: wifiON = true; setupWiFi(); break;
+          case 3: ESP.restart(); break;
+          case 4: onDisplay(MAINSCREEN); break;
+        }
+        break;
+      }
+  }
 }

 void outLCD(int lineNumber, String outStr, int textColor)
@@ -522,12 +583,12 @@
   M5.Lcd.printf(outStr.c_str());
 }

-void switchScreenOnOff(lcdState dState)
+void switchScreenOnOff(lcdStates dState)
 {
   if (dState == LCDON)
   {
     M5.Lcd.writecommand(ILI9341_DISPON);
-    M5.Lcd.setBrightness(20);
+    M5.Lcd.setBrightness(50);
   }
   else
   {
@@ -560,21 +621,6 @@
   return retVal;
 }

-void changeValueOrExecFunction(int upDownFactor, int lineNumber)
-{
-  switch (lineNumber)
-  {
-    case 2: delayToStart = limitsUpDown(upDownFactor, delayToStart, 0, LONG_MAX); break;
-    case 3: numberOfShots = limitsUpDown(upDownFactor, numberOfShots, 1, LONG_MAX) ; break;
-    case 4: delayBetweenShots = limitsUpDown(upDownFactor, delayBetweenShots, 1, LONG_MAX); break;
-    case 5: setAndDoProcessMode(WAITFORGPIO); break;
-    case 6: setAndDoProcessMode(TIMELAPSESTART); break;
-    case 7: setAndDoProcessMode(TIMELAPSESTOP); break;
-    case 8: setAndDoProcessMode(ONESHOT); break;
-    case 9: setAndDoProcessMode(RESET); break;
-  }
-}
-
 void processKeyboard()
 {
   delay(100);
@@ -587,15 +633,18 @@
       switchScreenOnOff(LCDON);
     else
     {
-      int upDownFaktor = (M5.BtnA.isPressed()) ? +1 : -1;
+      int upDownFactor = M5.BtnA.isPressed() ? +1 : -1;
       if (plusMinusPressed)
       {
-        upDownFaktor = M5.BtnC.isPressed() ? (upDownFaktor * 10) : upDownFaktor;
-        changeValueOrExecFunction(upDownFaktor, highlightLine);
+        int scaleFactor = 1;
+        scaleFactor = M5.BtnC.isPressed() ? 100 : 1;
+        changeValueOrExecFunction(upDownFactor * scaleFactor, actuScreen, highlightLine);
       }
       else if (M5.BtnC.wasPressed()) // Only Button C: Move from line to line
-        highlightLine = (highlightLine > 8) ? 2 : highlightLine + 1;
-      onDisplay();
+        highlightLine = (highlightLine >= lastDialogLine) ? 2 : highlightLine + 1;
+      else if (M5.BtnC.pressedFor(5000)) // Enter config menu after 5 seconds press on button C
+        actuScreen = CONFIGSCREEN;
+      onDisplay(actuScreen);
     }
   }
   M5.update();


Fixed I2C address error

Fixed I2C address error

Zero is a valid I2C address!

--- CRC_VCNL4200/CRC_VCNL4200.ino
+++ CRC_VCNL4200/CRC_VCNL4200.ino
@@ -24,7 +24,7 @@
 	Serial.println(F("Scanning..."));

 	nDevices = 0;
-	for (address = 1; address < 127; address++) {
+	for (address = 0; address < 127; address++) {
 		// The i2c_scanner uses the return value of
 		// the Write.endTransmisstion to see if
 		// a device did acknowledge to the address.


more printing and debugging

more printing and debugging

--- DanceFeather/DanceFeather.ino
+++ DanceFeather/DanceFeather.ino
@@ -21,7 +21,8 @@
 #define FFT_SIZE 256
 #define HANN_SIZE 40
 #define FS (16000.0 / ACC_SIZE / LOW_PASS_SIZE)
-#define F2 3.5f
+//#define F2 3.5f
+#define F2 6.8f
 #define END_INDEX ((uint16_t) (F2 / (FS / FFT_SIZE)))

 #define LED_PIN 13
@@ -258,7 +259,7 @@
     for (int i = startIndex; i < endIndex; i++) {
         float magnitude = mag[i];
         magAvg[i] = magAvg[i] * 0.99 + magnitude * 0.01;
-        if (magAvg[i] > maxMag && i > 1) {
+        if (magAvg[i] > maxMag && i > 1 && i < 7) {
             maxMag = magAvg[i];
             maxIndex = i;
         }
@@ -339,7 +340,15 @@
   if (diff > 2 * magAvg[0]) {
     digitalWrite(LED_PIN, LOW);

-    Serial.print("Diff:\t"); Serial.println(diff);
+    Serial.print("Prev :\t");
+    for (int i = 0; i < endIndex; i++) {
+      float phase = prevPhase[i];
+      Serial.print(phase);
+      Serial.print("\t");
+    }
+    Serial.println("");
+
+    // Serial.print("Diff:\t"); Serial.println(diff);
     Serial.print("Phase:\t");
     for (int i = 0; i < endIndex; i++) {
       float phase = phaseAvg[i];
@@ -347,11 +356,6 @@
       Serial.print("\t");
     }
     Serial.println("");
-
-  }
-
-  if (diff > 2 * magAvg[0] && phaseNearZero) {
-    digitalWrite(LED_PIN, HIGH);

     Serial.print("BPM:\t");
     for (int i = 0; i < endIndex; i++) {
@@ -370,6 +374,11 @@
     }
     Serial.println("");

+  }
+
+  if (diff > 1 * magAvg[0] && phaseNearZero) {
+    Serial.println("BEAT!");
+    digitalWrite(LED_PIN, HIGH);
   } else {
     digitalWrite(LED_PIN, LOW);
   }
@@ -417,14 +426,15 @@
       float newVal = tempBuffer[i];
       lowPass += newVal;
       if (++numInLowPass >= LOW_PASS_SIZE) {
-        acc += abs(lowPass);
+        lowPass /= LOW_PASS_SIZE;
+        acc += lowPass * lowPass;
+        lowPass = 0;
+        numInLowPass = 0;
         numInAcc++;
-        numInLowPass = 0;
-        lowPass = 0;
       }

       if (numInAcc >= ACC_SIZE) {
-          addToFFT(acc);
+          addToFFT(acc / 2048);
           acc = 0;
           numInAcc = 0;
       }