Updated the ReadAndWrite example

Updated the ReadAndWrite example

--- examples/ReadAndWrite/ReadAndWrite.ino
+++ examples/ReadAndWrite/ReadAndWrite.ino
@@ -1,240 +1,198 @@
-/*
- * MFRC522 - Library to use ARDUINO RFID MODULE KIT 13.56 MHZ WITH TAGS SPI W AND R BY COOQROBOT.
- * The library file MFRC522.h has a wealth of useful info. Please read it.
- * The functions are documented in MFRC522.cpp.
- *
- * Based on code Dr.Leong   ( WWW.B2CQSHOP.COM )
- * Created by Miguel Balboa (circuitito.com), Jan, 2012.
- * Rewritten by Søren Thing Andersen (access.thing.dk), fall of 2013 (Translation to English, refactored, comments, anti collision, cascade levels.)
+/**
+ * ----------------------------------------------------------------------------
+ * This is a MFRC522 library example; see https://github.com/miguelbalboa/rfid
+ * for further details and other examples.
+ *
+ * NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
  *
  * Released into the public domain.
- *
- * This sample shows how to setup a block on a MIFARE Classic PICC to be in "Value Block" mode.
- * In Value Block mode the operations Increment/Decrement/Restore and Transfer can be used.
+ * ----------------------------------------------------------------------------
+ * This sample shows how to read and write data blocks on a MIFARE Classic PICC
+ * (= card/tag).
  *
- ----------------------------------------------------------------------------- empty_skull
-
- - Aggiunti pin per arduino Mega
- - Scritto semplice codice per la scrittura e lettura
-
- - add pin configuration for arduino mega
- - write simple read/write Code for new entry user
-
- http://mac86project.altervista.org/
-
- ----------------------------------------------------------------------------- Nicola Coppola
- * Pin layout should be as follows:
- * Signal     Pin              Pin               Pin
- *            Arduino Uno      Arduino Mega      MFRC522 board
+ * BEWARE: Data will be written to the PICC, in sector #1 (blocks #4 to #7).
+ *
+ *
+ * Typical pin layout used:
  * ------------------------------------------------------------
- * Reset      9                5                 RST
- * SPI SS     10               53                SDA
- * SPI MOSI   11               51                MOSI
- * SPI MISO   12               50                MISO
- * SPI SCK    13               52                SCK
- *
- * The reader can be found on eBay for around 5 dollars. Search for "mf-rc522" on ebay.com.
+ *             MFRC522      Arduino       Arduino   Arduino
+ *             Reader/PCD   Uno           Mega      Nano v3
+ * Signal      Pin          Pin           Pin       Pin
+ * ------------------------------------------------------------
+ * RST/Reset   RST          9             5         D9
+ * SPI SS      SDA(SS)      10            53        D10
+ * SPI MOSI    MOSI         11 / ICSP-4   51        D11
+ * SPI MISO    MISO         12 / ICSP-1   50        D12
+ * SPI SCK     SCK          13 / ICSP-3   52        D13
  */

 #include <SPI.h>
 #include <MFRC522.h>

-#define SS_PIN 10
-#define RST_PIN 9
-MFRC522 mfrc522(SS_PIN, RST_PIN);        // Create MFRC522 instance.
+#define RST_PIN         9           // Configurable, see typical pin layout above
+#define SS_PIN          10          // Configurable, see typical pin layout above

+MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
+
+MFRC522::MIFARE_Key key;
+
+/**
+ * Initialize.
+ */
 void setup() {
-        Serial.begin(9600);        // Initialize serial communications with the PC
-        SPI.begin();                // Init SPI bus
-        mfrc522.PCD_Init();        // Init MFRC522 card
-        //Serial.println("Scan a MIFARE Classic PICC to demonstrate Value Blocks.");
+    Serial.begin(9600); // Initialize serial communications with the PC
+    SPI.begin();        // Init SPI bus
+    mfrc522.PCD_Init(); // Init MFRC522 card
+
+    // Prepare the key (used both as key A and as key B)
+    // using FFFFFFFFFFFFh which is the default at chip delivery from the factory
+    for (byte i = 0; i < 6; i++) {
+        key.keyByte[i] = 0xFF;
+    }
+
+    Serial.println("Scan a MIFARE Classic PICC to demonstrate read and write.");
+    Serial.print("Using key (for A and B):");
+    dump_byte_array(key.keyByte, MFRC522::MF_KEY_SIZE);
+    Serial.println();
+
+    Serial.println("BEWARE: Data will be written to the PICC, in sector #1");
 }

+/**
+ * Main loop.
+ */
 void loop() {
+    // Look for new cards
+    if ( ! mfrc522.PICC_IsNewCardPresent())
+        return;
+
+    // Select one of the cards
+    if ( ! mfrc522.PICC_ReadCardSerial())
+        return;
+
+    // Show some details of the PICC (that is: the tag/card)
+    Serial.print("Card UID:");
+    dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
+    Serial.println();
+    Serial.print("PICC type: ");
+    byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
+    Serial.println(mfrc522.PICC_GetTypeName(piccType));
+
+    // Check for compatibility
+    if (    piccType != MFRC522::PICC_TYPE_MIFARE_MINI
+        &&  piccType != MFRC522::PICC_TYPE_MIFARE_1K
+        &&  piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
+        Serial.println("This sample only works with MIFARE Classic cards.");
+        return;
+    }
+
+    // In this sample we use the second sector,
+    // that is: sector #1, covering block #4 up to and including block #7
+    byte sector         = 1;
+    byte blockAddr      = 4;
+    byte dataBlock[]    = {
+        0x01, 0x02, 0x03, 0x04, //  1,  2,   3,  4,
+        0x05, 0x06, 0x07, 0x08, //  5,  6,   7,  8,
+        0x08, 0x09, 0xff, 0x0b, //  9, 10, 255, 12,
+        0x0c, 0x0d, 0x0e, 0x0f  // 13, 14,  15, 16
+    };
+    byte trailerBlock   = 7;
+    byte status;
+    byte buffer[18];
+    byte size = sizeof(buffer);
+
+    // Authenticate using key A
+    Serial.println("Authenticating using key A...");
+    status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &key, &(mfrc522.uid));
+    if (status != MFRC522::STATUS_OK) {
+        Serial.print("PCD_Authenticate() failed: ");
+        Serial.println(mfrc522.GetStatusCodeName(status));
+        return;
+    }
+
+    // Show the whole sector as it currently is
+    Serial.println("Current data in sector:");
+    mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);
+    Serial.println();
+
+    // Read data from the block
+    Serial.print("Reading data from block "); Serial.print(blockAddr);
+    Serial.println(" ...");
+    status = mfrc522.MIFARE_Read(blockAddr, buffer, &size);
+    if (status != MFRC522::STATUS_OK) {
+        Serial.print("MIFARE_Read() failed: ");
+        Serial.println(mfrc522.GetStatusCodeName(status));
+    }
+    Serial.print("Data in block "); Serial.print(blockAddr); Serial.println(":");
+    dump_byte_array(buffer, 16); Serial.println();
+    Serial.println();
+
+    // Authenticate using key B
+    Serial.println("Authenticating again using key B...");
+    status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_B, trailerBlock, &key, &(mfrc522.uid));
+    if (status != MFRC522::STATUS_OK) {
+        Serial.print("PCD_Authenticate() failed: ");
+        Serial.println(mfrc522.GetStatusCodeName(status));
+        return;
+    }
+
+    // Write data to the block
+    Serial.print("Writing data into block "); Serial.print(blockAddr);
+    Serial.println(" ...");
+    dump_byte_array(dataBlock, 16); Serial.println();
+    status = mfrc522.MIFARE_Write(blockAddr, dataBlock, 16);
+    if (status != MFRC522::STATUS_OK) {
+        Serial.print("MIFARE_Write() failed: ");
+        Serial.println(mfrc522.GetStatusCodeName(status));
+    }
+    Serial.println();
+
+    // Read data from the block (again, should now be what we have written)
+    Serial.print("Reading data from block "); Serial.print(blockAddr);
+    Serial.println(" ...");
+    status = mfrc522.MIFARE_Read(blockAddr, buffer, &size);
+    if (status != MFRC522::STATUS_OK) {
+        Serial.print("MIFARE_Read() failed: ");
+        Serial.println(mfrc522.GetStatusCodeName(status));
+    }
+    Serial.print("Data in block "); Serial.print(blockAddr); Serial.println(":");
+    dump_byte_array(buffer, 16); Serial.println();

-        // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
-        MFRC522::MIFARE_Key key;
-        for (byte i = 0; i < 6; i++) {
-                key.keyByte[i] = 0xFF;
-        }
-        // Look for new cards
-        if ( ! mfrc522.PICC_IsNewCardPresent()) {
-                return;
-        }
+    // Check that data in block is what we have written
+    // by counting the number of bytes that are equal
+    Serial.println("Checking result...");
+    byte count = 0;
+    for (byte i = 0; i < 16; i++) {
+        // Compare buffer (= what we've read) with dataBlock (= what we've written)
+        if (buffer[i] == dataBlock[i])
+            count++;
+    }
+    Serial.print("Number of bytes that match = "); Serial.println(count);
+    if (count == 16) {
+        Serial.println("Success :-)");
+    } else {
+        Serial.println("Failure, no match :-(");
+        Serial.println("  perhaps the write didn't work properly...");
+    }
+    Serial.println();
+
+    // Dump the sector data
+    Serial.println("Current data in sector:");
+    mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);
+    Serial.println();

-        // Select one of the cards
-        if ( ! mfrc522.PICC_ReadCardSerial()) {
-                return;
-        }
-        // Now a card is selected. The UID and SAK is in mfrc522.uid.
-
-        // Dump UID
-        Serial.print("Card UID:");
-        for (byte i = 0; i < mfrc522.uid.size; i++) {
-                Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
-                Serial.print(mfrc522.uid.uidByte[i], HEX);
-        }
-        Serial.println();
+    // Halt PICC
+    mfrc522.PICC_HaltA();
+    // Stop encryption on PCD
+    mfrc522.PCD_StopCrypto1();
+}

-        // Dump PICC type
-        byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
-        Serial.print("PICC type: ");
-        Serial.println(mfrc522.PICC_GetTypeName(piccType));
-        if (        piccType != MFRC522::PICC_TYPE_MIFARE_MINI
-                &&        piccType != MFRC522::PICC_TYPE_MIFARE_1K
-                &&        piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
-                //Serial.println("This sample only works with MIFARE Classic cards.");
-                return;
-        }
-
-        // In this sample we use the second sector (ie block 4-7). the first sector is = 0
-        // scegliere settore di lettura da 0 = primo settore
-        byte sector         = 1;
-        // block sector 0-3(sector0) 4-7(sector1) 8-11(sector2)
-        // blocchi di scrittura da 0-3(sector0) 4-7(sector1) 8-11(sector2)
-        byte valueBlockA    = 4;
-        byte valueBlockB    = 5;
-        byte valueBlockC    = 6;
-        byte trailerBlock   = 7;
-        byte status;
-        // Authenticate using key A.
-        // avvio l'autentificazione A
-        //Serial.println("Authenticating using key A...");
-        status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &key, &(mfrc522.uid));
-        if (status != MFRC522::STATUS_OK) {
-                Serial.print("PCD_Authenticate() failed: ");
-                Serial.println(mfrc522.GetStatusCodeName(status));
-                return;
-        }
-        // Authenticate using key B.
-        // avvio l'autentificazione B
-        //Serial.println("Authenticating again using key B...");
-        status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_B, trailerBlock, &key, &(mfrc522.uid));
-        if (status != MFRC522::STATUS_OK) {
-                Serial.print("PCD_Authenticate() failed: ");
-                Serial.println(mfrc522.GetStatusCodeName(status));
-                return;
-        }
-
-        // Writing new value block A
-        // Scrivo i valori per il settore A
-        Serial.println("Writing new value block A(4) : the first of the sector TWO ");
-                byte value1Block[] = { 1,2,3,4,  5,6,7,8, 9,10,255,12,  13,14,15,16,   valueBlockA,~valueBlockA,valueBlockA,~valueBlockA };
-                status = mfrc522.MIFARE_Write(valueBlockA, value1Block, 16);
-                if (status != MFRC522::STATUS_OK) {
-                        Serial.print("MIFARE_Write() failed: ");
-                        Serial.println(mfrc522.GetStatusCodeName(status));
-                }
-        /*
-
-        // Writing new value block B
-        // Scrivo i valori per il settore B
-        Serial.println("Writing new value block B");
-                byte value2Block[] = { 255,255,255,255,  0,0,0,0, 0,0,0,0,  255,255,255,255,   valueBlockB,~valueBlockB,valueBlockB,~valueBlockB };
-                status = mfrc522.MIFARE_Write(valueBlockB, value2Block, 16);
-                if (status != MFRC522::STATUS_OK) {
-                        Serial.print("MIFARE_Write() failed: ");
-                        Serial.println(mfrc522.GetStatusCodeName(status));
-                }
-
-        // Writing new value block D
-        // Scrivo i valori per il settore C
-        Serial.println("Writing new value block C");
-                byte value3Block[] = { 255,255,255,255,  0,0,0,0, 0,0,0,0,  255,255,255,255,   valueBlockC,~valueBlockC,valueBlockC,~valueBlockC };
-                status = mfrc522.MIFARE_Write(valueBlockC, value3Block, 16);
-                if (status != MFRC522::STATUS_OK) {
-                        Serial.print("MIFARE_Write() failed: ");
-                        Serial.println(mfrc522.GetStatusCodeName(status));
-                }
-
-        */
-
-
-        Serial.println("Read block A(4) : the first of the sector TWO");
-        byte buffer[18];
-        byte size = sizeof(buffer);
-        // change this: valueBlockA , for read anather block
-        // cambiate valueBlockA per leggere un altro blocco
-        status = mfrc522.MIFARE_Read(valueBlockA, buffer, &size);
-        Serial.print("Settore : 0 Valore :");
-        Serial.println(buffer[0]);
-        Serial.print("Settore : 1 Valore :");
-        Serial.println(buffer[1]);
-        Serial.print("Settore : 2 Valore :");
-        Serial.println(buffer[2]);
-        Serial.print("Settore : 3 Valore :");
-        Serial.println(buffer[3]);
-        Serial.print("Settore : 4 Valore :");
-        Serial.println(buffer[4]);
-        Serial.print("Settore : 5 Valore :");
-        Serial.println(buffer[5]);
-        Serial.print("Settore : 6 Valore :");
-        Serial.println(buffer[6]);
-        Serial.print("Settore : 7 Valore :");
-        Serial.println(buffer[7]);
-        Serial.print("Settore : 8 Valore :");
-        Serial.println(buffer[8]);
-        Serial.print("Settore : 9 Valore :");
-        Serial.println(buffer[9]);
-        Serial.print("Settore :10 Valore :");
-        Serial.println(buffer[10]);
-        Serial.print("Settore :11 Valore :");
-        Serial.println(buffer[11]);
-        Serial.print("Settore :12 Valore :");
-        Serial.println(buffer[12]);
-        Serial.print("Settore :13 Valore :");
-        Serial.println(buffer[13]);
-        Serial.print("Settore :14 Valore :");
-        Serial.println(buffer[14]);
-        Serial.print("Settore :15 Valore :");
-        Serial.println(buffer[15]);
-
-
-
-        //byte value1Block[] = { 1,2,3,4,  5,6,7,8, 9,10,255,12,  13,14,15,16,   valueBlockA,~valueBlockA,valueBlockA,~valueBlockA };
-        if (
-        buffer[0]  == 1   &&
-        buffer[1]  == 2   &&
-        buffer[2]  == 3   &&
-        buffer[3]  == 4   &&
-        buffer[4]  == 5   &&
-        buffer[5]  == 6   &&
-        buffer[6]  == 7   &&
-        buffer[7]  == 8   &&
-        buffer[8]  == 9   &&
-        buffer[9]  == 10  &&
-        buffer[10] == 255 &&
-        buffer[11] == 12  &&
-        buffer[12] == 13  &&
-        buffer[13] == 14  &&
-        buffer[14] == 15  &&
-        buffer[15] == 16
-        ){
-
-        // sel a scrittura è uguale alla lettura allora e stato un successo !!
-        Serial.println("Read block A(4) : the first of the sector TWO : success");
-        Serial.println(":-)");
-
-        }else{
-
-         //  scrittura Fallita
-        Serial.println("Read block A(4) : the first of the sector TWO : no match - write don't work fine ");
-        Serial.println(":-( ");
-
-        }
-
-
-        // risponde successo
-        //Serial.println(mfrc522.GetStatusCodeName(status));
-
-        // Dump the result
-        //mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);
-
-        // Halt PICC
-        mfrc522.PICC_HaltA();
-
-        // Stop encryption on PCD
-        mfrc522.PCD_StopCrypto1();
-
-
+/**
+ * Helper routine to dump a byte array as hex values to Serial.
+ */
+void dump_byte_array(byte *buffer, byte bufferSize) {
+    for (byte i = 0; i < bufferSize; i++) {
+        Serial.print(buffer[i] < 0x10 ? " 0" : " ");
+        Serial.print(buffer[i], HEX);
+    }
 }


add LedMat.setPlane(8) in comment

add LedMat.setPlane(8) in comment

--- examples/movie_player/movie_player.ino
+++ examples/movie_player/movie_player.ino
@@ -1,24 +1,25 @@
 #include <SD.h>

-#include <Adafruit_GFX.h>				// https://github.com/adafruit/Adafruit-GFX-Library
-#include <Fontx.h>							// https://github.com/h-nari/Fontx
-#include <Humblesoft_GFX.h>			// https://github.com/h-nari/Humblesoft_GFX
-#include <Humblesoft_LedMat.h>	// https://github.com/h-nari/Humblesoft_LedMat
-#include <MoviePlayer.h>			  // included in Humblesoft_LedMat
+#include <Adafruit_GFX.h>       // https://github.com/adafruit/Adafruit-GFX-Library
+#include <Fontx.h>              // https://github.com/h-nari/Fontx
+#include <Humblesoft_GFX.h>     // https://github.com/h-nari/Humblesoft_GFX
+#include <Humblesoft_LedMat.h>  // https://github.com/h-nari/Humblesoft_LedMat
+#include <MoviePlayer.h>        // included in Humblesoft_LedMat

 uint8_t imgBuf[1024*8];
+// uint8_t imgBuf[1024*16];
 MoviePlayer moviePlayer;

 void error_printf(const char *fmt, ...)
 {
-	va_list ap;
-	char buf[80];
+  va_list ap;
+  char buf[80];

-	va_start(ap, fmt);
-	vsnprintf(buf,sizeof buf,fmt, ap);
-	va_end(ap);
-	Serial.print("Error:");
-	Serial.println(buf);
+  va_start(ap, fmt);
+  vsnprintf(buf,sizeof buf,fmt, ap);
+  va_end(ap);
+  Serial.print("Error:");
+  Serial.println(buf);
 }

 void setup(void)
@@ -26,22 +27,23 @@
   Serial.begin(115200);
   delay(100);
   Serial.println("\n\nReset:");
-
+
   Serial.println("Initialize");
   LedMat.begin(LMMT64x32s16,1,2);
-	LedMat.setImgBuf(imgBuf, sizeof(imgBuf));
-	LedMat.setBright(10);
-
-	LedMat.setTextWrap(true);
-	LedMat.clear();
-	LedMat.println("64x32");
-	LedMat.setTextColor("red");
-	LedMat.print("R");
-	LedMat.setTextColor("green");
-	LedMat.print("G");
-	LedMat.setTextColor("blue");
-	LedMat.println("B");
-	LedMat.display();
+  LedMat.setImgBuf(imgBuf, sizeof(imgBuf));
+  LedMat.setBright(10);                     // set led brightness 1 .. 100
+  //  LedMat.setPlane(8);
+
+  LedMat.setTextWrap(true);
+  LedMat.clear();
+  LedMat.println("64x32");
+  LedMat.setTextColor("red");
+  LedMat.print("R");
+  LedMat.setTextColor("green");
+  LedMat.print("G");
+  LedMat.setTextColor("blue");
+  LedMat.println("B");
+  LedMat.display();
 }

 int  cnt;
@@ -49,36 +51,36 @@

 void set_next_file()
 {
-	if(!dir){
-		dir = SD.open("/");
-		if(!dir)
-			LedMat.error("open SD failed");
-		dir.rewindDirectory();
-		cnt = 0;
-	}
-	else {
-		File f = dir.openNextFile();
-		if(f){
-			Serial.printf("file:%s\n",f.name());
-			String filename = f.name();
-			if(filename.endsWith(".HLM")){
-				if(moviePlayer.begin(f.name()))
-					cnt++;
-			}
-			f.close();
-		}
-		else {
-			dir.close();
-			if(!cnt)
-				LedMat.error("no movie file found.");
-		}
-	}
+  if(!dir){
+    dir = SD.open("/");
+    if(!dir)
+      LedMat.error("open SD failed");
+    dir.rewindDirectory();
+    cnt = 0;
+  }
+  else {
+    File f = dir.openNextFile();
+    if(f){
+      Serial.printf("file:%s\n",f.name());
+      String filename = f.name();
+      if(filename.endsWith(".HLM")){
+        if(moviePlayer.begin(f.name()))
+          cnt++;
+      }
+      f.close();
+    }
+    else {
+      dir.close();
+      if(!cnt)
+        LedMat.error("no movie file found.");
+    }
+  }
 }

 void loop(void){
-	LedMat.checkSubcon();		/* 電源電圧降下によるサブCPUリセットの監視と再設定 */
-	if(!moviePlayer.update())
-		set_next_file();
+  LedMat.checkSubcon();   /* 電源電圧降下によるサブCPUリセットの監視と再設定 */
+  if(!moviePlayer.update())
+    set_next_file();
 }


Correct ASCII printing when group i s 0

Correct ASCII printing when group i s 0

Decode node letter from first byte of payload - fudging the true hex
value!

--- examples/RF12/RF12demo/RF12demo.ino
+++ examples/RF12/RF12demo/RF12demo.ino
@@ -943,7 +943,13 @@
     Serial.println();

   if (useHex > 1) {  // Print ascii interpretation under hex output
-    Serial.print("ASCII ");
+    Serial.print("ASC");
+    if (config.group == 0) {
+      Serial.print("II  ");
+    }
+    Serial.print(" .");
+    Serial.print(char((rf12_hdr & RF12_HDR_MASK) | 0x40)); // Convert node number into a letter, A to Z to undersore (1-31)
+
     for (byte i = 0; i < n; ++i) {
       if ((rf12_data[i] < 32) || (rf12_data[i] > 126))
         {


Support 38k4 serial on T84

Support 38k4 serial on T84

The bitdelay value of 11 was derived empirically - it works on my T84.

--- examples/RF12/RF12demo/RF12demo.ino
+++ examples/RF12/RF12demo/RF12demo.ino
@@ -38,7 +38,7 @@
 ///  All right reserved.
 /// Connect Tiny84 PA0 to USB-BUB TXD for serial input to sketch.
 /// 9600 at present!
-#define SERIAL_BAUD 9600
+#define SERIAL_BAUD 38400
 #define MAX_NODES 14
 #else
 #define SERIAL_BAUD 57600
@@ -1039,6 +1039,12 @@
     if (nodes[i] != 0xFF)
       nodes[i] = 0;   // No post waiting for node.
     }
+#if SERIAL_BAUD == 9600
+#define BITDELAY 54      // 9k6 @ 8MHz, 19k2 @16MHz
+#endif
+#if SERIAL_BAUD == 38400
+#define BITDELAY 11     // 38k4 @ 8MHz, 76k8 @16MHz
+#endif
 #if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
   delay(1000);            // Delay on startup to avoid ISP/RFM12B interference.
   PCMSK0 |= (1<<PCINT0);  // tell pin change mask to listen to PA0
@@ -1046,7 +1052,7 @@
   whackDelay(_bitDelay*2); // if we were low this establishes the end
   pinMode(_receivePin, INPUT);      // PA0
   digitalWrite(_receivePin, HIGH);  // pullup!
-  _bitDelay = 54;   // 9k6 @ 8MHz, 19k2 @16MHz
+  _bitDelay = BITDELAY;
 #else
   activityLed(1);
 #endif


Delete sensorflare-relayboard.ino

Delete sensorflare-relayboard.ino

--- examples/sensorflare-relayboard.ino
+++ examples/sensorflare-relayboard.ino
@@ -1,26 +0,0 @@
-//Include the SensorFlare library
-#include "sensorflare.h"
-
-//Initialize objects from the library
-//One object of the class "DigitalOut" is initialized for
-//every digital output that will be remote control
-SensorFlare::DigitalOut outputPin1(D1);
-SensorFlare::DigitalOut outputPin2(D2);
-SensorFlare::DigitalOut outputPin3(D3);
-SensorFlare::DigitalOut outputPin4(D4);
-
-void setup() {
-
-// Call the begin() functions for every object of the classes "DigitalOut" and
-//"PWMout" to be wired up correct and available.
-    outputPin1.begin();
-    outputPin2.begin();
-    outputPin3.begin();
-    outputPin4.begin();
-
-}
-
-void loop() {
-
-
-}


Update EndNode_17_fioV3_Awing.ino

Update EndNode_17_fioV3_Awing.ino

--- Arduino/EndNode_17_fioV3_Awing/EndNode_17_fioV3_Awing.ino
+++ Arduino/EndNode_17_fioV3_Awing/EndNode_17_fioV3_Awing.ino
@@ -1,7 +1,7 @@
 /*
   CONFIGURATION for ENDNODE PCB
-  25/04/2019
-  Version 17.0 XX
+  30/04/2019
+  Version 17.1 XX
   Author: Franco Parenti
   Url:
   Support for Arduino Fio V3, Arduino Leonardo
@@ -131,6 +131,8 @@

 #define AWNINGUP      39
 #define AWNINGDOWN    40
+#define AWNINGSTOP    41
+#define AWRUNTIME     15000 //time to keep the command on

 #define SONY      1
 #define SAMSUNG   2
@@ -350,9 +352,11 @@
     else
     { //read sensors
       sensors[i][1] = analogRead(sensors[i][0]);
-      //Serial.print(sensors[i][0]);
-      //Serial.print(" ");
-      //Serial.println(sensors[i][1]);
+      //if (i == 0 || i == 1) {
+        //Serial.print(sensors[i][0]);
+        //Serial.print(" ");
+        //Serial.println(sensors[i][1]);
+      //}
     }
   }

@@ -674,6 +678,7 @@
       // Sensors data
       for (int i = 0; i < NUM_DATA; i++)
       {
+        delay(1); //to avoid reading wrong values
         xbeeData[idx] = sensors[i][0]; //sensor number
         idx++;
         xbeeData[idx] = sensors[i][1]; //value
@@ -704,7 +709,6 @@
   /* begin the common part */
   xbee.send(tx);
   xbee.readPacket(500);
-
   if (xbee.getResponse().isAvailable()) //got something
   {
     log(7);
@@ -807,30 +811,45 @@
         case AWNINGUP:
           Serial.println("up");
           //attivo relay di salita
-          if (sensors[0][1] == 0 || sensors[1][1] == 0) {
-            tone(8, 4500, 100);
-            digitalWrite(14, HIGH); //relay per impostare up/down up=HIGH down=LOW (1 tenda)
-            delay(500);
-            digitalWrite(11, HIGH); //relay per impostare up/down up=HIGH down=LOW (1 tenda)
-            delay(500);
-            digitalWrite(10, HIGH); //Attiva il comando (fase/neutro)
-          }
+          if (awning_started == false) {
+            if (sensors[0][1] == 0 || sensors[1][1] == 0) {
+              tone(8, 4500, 100);
+              digitalWrite(14, HIGH); //relay per impostare up/down up=HIGH down=LOW (1 tenda)
+              digitalWrite(11, HIGH); //relay per impostare up/down up=HIGH down=LOW (1 tenda)
+              digitalWrite(10, HIGH); //Attiva il comando (fase/neutro)
+              awning_started = true;
+              awning_starttime = millis();
+            }
+          }
+          else {
+            Serial.println("altro comando in esecuzione");
+          }
+          break;
+        case AWNINGSTOP:
+          digitalWrite(10, LOW); //Attiva il comando (fase/neutro)
+          digitalWrite(11, LOW); //relay per impostare up/down up=HIGH down=LOW (1 tenda)
+          digitalWrite(14, LOW); //relay per impostare up/down up=HIGH down=LOW (1 tenda)
+          awning_started = false;
+          tone(8, 4500, 100);
           break;
         case AWNINGDOWN:
           Serial.println("down");
           //attivo relay di discesa
-          if (sensors[0][1] == 0 || sensors[1][1] == 0) {
-            tone(8, 4500, 100);
-            digitalWrite(14, LOW); //relay per impostare up/down up=HIGH down=LOW (1 tenda)
-            delay(500);
-            digitalWrite(11, LOW); //relay per impostare up/down up=HIGH down=LOW (1 tenda)
-            delay(500);
-            digitalWrite(10, HIGH); //Attiva il comando (fase/neutro)
-          }
-          break;
-      }
-      awning_started = true;
-      awning_starttime = millis();
+          if (awning_started == false) {
+            if (sensors[0][1] == 0 || sensors[1][1] == 0) {
+              tone(8, 4500, 100);
+              digitalWrite(14, LOW); //relay per impostare up/down up=HIGH down=LOW (1 tenda)
+              digitalWrite(11, LOW); //relay per impostare up/down up=HIGH down=LOW (1 tenda)
+              digitalWrite(10, HIGH); //Attiva il comando (fase/neutro)
+              awning_started = true;
+              awning_starttime = millis();
+            }
+          }
+          else {
+            Serial.println("altro comando in esecuzione");
+          }
+          break;
+      }
       break;

     case SERVO:  //analog
@@ -980,19 +999,6 @@
       break;
 #endif

-      /*
-          case LEDRGB:  // TV
-
-            convertColors(RxData[4]);
-
-            for (uint16_t i = 0; i < LEDCOUNT; i++)
-            {
-              colors[i] = color;
-            }
-        //      ledStrip.write(colors, LEDCOUNT);
-
-            break;
-      */
   }
   actuators[actuatorId][3] = sts; //set the actuator value

@@ -1086,48 +1092,23 @@
   Serial.println( msg[num]);
 }

-/*
-  void convertColors(long c)
-  {
-
-  String x = String(c, HEX);
-
-  long number = (long) strtol( &x[0], NULL, 16);
-  byte r = number >> 16;
-  byte g = number >> 8 & 0xFF;
-  byte b = number & 0xFF;
-
-  Serial.println(r , HEX);
-  Serial.println(g , HEX);
-  Serial.println(b , HEX);
-
-  //color.red = g; //verde
-  //color.green = b; //blu
-  //color.blue = r; //rosso
-
-  }
-*/
-
 void checkAwinig()
 {
   if (awning_started == true) {
-    if (millis() - 15000 > awning_starttime) {
+    if (millis() - AWRUNTIME > awning_starttime) {
       digitalWrite(10, LOW); //Disattiva il comando (fase/neutro)
-      delay(500);
       digitalWrite(11, LOW); //disattiva led tenda 1
-      delay(500);
       digitalWrite(14, LOW); //disattiva led tenda 2
       awning_started = false;
       tone(8, 4500, 100);
-      delay(400);
-      tone(8, 4500, 100);
     }
   }
   else if (awning_started == false) {
-    if (sensors[0][1] != 0 || sensors[1][1] != 0) {
+    if (sensors[0][1] == 1023 || sensors[1][1] == 1023) {
       digitalWrite(10, LOW); //Disattiva il comando (fase/neutro)
       digitalWrite(11, LOW); //disattiva led tenda 1
       digitalWrite(14, LOW); //disattiva led tenda 2
+      tone(8, 4500, 100);
     }
   }
 }


moved repeat to loop()

moved repeat to loop()

--- Arduino/TurquoiseBicuspid.ino
+++ Arduino/TurquoiseBicuspid.ino
@@ -7,13 +7,14 @@
 String BUFFSTORE = "";
 char DELIMETER = ':';
 int LED = 13;
+int TIME_START = 0;

 // Defaults
-String TYPE = "blink";
-int TIME = 100;  // 500, 250, 100, 50 (milliseconds)
-int LOOP = 3;    // 3, 2, 1
-int REPT = 15000;   // 30000, 15000, 5000, 3000 (milliseconds)
-boolean REPEATING = true;
+String TYPE = "blink";   // blink, pulse
+int TIME = 100;          // 500, 250, 100, 50 (milliseconds)
+int LOOP = 3;            // 3, 2, 1
+int REPT = 15000;        // 30000, 15000, 5000, 3000 (milliseconds)
+boolean REPEATING = false;

 void setup()
 {
@@ -27,6 +28,8 @@
    btSerial.write("AT+BAUD4");
    btSerial.write("AT+NAMETurquoiseBicuspid");
    btSerial.write("AT+PIN1234");
+
+   TIME_START = millis();
 }

 void loop()
@@ -39,12 +42,13 @@
   if(btSerial.available()) {
     while(btSerial.available()) {
       BUFFER += (char)btSerial.read();
+      delay(1);
     }
     BUFFSTORE = BUFFER;

     Serial.println("BUFFER: "+BUFFER);
     String buff = "";
-    int parsed = 0;
+    int index = 0;
     for(int i=0; i<BUFFER.length(); i++) {
       // copy buffer
       buff += BUFFER[i];
@@ -56,17 +60,17 @@

       // get a value
       if(BUFFER[i+1] == ':') {
-        if(parsed == 0) {
+        if(index == 0) {
           type = buff;
-          parsed++;
+          index++;
         }
-        else if(parsed == 1) {
+        else if(index == 1) {
           looper = buff.toInt();
-          parsed++;
+          index++;
         }
-        else if(parsed == 2) {
+        else if(index == 2) {
           time = buff.toInt();
-          parsed++;
+          index++;
         }
         buff = "";
       }
@@ -74,11 +78,11 @@
       // get last value
       if(i == (BUFFER.length()-1)) {
         repeat = buff.toInt();
+        REPEATING = true;
       }
     }
     BUFFER = "";

-    // type+":"+loop+":"+time+":"+repeat
     Serial.println(type+":"+looper+":"+time+":"+repeat);
     btSerial.write(time);

@@ -88,17 +92,23 @@
     // loop[1, 2, 3]
     // rept[30, 15, 5, 3]
     if(type == "blink") {
-      //blink(looper, time);
-      repeater(looper, time, repeat);
+      blink(looper, time);
     }
     else if(type == "pulse") {
-      //blink(looper, time);
-      repeater(looper, time, repeat);
+      blink(looper, time);
     }
     else {
-      // error in data, perform default
-      //blink(looper, time);
-      repeater(looper, time, repeat);
+      blink(looper, time);
+    }
+  }
+
+  int time_end = millis();
+  int time_diff = time_end - TIME_START;
+  if(time_diff > 5000) {
+    TIME_START = millis();
+    if(REPEATING) {
+      Serial.println("repeat");
+      blink(looper, time);
     }
   }

@@ -129,22 +139,3 @@
 void pulse(int looper, int time) {
   // same as above, but with pwm
 }
-
-// reapeat - repeats a function
-// params:
-//   looper: int - amount of times to blink the LED
-//   time: int - milliseconds to blink
-//   rept: int - milliseconds to call function
-void repeater(int looper, int time, int rept) {
-  int start = millis();
-
-  while(REPEATING == true) {
-    int current = millis();
-    int diff = current - start;
-    Serial.println(diff);
-    if(diff > rept) {
-      blink(looper, time);
-      start = millis();
-    }
-  }
-}


some cleanup

some cleanup

--- grill.ino
+++ grill.ino
@@ -39,11 +39,9 @@
       pid.SetMode(AUTOMATIC);
     }
     if (output == 0 || output == 255) {
-      if (pid.GetKi() != 0) {
-        pid.SetTunings(P, 0, D);
-      }
-    } else if (pid.GetKi() != I) {
-      pid.SetTunings(P, I, D);
+      setI(0);
+    } else {
+      setI(I);
     }
     pid.Compute();
     fan.powerTo(output);
@@ -51,3 +49,9 @@

   delay(50);
 }
+
+void setI(double i) {
+  if (pid.GetKi() != i) {
+    pid.SetTunings(P, i, D);
+  }
+}


Correct display segment bits

Correct display segment bits

The mapping of bits to specific segments of the display changed
from the prototype circuit when the PCB design was created.  This
corrects the mapping so the display works properly for the circuit
shown in the schematic and the PCB design.

--- firmware/removinator/removinator.ino
+++ firmware/removinator/removinator.ino
@@ -47,8 +47,8 @@
 #define LOG_DBG_PREFIX "[DBG] "

 // Constants
-const byte display_digits[] = { 0x88, 0xDB, 0xA2, 0x92, 0xD1,
-                                0x94, 0x84, 0xDA, 0x80, 0x90 };
+const byte display_digits[] = { 0x84, 0xD7, 0xA1, 0x91, 0xD2,
+                                0x98, 0x88, 0xD5, 0x80, 0x90 };
 const int mux_en_pin = 2;
 const int mux_a0_pin = 3;
 const int mux_a1_pin = 4;
@@ -339,10 +339,10 @@
 // the LSB and output 'H' is controlled by the MSB.  The shift register
 // outputs are connected to the 7-segment display as follows:
 //
-//       A
+//       B
 //     -----
-//   B |   | C
-//   D -----
+//   A |   | D
+//   C -----
 //   E |   | F
 //     -----
 //       G


adds temp monitoring from the humidity sensor

--- embed-code/embed-code.ino
+++ embed-code/embed-code.ino
@@ -67,6 +67,7 @@
       float objt = tmp007.readObjTempC();
       float diet = tmp007.readDieTempC();
       float hum = htu.readHumidity();
+      float hum_temp = htu.readTemperature();

       DateTime now = rtc.now();
       //long seconds = now.secondstime();
@@ -80,6 +81,8 @@
         logfile.print(diet);
         logfile.print(", ");
         logfile.print(hum);
+        logfile.print(", ");
+        logfile.print(hum_temp);
         logfile.println();
         logfile.close();

@@ -92,7 +95,9 @@
       Serial.print(", ");
       Serial.print(diet);
       Serial.print(", ");
-      Serial.print(hum);
+      Serial.print(hum);
+      Serial.print(", ");
+      Serial.print(hum_temp);
       Serial.println(" ");

   }


Making EEPROM optional

Making EEPROM optional

--- BiblioPixelSerialReceiver.ino
+++ BiblioPixelSerialReceiver.ino
@@ -5,13 +5,19 @@
 If using "SmartMatrix" style panels checkout:
 https://github.com/ManiacalLabs/BiblioPixelSmartMatrix
 **********************************/
-
 #include "FastLED.h"
-#include <EEPROM.h>

 /****************************
 All Firmware options go here!
 ****************************/
+// Comment out below line if EEPROM unavailable on your board
+#define USE_EEPROM
+
+// If not using EEPROM, you can specify device ID here
+#ifndef USE_EEPROM
+    const uint8_t deviceID = 0;
+#endif
+
 // How many leds in your strip?
 #define NUM_LEDS 8 * 8

@@ -25,6 +31,10 @@
 /***************************
 End Firmware options
 ***************************/
+
+#ifdef USE_EEPROM
+    #include <EEPROM.h>
+#endif

 #define FIRMWARE_VER 3

@@ -137,7 +147,11 @@
         }
         else if(cmd == CMDTYPE::GETID)
         {
-            Serial.write(EEPROM.read(16));
+            #ifdef USE_EEPROM
+                Serial.write(EEPROM.read(16));
+            #else
+                Serial.write(deviceID);
+            #endif
         }
         else if(cmd == CMDTYPE::SETID)
         {
@@ -148,7 +162,9 @@
             else
             {
                 uint8_t id = Serial.read();
-                EEPROM.write(16, id);
+                #ifdef USE_EEPROM
+                    EEPROM.write(16, id);
+                #endif
                 Serial.write(RETURN_CODES::SUCCESS);
             }
         }


Add beeper to arduino

Add beeper to arduino

--- DigitalInOut/DigitalInOut.ino
+++ DigitalInOut/DigitalInOut.ino
@@ -15,11 +15,16 @@
 int bNoPins = sizeof(bPins)/sizeof(int);
 int SAMPLES_PER_SECOND = 20;

+int beepPin = 10;
 int buttonPin = 12;
+boolean beeping = 0;
+int counter = 0;

 void setup() {
   // initialize serial communications at 9600 bps:
   Serial.begin(9600);
+  pinMode(beepPin, OUTPUT);
+  digitalWrite(beepPin, LOW);
   // set pin modes for digital pins
   for(int i = 0; i < dNoPins; i++){
     pinMode(dPins[i], INPUT);
@@ -61,7 +66,20 @@
   // wait
   // for the analog-to-digital converter to settle
   // after the last reading:
-  delay(1000/SAMPLES_PER_SECOND);
+  if (beeping && counter > 10)
+  {
+  digitalWrite(beepPin, HIGH);
+  beeping = 0;
+  counter = 0;
+}
+  else if (counter > 10)
+  {
+  digitalWrite(beepPin, LOW);
+  beeping = 1;
+  counter = 0;
+}
+counter++;
+  delay(1000/SAMPLES_PER_SECOND);
 }

 /**


Minor comment tweak

Minor comment tweak

Edited comments to be more specific

--- EPROM_Dumper/EPROM_Dumper.ino
+++ EPROM_Dumper/EPROM_Dumper.ino
@@ -5,9 +5,9 @@
 {
    Serial.begin(9600); // Opens Serial Port to receive data

-   DDRL = B00000000;  //Sets up L-pins as 8-bit input A + C as 16 bit output
-   DDRA = B11111111;  //Lower address
-   DDRC = B11111111;  //Upper address
+   DDRL = B00000000;  //Sets up L register pins as 8-bit input
+   DDRA = B11111111;  //Lower address (A register pins)
+   DDRC = B11111111;  //Upper address (C register pins)

    PORTA = B00000000; //Sets output data on pin register A as 0
    PORTC = B00000000; //Sets output data on pin register C as 0


replaced scheduleTimers() by yield() call in loop() function in the Examples/Blink_with_Timer.ino

--- Examples/Blink_with_Timer.ino
+++ Examples/Blink_with_Timer.ino
@@ -27,6 +27,6 @@
 // The loop function is called in an endless loop
 void loop()
 {
-  scheduleTimers();
+  yield();
 }
-  +


use one button to control bell

use one button to control bell

--- keypad/keypad.ino
+++ keypad/keypad.ino
@@ -142,6 +142,8 @@
   3, 3, 3
 };

+  int count=0;
+
 void setup()
 {
   pinMode(ledpin,OUTPUT);
@@ -247,11 +249,13 @@

         break;
       case '*':
-//        digitalWrite(ledpin, LOW);
-        analogWrite(motorPin, 200);
+        count++;
+        if (count%2==1)
+            analogWrite(motorPin, 200);
+        else
+            analogWrite(motorPin, 0);
         break;
       case '#':
-//        digitalWrite(ledpin, HIGH);
         analogWrite(motorPin, 0);
         break;
       default:


led blink

led blink

--- led_ir/led_ir.ino
+++ led_ir/led_ir.ino
@@ -8,6 +8,7 @@
         RED_PIN = 9,
         GREEN_PIN = 10,
         BLUE_PIN = 8,
+        LED_PIN = 13,
 };

 #define MS(ms) ((int)((ms*16000L)/1024L))
@@ -233,6 +234,7 @@
         pinMode(RED_PIN, OUTPUT);
         pinMode(GREEN_PIN, OUTPUT);
         pinMode(BLUE_PIN, OUTPUT);
+        pinMode(LED_PIN, OUTPUT);

         TCCR1A = 0;
         TCCR1B = 5;
@@ -276,6 +278,7 @@
                 Serial.print(command2string(cmd));
                 Serial.println(rep ? " (repeated)" : "");
         }
+        digitalWrite(LED_PIN, cmd);

         float elapsed = timer3() * (1024 / 1.6e7);
         time += elapsed;
@@ -369,6 +372,7 @@
                 a_v = 0.4;
                 mode = MODE_STATIC;
                 break;
+        case LIGHT_ON:
         case LIGHT_SMOOTH:
                 if (!rep) {
                         mode = MODE_SMOOTH;


Brighten more quickly than dim, to get a nicer tail; if tails overlap then mix the hue---otherwise directly use the head hue

--- MatrixEffect/MatrixEffect.ino
+++ MatrixEffect/MatrixEffect.ino
@@ -32,14 +32,23 @@
   // We do not need to use the array structure here---just copy some values
   for(uint8_t i_led=0; i_led<NUM_LEDS; ++i_led){
     // First do a FO low-pass between new_colors and colors (in HSV space)
-    // Actually, for this effect, copy the hue and saturation directly,
-    // and only do FO low-pass on value (lightness)
-    colors[i_led].h = new_colors[i_led].h;
+
+    // If the led is currently on,  do a low-pass filter on the hue, to blend overlapping tail colours; otherwise simply copy the new hue, to prevent a grey-ish "head"
+    if(colors[i_led].v > 20)
+      colors[i_led].h = (uint8_t) (((uint16_t) colors[i_led].h*9 + new_colors[i_led].h)/10);
+    else
+      colors[i_led].h = new_colors[i_led].h;
+
+    // saturation is always maximal right now, anyway simply copy it
     colors[i_led].s = new_colors[i_led].s;
-    colors[i_led].v = (uint8_t) (((uint16_t) colors[i_led].v*19 + new_colors[i_led].v)/20);
-    // colors[i_led].v = new_colors[i_led].v;

-    // Then copy the current HSV value to the current RGB value
+    // Then, value/brightness: brighten more quickly than dim
+    if(new_colors[i_led].v > colors[i_led].v)
+      colors[i_led].v = (uint8_t) (((uint16_t) colors[i_led].v*9 + new_colors[i_led].v)/10);
+    else
+      colors[i_led].v = (uint8_t) (((uint16_t) colors[i_led].v*19 + new_colors[i_led].v)/20);
+
+    // Finally copy the current HSV value to the current RGB value
     leds[i_led] = colors[i_led];
   }

@@ -79,7 +88,7 @@
         new_colors[xy2i(x,y)] = new_colors[xy2i(x,y-1)];
       } else {
         // If off, turn the pixel off (the actual pixel colour has a FO low-pass filter)
-        // Leave the hue and saturation intact
+        // Leave the hue and saturation intact: they are not used in the interpolation
         new_colors[xy2i(x,y)].v = 0;
       }
     }
@@ -89,7 +98,7 @@
   for(uint8_t x=0; x<COLS; ++x){
     //first row -> turn off the off pixels after propagation of colour
     if(!onPixels[0][x]){
-      new_colors[xy2i(x,0)].v = 0; //leave H and S value
+      new_colors[xy2i(x,0)].v = 0; //leave H and S value, since we're not using that for interpolation
     }
   }
 }
@@ -100,7 +109,7 @@
   // Let the controller know we're using WS2801 leds, and give a pointer to the current colour array
   LEDS.addLeds<WS2801, RGB>(leds, NUM_LEDS);
   // Limit the brightness somewhat (scale is 0-255)
-  LEDS.setBrightness(200);
+  LEDS.setBrightness(127);

   // Initialise the leds to black (off)
   for(uint8_t i=0; i<NUM_LEDS; ++i){


i hear Woodi again

i hear Woodi again

--- discont/Motor_Shield/MotorShield/MotorShield.ino
+++ discont/Motor_Shield/MotorShield/MotorShield.ino
@@ -89,6 +89,9 @@
   lastLoopTime = millis();
   dT_sec = millis();

+  //setPwmFrequency(6,1);
+  //setPwmFrequency(9,1);
+
   Serial.println();
   Serial.flush();
   Serial.println("Ready");
@@ -119,7 +122,7 @@
     Serial.print(dT_sec);
     Serial.print('\n');
   }
-
+  /*
   //Serial.println(tickDataLeft);
   if( millis() - lastCmdTime > 500)
   {
@@ -129,7 +132,7 @@
     PWM_L = 0;
     PWM_R = 0;
   }
-
+  */
   dT_sec = (float)( millis() - lastLoopTime ) / 1000.0;
   lastLoopTime = millis();
   actualSpeedL = ( metersPerTick * tickDataLeft ) / dT_sec;
@@ -177,7 +180,7 @@
   analogWrite(rightSpeed, powerR);
   analogWrite(leftSpeed, powerL);

-  //lastErrorL = ErrorL;
+  lastErrorL = ErrorL;
   lastErrorR = ErrorR;
 }

@@ -205,3 +208,65 @@
   }
 }

+/**
+ * Divides a given PWM pin frequency by a divisor.
+ *
+ * The resulting frequency is equal to the base frequency divided by
+ * the given divisor:
+ *   - Base frequencies:
+ *      o The base frequency for pins 3, 9, 10, and 11 is 31250 Hz.
+ *      o The base frequency for pins 5 and 6 is 62500 Hz.
+ *   - Divisors:
+ *      o The divisors available on pins 5, 6, 9 and 10 are: 1, 8, 64,
+ *        256, and 1024.
+ *      o The divisors available on pins 3 and 11 are: 1, 8, 32, 64,
+ *        128, 256, and 1024.
+ *
+ * PWM frequencies are tied together in pairs of pins. If one in a
+ * pair is changed, the other is also changed to match:
+ *   - Pins 5 and 6 are paired on timer0
+ *   - Pins 9 and 10 are paired on timer1
+ *   - Pins 3 and 11 are paired on timer2
+ *
+ * Note that this function will have side effects on anything else
+ * that uses timers:
+ *   - Changes on pins 3, 5, 6, or 11 may cause the delay() and
+ *     millis() functions to stop working. Other timing-related
+ *     functions may also be affected.
+ *   - Changes on pins 9 or 10 will cause the Servo library to function
+ *     incorrectly.
+ *
+ * Thanks to macegr of the Arduino forums for his documentation of the
+ * PWM frequency divisors. His post can be viewed at:
+ *   http://forum.arduino.cc/index.php?topic=16612#msg121031
+ */
+void setPwmFrequency(int pin, int divisor) {
+  byte mode;
+  if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
+    switch(divisor) {
+      case 1: mode = 0x01; break;
+      case 8: mode = 0x02; break;
+      case 64: mode = 0x03; break;
+      case 256: mode = 0x04; break;
+      case 1024: mode = 0x05; break;
+      default: return;
+    }
+    if(pin == 5 || pin == 6) {
+      TCCR0B = TCCR0B & 0b11111000 | mode;
+    } else {
+      TCCR1B = TCCR1B & 0b11111000 | mode;
+    }
+  } else if(pin == 3 || pin == 11) {
+    switch(divisor) {
+      case 1: mode = 0x01; break;
+      case 8: mode = 0x02; break;
+      case 32: mode = 0x03; break;
+      case 64: mode = 0x04; break;
+      case 128: mode = 0x05; break;
+      case 256: mode = 0x06; break;
+      case 1024: mode = 0x07; break;
+      default: return;
+    }
+    TCCR2B = TCCR2B & 0b11111000 | mode;
+  }
+}


Minor Changes in Mag Auto Update

Minor Changes in Mag Auto Update

Minor

--- TeensyMagCal/TeensyMagCal.ino
+++ TeensyMagCal/TeensyMagCal.ino
@@ -138,54 +138,57 @@
 			// this needs to be run several times until it iterates to wards solution
 			// BETA
 			if (autoTune) {
-
-				magCal->m_magMaxAutoTune.data(0) = magCal->m_magMax.data(0);
-				magCal->m_magMaxAutoTune.data(1) = magCal->m_magMax.data(1);
-				magCal->m_magMaxAutoTune.data(2) = magCal->m_magMax.data(2);
-				magCal->m_magMinAutoTune.data(0) = magCal->m_magMin.data(0);
-				magCal->m_magMinAutoTune.data(1) = magCal->m_magMin.data(1);
-				magCal->m_magMinAutoTune.data(2) = magCal->m_magMin.data(2);
-
-				RTFLOAT l = compass.length();  // This should be same as FIELDSTRENGTH
-				RTFLOAT c = (FIELDSTRENGTH / l) - (FIELDSTRENGTH / l / l); // adjust calibration values (empirically)
-
-				if (imuData.compass.x() >= 0)
-					magCal->m_magMaxAutoTune.data(0) = ( (1.0 - compass_ALPHA) * magCal->m_magMaxAutoTune.data(0) + compass_ALPHA * (
-					magCal->m_magMaxAutoTune.data(0)* (1.0 + imuData.compass.x() * c) ));
-				else
-					magCal->m_magMinAutoTune.data(0) = ( (1.0 - compass_ALPHA) * magCal->m_magMinAutoTune.data(0) + compass_ALPHA * (
-					magCal->m_magMinAutoTune.data(0)* (1.0 + imuData.compass.x() * c) ));
-
-				if (imuData.compass.y() >= 0)
-					magCal->m_magMax.data(1) = ( (1.0 - compass_ALPHA) * magCal->m_magMax.data(1) + compass_ALPHA * (
-					magCal->m_magMax.data(1)* (1.0 + imuData.compass.y() * c) ));
-				else
-					magCal->m_magMinAutoTune.data(1) = ( (1.0 - compass_ALPHA) * magCal->m_magMinAutoTune.data(1) + compass_ALPHA * (
-					magCal->m_magMinAutoTune.data(1)* (1.0 + imuData.compass.y() * c) ));
-
-				if (imuData.compass.z() >= 0)
-					magCal->m_magMaxAutoTune.data(2) = ( (1.0 - compass_ALPHA) * magCal->m_magMaxAutoTune.data(2) + compass_ALPHA * (
-					magCal->m_magMaxAutoTune.data(2)* (1.0 + imuData.compass.z() * c) ));
-				else
-					magCal->m_magMinAutoTune.data(2) = ( (1.0 - compass_ALPHA) * magCal->m_magMinAutoTune.data(2) + compass_ALPHA * (
-					magCal->m_magMinAutoTune.data(2)* (1.0 + imuData.compass.z() * c) ));
-
-				maxDelta = -1;
-				for (int i = 0; i < 3; i++) {
-				  if ((magCal->m_magMaxAutoTune.data(i) - magCal->m_magMinAutoTune.data(i)) > maxDelta)
-					maxDelta = magCal->m_magMaxAutoTune.data(i) - magCal->m_magMinAutoTune.data(i);
-				}
-				maxDelta /= 2.0f;
-				for (int i = 0; i < 3; i++) {
-				  delta = (magCal->m_magMaxAutoTune.data(i) - magCal->m_magMinAutoTune.data(i)) / 2.0f;
-				  compassCalScaleAutoTune[i] = maxDelta / delta;            // makes everything the same range
-				  compassCalOffsetAutoTune[i] = (magCal->m_magMaxAutoTune.data(i) + magCal->m_magMinAutoTune.data(i)) / 2.0f;
-				}
-				compass.setX((imuData.compass.x() - compassCalOffsetAutoTune[0]) * compassCalScaleAutoTune[0]);
-				compass.setY((imuData.compass.y() - compassCalOffsetAutoTune[1]) * compassCalScaleAutoTune[1]);
-				compass.setZ((imuData.compass.z() - compassCalOffsetAutoTune[2]) * compassCalScaleAutoTune[2]);
-				Serial.println("-Autotune--");
-				Serial.printf("%s", RTMath::displayRadians("Compass Auto Calibrated:", compass));
+				if (updateMaxMin) {
+					Serial.println("You need to turn off Update Max/Min for auto tuning");
+				} else {
+					magCal->m_magMaxAutoTune.data(0) = magCal->m_magMax.data(0);
+					magCal->m_magMaxAutoTune.data(1) = magCal->m_magMax.data(1);
+					magCal->m_magMaxAutoTune.data(2) = magCal->m_magMax.data(2);
+					magCal->m_magMinAutoTune.data(0) = magCal->m_magMin.data(0);
+					magCal->m_magMinAutoTune.data(1) = magCal->m_magMin.data(1);
+					magCal->m_magMinAutoTune.data(2) = magCal->m_magMin.data(2);
+
+					RTFLOAT l = compass.length();  // This should be same as FIELDSTRENGTH
+					RTFLOAT c = (FIELDSTRENGTH / l) - (FIELDSTRENGTH / l / l); // adjust calibration values (empirically)
+
+					if (imuData.compass.x() >= 0)
+						magCal->m_magMaxAutoTune.data(0) = ( (1.0 - compass_ALPHA) * magCal->m_magMaxAutoTune.data(0) + compass_ALPHA * (
+						magCal->m_magMaxAutoTune.data(0)* (1.0 + imuData.compass.x() * c) ));
+					else
+						magCal->m_magMinAutoTune.data(0) = ( (1.0 - compass_ALPHA) * magCal->m_magMinAutoTune.data(0) + compass_ALPHA * (
+						magCal->m_magMinAutoTune.data(0)* (1.0 + imuData.compass.x() * c) ));
+
+					if (imuData.compass.y() >= 0)
+						magCal->m_magMax.data(1) = ( (1.0 - compass_ALPHA) * magCal->m_magMax.data(1) + compass_ALPHA * (
+						magCal->m_magMax.data(1)* (1.0 + imuData.compass.y() * c) ));
+					else
+						magCal->m_magMinAutoTune.data(1) = ( (1.0 - compass_ALPHA) * magCal->m_magMinAutoTune.data(1) + compass_ALPHA * (
+						magCal->m_magMinAutoTune.data(1)* (1.0 + imuData.compass.y() * c) ));
+
+					if (imuData.compass.z() >= 0)
+						magCal->m_magMaxAutoTune.data(2) = ( (1.0 - compass_ALPHA) * magCal->m_magMaxAutoTune.data(2) + compass_ALPHA * (
+						magCal->m_magMaxAutoTune.data(2)* (1.0 + imuData.compass.z() * c) ));
+					else
+						magCal->m_magMinAutoTune.data(2) = ( (1.0 - compass_ALPHA) * magCal->m_magMinAutoTune.data(2) + compass_ALPHA * (
+						magCal->m_magMinAutoTune.data(2)* (1.0 + imuData.compass.z() * c) ));
+
+					maxDelta = -1;
+					for (int i = 0; i < 3; i++) {
+					  if ((magCal->m_magMaxAutoTune.data(i) - magCal->m_magMinAutoTune.data(i)) > maxDelta)
+						maxDelta = magCal->m_magMaxAutoTune.data(i) - magCal->m_magMinAutoTune.data(i);
+					}
+					maxDelta /= 2.0f;
+					for (int i = 0; i < 3; i++) {
+					  delta = (magCal->m_magMaxAutoTune.data(i) - magCal->m_magMinAutoTune.data(i)) / 2.0f;
+					  compassCalScaleAutoTune[i] = maxDelta / delta;            // makes everything the same range
+					  compassCalOffsetAutoTune[i] = (magCal->m_magMaxAutoTune.data(i) + magCal->m_magMinAutoTune.data(i)) / 2.0f;
+					}
+					compass.setX((imuData.compass.x() - compassCalOffsetAutoTune[0]) * compassCalScaleAutoTune[0]);
+					compass.setY((imuData.compass.y() - compassCalOffsetAutoTune[1]) * compassCalScaleAutoTune[1]);
+					compass.setZ((imuData.compass.z() - compassCalOffsetAutoTune[2]) * compassCalScaleAutoTune[2]);
+					Serial.println("-Autotune--");
+					Serial.printf("%s", RTMath::displayRadians("Compass Auto Calibrated:", compass));
+				} // need to have Update Off for Autotune
 			} // autotune
         } // display
     } // imu read


Reduce time allowed in calibration sequence to 2.5 seconds per side.

--- sketch/CurieDice/CurieDice.ino
+++ sketch/CurieDice/CurieDice.ino
@@ -292,16 +292,17 @@
   int face[] = {5, 4, 2, 3, 1, 6};
   for (int i=0; i<6; i++) {
     int f = face[i];
-    pix.disp(orientDisp[f], 0xf00, 3000);
-    pix.disp(orientDisp[f], 0xf60, 2000);
+    pix.disp(orientDisp[f], 0xf00, 1250);
+    pix.disp(orientDisp[f], 0xf60, 1000);
     CurieIMU.readAccelerometer(vcurr[0], vcurr[1], vcurr[2]);
-    pix.disp(orientDisp[f], 0x0f0, 1000);
+    pix.disp(orientDisp[f], 0x0f0, 250);
     signed char *t = orientable[i];
     t[0] = (signed char)(vcurr[0]>>8);
     t[1] = (signed char)(vcurr[1]>>8);
     t[2] = (signed char)(vcurr[2]>>8);
     t[3] = (signed char) f;
   }
+  vibrate(50);
 }

 int16_t imuRead() {


Default is Arduino Uno

Default is Arduino Uno

--- Utils/BabelFish/BabelFish.ino
+++ Utils/BabelFish/BabelFish.ino
@@ -30,9 +30,9 @@
 // Select 1 of the preconfigured platforms:
 // (not every microcontroller platform supports all functions)
 //
-#define ArduinoUno   0 // Default
+#define ArduinoUno   1 // Default
 #define ArduinoNano  0
-#define ArduinoMicro 1
+#define ArduinoMicro 0
 #define ATtiny85     0

 // The object file is embedded (in PROGMEM) in GT1 format. It would be


Hiep hoi Reedsensor

Hiep hoi Reedsensor

--- WeatherBuddy/WeatherBuddy.ino
+++ WeatherBuddy/WeatherBuddy.ino
@@ -1,12 +1,12 @@
-// Code Bas,
+// start met code van Bas die niet werkte, uplouds github door mij (Iris), Beetje vieze code nog maar het weerstation staat ;)

 int pinSwitch = 12;  //Pin Reed
 int regenSensor = A1; // Regensensor aan analoge ingang 1, als regensor dan gaat led 9 (rood) branden
 int LED = 9; // LED aan pen 9 gaat aan als het sneeuwt of refent
-int reedLed = 10; // LED a
+int reedLed = 10; // LED voor de reed, groen
 int val = 0;  // = dus de regensensorwaarde
 int StatoSwitch = 0;
- // andere ledje direct in 5V geeft aan of hij aan is (rood)
+// andere ledje direct in 5V geeft aan of hij aan is (rood)

 void setup()
@@ -15,12 +15,12 @@
   pinMode(reedLed, OUTPUT);
   pinMode(pinSwitch, INPUT);
   pinMode(LED, OUTPUT);
+}

-
-}
 void loop() {
   val = analogRead(regenSensor);
-  if (val > 700) {
+  if (val > 700)
+  {
     digitalWrite(LED, LOW);
   }
   else {
@@ -30,7 +30,7 @@
   Serial.print(val);
   delay(400);

-
+
   StatoSwitch = digitalRead(pinSwitch);
   if (StatoSwitch == HIGH)
   {


delays

delays

--- master/master.ino
+++ master/master.ino
@@ -564,7 +564,7 @@
 	SPI.setSCK(14);
 	SPI.begin();

-	delay(200);
+	delay(1000);
 	tft.begin();
 	drawPiLogo();

@@ -593,7 +593,7 @@

 	digitalWrite(LED, HIGH);

-	delay(800);
+	//delay(800);
 	tft.println("Calibrating IMU offset");
 	calibIMUOffset();


horloge_cycles_ultradiens

--- files/horloge_cycles_ultradiens/horloge_cycles_ultradiens.ino
+++ files/horloge_cycles_ultradiens/horloge_cycles_ultradiens.ino
@@ -132,7 +132,7 @@
   // Cette procédure permet de régler l’heure de l’horloge
   // via le bus RS232.
   // Exemple de commande à envoyer :
-  // 2016,6,8,9,36,30
+  // 2016,6,8,11,18,20

   const byte nbCharMax = 19;
   char str[ nbCharMax ] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
@@ -276,11 +276,11 @@

   // Préparation de l’affichage du pourcentage du cycle
   display.setTextSize( 2 );
-  if( cycleAtt < 0.01 )
+  if( cycleAtt < 0.005 )
     { display.setCursor( 53, 21 ); display.print( cycleAtt, 0 ); }
-  else if( cycleAtt < 10 )
+  else if( cycleAtt < 9.995 )
     { display.setCursor( 34, 21 ); display.print( cycleAtt, 2 ); }
-  else if( cycleAtt < 99.5 )
+  else if( cycleAtt < 99.95 )
     { display.setCursor( 34, 21 ); display.print( cycleAtt, 1 ); }
   else
     { display.setCursor( 42, 21 ); display.print( cycleAtt, 0 ); }


cleanup

cleanup

--- testing/arduino/arm_with_trigger.ino
+++ testing/arduino/arm_with_trigger.ino
@@ -3,15 +3,19 @@

 // Servo
 Servo ServoMotor_Bottom;
-const uint8_t servoPin_Bottom = 3;
+const uint8_t servoBotttom_Pin = 3;
+uint16_t servoBottom_Pos = 90;

 Servo ServoMotor_Top;
-const uint8_t servoPin_Top = 6;
+const uint8_t servoTop_Pin = 6;
+uint16_t servoTop_Pos = 90;

 Servo ServoMotor_Trigger;
-const uint8_t servoPin_Trigger = 9;
+const uint8_t servoTrigger_Pin = 9;
+const uint16_t servoTrigger_Pos = 100;
+const uint16_t servoTrigger_PosShoot = 135;

-const uint8_t servoRotationAngel = 10;
+const uint8_t servoRotationStep = 10;

 // Joystick
@@ -24,27 +28,30 @@
 {
     pinMode(buttonSW, INPUT_PULLUP);

-    ServoMotor_Bottom.attach(servoPin_Bottom, 400, 2600);
-    ServoMotor_Bottom.write(90);
+    ServoMotor_Bottom.attach(servoBotttom_Pin, 400, 2600);
+    ServoMotor_Bottom.write(servoBottom_Pos);

-    ServoMotor_Top.attach(servoPin_Top, 400, 2600);
-    ServoMotor_Top.write(90);
+    ServoMotor_Top.attach(servoTop_Pin, 400, 2600);
+    ServoMotor_Top.write(servoTop_Pos);

-    ServoMotor_Trigger.attach(servoPin_Trigger, 400, 2600);
-    ServoMotor_Trigger.write(100);
+    ServoMotor_Trigger.attach(servoTrigger_Pin, 400, 2600);
+    ServoMotor_Trigger.write(servoTrigger_Pos);
 }

 void loop()
 {
-    ServoMotor_Bottom.write(map(analogRead(buttonX), 0, 1024, 0, 180));
-
-    ServoMotor_Top.write(map(analogRead(buttonY), 0, 1024, 0, 180));
-
     if(digitalRead(buttonSW) == 0)
     {
-        ServoMotor_Trigger.write(135);
-        delay(100);
-        ServoMotor_Trigger.write(100);
+        ServoMotor_Trigger.write(servoTrigger_PosShoot);
+        delay(200);
+        ServoMotor_Trigger.write(servoTrigger_Pos);
+        return;
     }

+    servoBottom_Pos += map(analogRead(buttonX), 0, 1024, -servoRotationStep, servoRotationStep);
+    servoTop_Pos += map(analogRead(buttonY), 0, 1024, -servoRotationStep, servoRotationStep);
+    delay(50);
+
+    ServoMotor_Bottom.write(servoBottom_Pos);
+    ServoMotor_Top.write(servoTop_Pos);
 }


remove serial port reporting

remove serial port reporting

--- OS_SerialFunctions.ino
+++ OS_SerialFunctions.ino
@@ -75,11 +75,14 @@
 // * serialSetMode
 // Set speed mode on the DualShock
 void serialSetMode(){
+  if (!doGamePad){
+    return;
+  }
+
   while(Serial1.available() == 0 );//block until char arrives

   char ch = Serial1.read();

-   Serial.println(ch);
    if (ch=='1')
      coarseFine=1;
    if (ch=='2')
@@ -98,7 +101,6 @@
 // Current position becomes the new zero.
 // Also updates any stored locations so that we can still returns to them
 void zeroStage(){
-  Serial.println("Zeroing stage");
   float delta[numAxes]; //difference between current position and previous zero
   for (byte ii=0; ii<numAxes; ii++){
     delta[ii]=stagePosition[ii];


updated LCD display with smaller memory footprint

--- mwsLCD/mwsLCD.ino
+++ mwsLCD/mwsLCD.ino
@@ -109,7 +109,7 @@
 //byte month, day, hour, minute, second, hundredths;

 // volatiles are subject to modification by IRQs
-volatile unsigned long raintime, rainlast, raininterval, rain;
+volatile unsigned long rainlast;

 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

@@ -119,8 +119,8 @@
 // Count rain gauge bucket tips as they occur
 // Activated by the magnet and reed switch in the rain gauge, attached to input D2
 {
-  raintime = millis(); // grab current time
-  raininterval = raintime - rainlast; // calculate interval between this and last event
+  unsigned long raintime = millis(); // grab current time
+  unsigned long raininterval = raintime - rainlast; // calculate interval between this and last event

   if (raininterval > 10) // ignore switch-bounce glitches less than 10mS after initial edge
   {
@@ -155,12 +155,7 @@
 {
   // set up the LCD's number of columns and rows:
   lcd.begin(16, 2);
-  // Print a message to the LCD.
-  lcd.clear();
-  lcd.print("Mobile Weather");
-  lcd.setCursor(0, 2);
-  lcd.print("Station is up");
-
+
   Serial.begin(9600);

   ss.begin(9600); //Begin listening to GPS over software serial at 9600. This should be the default baud of the module.
@@ -485,41 +480,31 @@
   //delay(2000);

   lcd.clear();
-  lcd.print("GMT Date");
+  lcd.print(sz);
   lcd.setCursor(0, 2);
   lcd.print(sz);
-  delay(2000);
+  lcd.print(" GMT");
+  delay(4000);

   lcd.clear();
-  lcd.print("GMT Time");
+  lcd.print("WD: ");
+  lcd.print(get_wind_direction());
+  lcd.print("  N=0 CW");
   lcd.setCursor(0, 2);
-  lcd.print(sz);
-  delay(2000);
+  lcd.print("WS:");
+  lcd.print(get_wind_speed(), 1);
+  lcd.print(" m/s");
+  delay(4000);

   lcd.clear();
-  lcd.print("Wind Direction");
+  lcd.print("H:");
+  lcd.print(myHumidity.readHumidity());
+  lcd.print(" %");
   lcd.setCursor(0, 2);
-  lcd.print(get_wind_direction());
-  lcd.print("(N=0 CW)");
-  delay(2000);
-
-  lcd.clear();
-  lcd.print("Wind Speed (m/s)");
-  lcd.setCursor(0, 2);
-  lcd.print(get_wind_speed(), 1);
-  delay(2000);
-
-  lcd.clear();
-  lcd.print("Humidity (%)");
-  lcd.setCursor(0, 2);
-  lcd.print(myHumidity.readHumidity());
-  delay(2000);
-
-  lcd.clear();
-  lcd.print("Temperature (C)");
-  lcd.setCursor(0, 2);
+  lcd.print("T:");
   lcd.print(myPressure.readTemp());
-  delay(2000);
+  lcd.print(" C");
+  delay(4000);

   //Not enough dynamic memory in UNO
   //lcd.clear();
@@ -529,10 +514,14 @@
   //delay(2000);

   lcd.clear();
-  lcd.print("Rain Hourly (mm)");
+  lcd.print("R:");
+  lcd.print(rainin);
+  lcd.print(" mm/h");
   lcd.setCursor(0, 2);
-  lcd.print(rainin);
-  delay(2000);
+  lcd.print("P:");
+  lcd.print(myPressure.readPressure()/100.0);
+  lcd.print(" hPa");
+  delay(4000);

   //Not enough dynamic memory in UNO
   //lcd.clear();
@@ -541,11 +530,6 @@
   //lcd.print(rainin_5m);
   //delay(2000);

-  lcd.clear();
-  lcd.print("Pressure (hPa)");
-  lcd.setCursor(0, 2);
-  lcd.print(myPressure.readPressure()/100.0);
-  delay(2000);

   //Not enough dynamic memory in UNO
   //lcd.clear();


updated LCD display

updated LCD display

--- mwsLCD/mwsLCD.ino
+++ mwsLCD/mwsLCD.ino
@@ -552,7 +552,7 @@
   delay(2000);

   lcd.clear();
-  lcd.print("Temperature (Celsius)");
+  lcd.print("Temperature (C)");
   lcd.setCursor(0, 2);
   lcd.print(tempc);
   delay(2000);


Sent zero in cas of no analog signal (manual control).

--- HBridgePWM/Sabertooth/Sabertooth.ino
+++ HBridgePWM/Sabertooth/Sabertooth.ino
@@ -149,7 +149,12 @@
         alphaSigned = 0;
       }
     }
+    if (isManualControl)
+    {
+      alphaSigned = 0;
+    }
   }
   Serial.println(sensorValue);
   alphaSigned = min(1, max(-1, alphaSigned));
+
 }


Added delay between status reports

Added delay between status reports

--- Arduino/Arduino.ino
+++ Arduino/Arduino.ino
@@ -38,6 +38,7 @@
 char statusReport = 'A'; // one-byte status report to controller
 int iterationsSinceLastStatusReportSent = 0;

+bool everythingOk = true;
 bool batteryLow = false;
 bool batteryOk = true;
 bool motorOk = true;
@@ -87,6 +88,11 @@
 const char SENSORS_OFF_CONFIRM      = 'i';
 const char FLIGHT_REC_ON_CONFIRM    = 'O';
 const char FLIGHT_REC_OFF_CONFIRM   = 'o';
+
+//    Sending status reports
+const char STATUS_OK = 'A';
+
+const int ITERATIONS_FOR_EACH_STATUS_REPORT = 100;

 //   MPU constants
 const char MPU_POSITIVE_THRESHOLD   = 3;
@@ -204,7 +210,22 @@
   }

   // Send status to Serial
-  Serial.write(statusReport);
+  if ( everythingOk )
+  {
+    if ( iterationsSinceLastStatusReportSent > ITERATIONS_FOR_EACH_STATUS_REPORT )
+    {
+      Serial.write(STATUS_OK);
+      iterationsSinceLastStatusReportSent = 0;
+    }
+    else iterationsSinceLastStatusReportSent++;
+  }
+  else
+  {
+    if ( !batteryOk )
+    {
+
+    }
+  }

   // Send sensor data to serial
   if ( sensorReportingOn )


Update Keypad.ino

Update Keypad.ino

--- ComboKeypad/Keypad.ino
+++ ComboKeypad/Keypad.ino
@@ -143,7 +143,7 @@
     input[inputIndex] = 0;   //Zeros the input array
   }

-    time = millis();   //Sets this to 0 because it might be a bugg there
+    time = millis();
      digitalWrite(rightLight, 0);   //Turns the "Green" light off
       digitalWrite(wrongLight, 0);   //Turns the "Red" light off
        count = 0;  //Sets the counter to 0


We are successfully creating JSON connection data.

--- ServerSketch/ServerSketch.ino
+++ ServerSketch/ServerSketch.ino
@@ -33,6 +33,9 @@
 // JSON specifics
 aJsonStream serial_stream(&Serial);

+// Web sockets
+#define WEB_SOCKET_BUFFER_SIZE 10000
+
 // HW declaration
 #define TOTAL_NUM_Dx 14
 #define TOTAL_NUM_Px 12
@@ -46,6 +49,8 @@

 #define ANALOG_OUT_MAX_VALUE 255
 #define ANALOG_IN_MAX_VALUE 1024 //4096
+
+char** g_caaPinNames[20][PIN_LABEL_SIZE];

 typedef struct Pin {
   char label[PIN_LABEL_SIZE];
@@ -423,105 +428,22 @@

   if( g_luiCounter%100 == 0)
   {
-    Serial.println("NEW CODE");
-/*
-    unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 512 + LWS_SEND_BUFFER_POST_PADDING];
+
+    unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + WEB_SOCKET_BUFFER_SIZE + LWS_SEND_BUFFER_POST_PADDING];
     unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
-
+
     updateBoardState();
-    aJsonObject *msg = getJsonBoardState();
-    char * pTempPointer = aJson.print(msg);
-//    String sTempString = aJson.print(msg);
-   // snprintf(buf,sizeof(buf),"%s",aJson.print(msg));

-    p = (unsigned char *)pTempPointer;
-    aJson.print(msg, &serial_stream);
-//    aJson.deleteItem(msg);
-
-    //n = sizeof(pTempPointer);
-//    n = sprintf(bufTwo,"%s",pTempPointer);
-    Serial.println("");
-    Serial.print("n: ");
-    Serial.println(n);
- //   Serial.print("len: ");
-  //  Serial.println(    sTempString.length() );
-//    n = libwebsocket_write(wsi, p, n, LWS_WRITE_TEXT);
-    n = libwebsocket_write(wsi, p, 2000, LWS_WRITE_TEXT);
-    */
+    aJsonObject *msg = getJsonBoardState();

-    /*
-    unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 2000 + LWS_SEND_BUFFER_POST_PADDING];
-    unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
-
-    updateBoardState();
-    aJsonObject *msg = getJsonBoardState();
-    char * pTempPointer = "{\"status\":\"OK\",\"pins\":{ \"13\":{\"label\":\"Pin 13\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"1\"}  }}"; //aJson.print(msg);
-//    String sTempString = aJson.print(msg);
-   // snprintf(buf,sizeof(buf),"%s",aJson.print(msg));
-
-    p = (unsigned char *)pTempPointer;
-    aJson.print(msg, &serial_stream);
-//    aJson.deleteItem(msg);
-
-    //n = sizeof(pTempPointer);
-//    n = sprintf(bufTwo,"%s",pTempPointer);
-    Serial.println("");
-    Serial.print("n: ");
-    Serial.println(n);
- //   Serial.print("len: ");
-  //  Serial.println(    sTempString.length() );
-//    n = libwebsocket_write(wsi, p, n, LWS_WRITE_TEXT);
-    n = libwebsocket_write(wsi, p, 2000, LWS_WRITE_TEXT);
-
+    aJsonStringStream stringStream(NULL, (char *)p, WEB_SOCKET_BUFFER_SIZE);
+    aJson.print(msg, &stringStream);
+    String sTempString((char *)p);
+
+    n = libwebsocket_write(wsi, p, sTempString.length(), LWS_WRITE_TEXT);

     aJson.deleteItem(msg);
-    */
-    unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 10000 + LWS_SEND_BUFFER_POST_PADDING];
-    unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
-
-    //n = sprintf((char *)p, "%s","{\"status\":\"OK\",\"pins\":{ \"13\":{\"label\":\"Pin 13\",\"is_analog\":\"false\",\"is_input\":\"false\",\"sensitivity\":\"0.5\",\"is_inverted\":\"false\",\"is_visible\":\"true\",\"value\":\"1\"}  }}");
-//    n = sprintf((char *)p, "%s","{\"status\":\"OK\",\"pins\":{ \"13\":{\"label\":\"Pin 13\",\"is_analog\":false,\"is_input\":false,\"sensitivity\":0.5,\"is_inverted\":false,\"is_visible\":true,\"value\":1}  }}");
-//    n = sprintf((char *)p, "%s","{\"status\":\"OK\",\"pins\":{ \"14\":{\"label\":\"A0\",\"is_analog\":true,\"is_input\":true,\"sensitivity\":0.5,\"is_inverted\":false,\"is_visible\":true,\"value\":0.5}, \"3\":{\"label\":\"~3\",\"is_analog\":true,\"is_input\":false,\"sensitivity\":0.5,\"is_inverted\":false,\"is_visible\":true,\"value\":0.6}  }}");
-//    n = sprintf((char *)p, "%s","{\"status\":\"OK\",\"pins\":{ \"14\":{\"label\":\"A0\",\"is_analog\":true,\"is_input\":true,\"sensitivity\":0.5,\"is_inverted\":false,\"is_visible\":true,\"value\":0.5}, \"3\":{\"label\":\"~3\",\"is_analog\":true,\"is_input\":false,\"sensitivity\":0.5,\"is_inverted\":false,\"is_visible\":true,\"value\":0.6}  },\"connections\":[{\"source\":\"14\",\"target\":\"3\"}] }");
-
-      updateBoardState();
-      aJsonObject *msg = getJsonBoardState();
-//      String sTempString = aJson.print(msg);
-//      Serial.println("");
- //     Serial.print("sTempString :");
- //     Serial.println(sTempString);
-
-//      String sTempString = "{\"status\":\"OK\",\"pins\":{ \"13\":{\"label\":\"Pin 13\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"1\"}, \"2\":{\"label\":\"Pin 2\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"1\"}, \"4\":{\"label\":\"Pin 4\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"1\"}, \"7\":{\"label\":\"Pin 7\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"1\"}, \"8\":{\"label\":\"Pin 8\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"1\"}, \"12\":{\"label\":\"Pin 12\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"1\"}, \"3\":{\"label\":\"Pin 3\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.9\"}, \"5\":{\"label\":\"Pin 5\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.9\"}, \"6\":{\"label\":\"Pin 6\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.9\"}, \"9\":{\"label\":\"Pin 9\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.9\"}, \"10\":{\"label\":\"Pin 10\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.9\"}, \"11\":{\"label\":\"Pin 11\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.9\"}   }}";
-//      n = sprintf((char *)p, "%s",aJson.print(msg)); // This funtion can only print 256 characters
-
-   //   char* outBuf = (char*) malloc(2000); /* XXX: Dynamic size. */
-//      n = sizeof(buf) - LWS_SEND_BUFFER_PRE_PADDING - LWS_SEND_BUFFER_POST_PADDING;
-
-    //  n = sizeof((char *)p);
-      /*
-      int count = 0;
-      while(*(p+n*count) != '\0' || count != 10100)
-      {
-        count++;
-      }
-      */
-
-      aJsonStringStream stringStream(NULL, (char *)p, 10000);
-      aJson.print(msg, &stringStream);
-      String sTempString((char *)p);
-
-      Serial.println("");
-      Serial.print("sTempString.len:  ");
-      Serial.println(sTempString.length());
-
-      n = libwebsocket_write(wsi, p, sTempString.length(), LWS_WRITE_TEXT);
-
-      Serial.println("");
-      Serial.print("n after: ");
-      Serial.println(n);
-
-      aJson.deleteItem(msg);
-
+
   }

   g_luiCounter++;
@@ -627,12 +549,12 @@
 //////////////////////////////////////////////////////
 void initBoardState()
 {
-
+
   // Initialize all pins with no lable and 0.0 value
   for(int i=0; i<TOTAL_NUM_OF_PINS; i++)
   {
     memset(g_aPins[i].label, '\0', sizeof(g_aPins[i].label));
-    strcpy(g_aPins[i].label,"None");
+    //strcpy(g_aPins[i].label,"None");
     g_aPins[i].value = 0.0;
     memset(g_aPins[i].connections, '\0', sizeof(g_aPins[i].connections));
     for(int j=0; j<TOTAL_NUM_OF_PINS; j++)
@@ -643,6 +565,27 @@
         g_aPins[i].connections[j] = false;
     }
   }
+
+  strcpy(g_aPins[0].label,"0");
+  strcpy(g_aPins[1].label,"1");
+  strcpy(g_aPins[2].label,"2");
+  strcpy(g_aPins[3].label,"3");
+  strcpy(g_aPins[4].label,"4");
+  strcpy(g_aPins[5].label,"5");
+  strcpy(g_aPins[6].label,"6");
+  strcpy(g_aPins[7].label,"7");
+  strcpy(g_aPins[8].label,"8");
+  strcpy(g_aPins[9].label,"9");
+  strcpy(g_aPins[10].label,"10");
+  strcpy(g_aPins[11].label,"11");
+  strcpy(g_aPins[12].label,"12");
+  strcpy(g_aPins[13].label,"13");
+  strcpy(g_aPins[14].label,"A0");
+  strcpy(g_aPins[15].label,"A1");
+  strcpy(g_aPins[16].label,"A2");
+  strcpy(g_aPins[17].label,"A3");
+  strcpy(g_aPins[18].label,"A4");
+  strcpy(g_aPins[19].label,"A5");

   // Initialize pins 0-13 as digital out pins
   for(int i=0; i<(TOTAL_NUM_OF_PINS-NUM_OF_ANALOG_PINS); i++)
@@ -793,7 +736,7 @@
   }

   // Creating connection JSON object
-  aJsonObject* poConnections = aJson.createObject();
+  aJsonObject* paConnections = aJson.createArray();

   // Create STATUS
   poStatus = aJson.createItem("OK");
@@ -826,8 +769,6 @@
     }

     // Populate sensitivity
-//    snprintf(buff, sizeof(buff),"%f", g_aPins[i].sensitivity);
-//    aJson.addItemToObject(apoPin[i],"sensitivity", aJson.createItem( buff ) );
     aJson.addItemToObject(apoPin[i],"sensitivity", aJson.createItem( g_aPins[i].sensitivity ) );

     // Populate pin's inversion
@@ -850,16 +791,7 @@
       aJson.addItemToObject(apoPin[i],"is_visible", aJson.createFalse() );
     }

-    /*
-      float sensitivity;
-  int is_inverted;
-  int is_visible;
-    */
-
-    // Populate pin's value
-//    snprintf(buff, sizeof(buff),"%f", g_aPins[i].value);
-//    aJson.addItemToObject(apoPin[i],"value", aJson.createItem( buff ) );
-    aJson.addItemToObject(apoPin[i],"sensitivity", aJson.createItem( g_aPins[i].value ) );
+    aJson.addItemToObject(apoPin[i],"value", aJson.createItem( g_aPins[i].value ) );

     // Push to JSON structure
     sprintf(caPinNumBuffer,"%d",i);
@@ -879,15 +811,34 @@
 "connections":[ {"source":"<0,1,…,13,A0,…,A5>","target":"<0,1,…,13,A0,…,A5>",”is_connected”:”<true,false>”},  ...,  ]  }
   */

-
   // Create CONNECTIONS
-  int iaConnections[10];
-  poConnections = aJson.createIntArray(iaConnections, 0);
+//  int iaConnections[10];
+//  poConnections = aJson.createIntArray(iaConnections, 0);
+
+//  paConnections =
+
+  for(int i=0; i<TOTAL_NUM_OF_PINS ;i++)
+  {
+    for(int j=0; j<TOTAL_NUM_OF_PINS ;j++)
+    {
+      if(g_aPins[i].connections[j] && i !=j )
+      {
+        aJsonObject* poConnObject = aJson.createObject();
+        sprintf(caPinNumBuffer,"%d",i);
+        aJson.addItemToObject(poConnObject,"source",aJson.createItem(caPinNumBuffer));
+        sprintf(caPinNumBuffer,"%d",j);
+        aJson.addItemToObject(poConnObject,"target",aJson.createItem(caPinNumBuffer));
+        aJson.addItemToArray(paConnections,poConnObject);
+      }
+    }
+  }
+

   // Push to JSON object
   aJson.addItemToObject(poJsonBoardState,"status",poStatus);
   aJson.addItemToObject(poJsonBoardState,"pins",poPins);
-  aJson.addItemToObject(poJsonBoardState,"connections",poConnections);
+//  aJson.addItemToObject(poJsonBoardState,"connections",poConnections);
+  aJson.addItemToObject(poJsonBoardState,"connections",paConnections);

   return poJsonBoardState;

@@ -895,6 +846,9 @@

 void processMessage(char *_acMsg)
 {
+
+  Serial.print("Msg recvd: ");
+  Serial.println(_acMsg);

   aJsonObject *poMsg = aJson.parse(_acMsg);

@@ -1160,10 +1114,10 @@

     //////////////////////////////////////////
     // Test sending message
-    //    aJsonObject *msg = getJsonBoardState();
-    //   aJson.print(msg, &serial_stream);
-    //    Serial.println("");
-    //   aJson.deleteItem(msg);
+    aJsonObject *msg = getJsonBoardState();
+    aJson.print(msg, &serial_stream);
+    Serial.println("");
+    aJson.deleteItem(msg);
     //////////////////////////////////////////

     last_print = millis();


Cleanup OTA and add ESP OTA status updates

--- Arduino_Sketch/HASwitchPlate/HASwitchPlate.ino
+++ Arduino_Sketch/HASwitchPlate/HASwitchPlate.ino
@@ -419,12 +419,12 @@
   }
   // Catch 0x1A error, possibly from .val query against things that might not support that request
   if (nextionReturnBuffer[0] == 0x1A) {
-    // 0x1A+End
+    // 0x1A+End
     // ERROR: Variable name invalid
     // We'll be triggering this a lot due to requesting .val on every component that sends us a Touch Off
     // Just reset mqttGetSubtopic and move on with life.
     mqttGetSubtopic = "";
-  }
+  }
 }

 ////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -481,29 +481,32 @@
 void setupOTA() {
   // Start up OTA
   // ArduinoOTA.setPort(8266); // Port defaults to 8266
-  ArduinoOTA.setHostname(mqttNode.c_str()); // Hostname defaults to esp8266-[ChipID]
-  ArduinoOTA.setPassword(otaPassword); // No authentication by default
+  ArduinoOTA.setHostname(mqttNode.c_str());
+  ArduinoOTA.setPassword(otaPassword);

   ArduinoOTA.onStart([]() {
-    debugPrintln("OTA update start");
+    debugPrintln("ESP OTA:  update start");
+    setNextionAttr("p[0].b[1].txt", "\"ESP OTA Update\"");
+    sendNextionCmd("page 0");
   });
   ArduinoOTA.onEnd([]() {
-    debugPrintln("\nOTA update complete");
+    debugPrintln("ESP OTA:  update complete");
+    setNextionAttr("p[0].b[1].txt", "\"ESP OTA Update\\rComplete!\"");
   });
-  ArduinoOTA.onProgress([](unsigned int
-  , unsigned int total) {
+  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
+    setNextionAttr("p[0].b[1].txt", "\"ESP OTA Update\\rProgress: " + String(progress / (total / 100)) + "%\"");
     //Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
   });
   ArduinoOTA.onError([](ota_error_t error) {
-    debugPrint("OTA Error: " + String(error));
-    if (error == OTA_AUTH_ERROR) debugPrintln(" Auth Failed");
-    else if (error == OTA_BEGIN_ERROR) debugPrintln(" Begin Failed");
-    else if (error == OTA_CONNECT_ERROR) debugPrintln(" Connect Failed");
-    else if (error == OTA_RECEIVE_ERROR) debugPrintln(" Receive Failed");
-    else if (error == OTA_END_ERROR) debugPrintln(" End Failed");
+    debugPrintln("ESP OTA:  ERROR code " + String(error));
+    if (error == OTA_AUTH_ERROR) debugPrintln("ESP OTA:  ERROR - Auth Failed");
+    else if (error == OTA_BEGIN_ERROR) debugPrintln("ESP OTA:  ERROR - Begin Failed");
+    else if (error == OTA_CONNECT_ERROR) debugPrintln("ESP OTA:  ERROR - Connect Failed");
+    else if (error == OTA_RECEIVE_ERROR) debugPrintln("ESP OTA:  ERROR - Receive Failed");
+    else if (error == OTA_END_ERROR) debugPrintln("ESP OTA:  ERROR - End Failed");
   });
   ArduinoOTA.begin();
-  debugPrintln("OTA firmware update ready");
+  debugPrintln("ESP OTA:  Over the Air firmware update ready");
 }

 ////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -622,6 +625,7 @@
       delay (1);
     }
   }
+  delay (10);
   return otaSuccessVal;
 }


Changed call to initialize CCS811 sensor in setup

it was being constantly polled in loop - probably resetting readings
every time

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -1,4 +1,4 @@
-// v0.56 - 7/13/2017
+// v0.56 - 7/20/2017
 // Developed by Akram Ali

 // www.crtlabs.org
@@ -83,6 +83,9 @@

   Serial.begin(115200);
   Serial.println("Setup");
+
+  ccs811_sensor.begin(uint8_t(ADDR), uint8_t(WAKE_PIN));  // initialize CCS811 sensor
+
   mySerial.begin(9600);   // initialize MHz-19 in UART mode
   mySerial2.begin(9600);   // initialize PMS7003 in UART mode

@@ -253,7 +256,6 @@

   // CCS811 VOC readings
-  ccs811_sensor.begin(uint8_t(ADDR), uint8_t(WAKE_PIN));
   ccs811_sensor.compensate(temp, rh);  // environmental compensation for current temperature and humidity
   ccs811_sensor.getData();
   tvoc = ccs811_sensor.readTVOC();


smoothed power readings

smoothed power readings

--- power_measure_tool.ino
+++ power_measure_tool.ino
@@ -4,13 +4,19 @@
 #include <Adafruit_GFX.h>
 #include <Adafruit_SSD1306.h>

-#define POLL_RATE 200
+#define POLL_RATE 100
 #define SCREEN_RESET_PIN 4 //Digital 4
 #define DISPLAY_CONTRAST true
+#define PAST_POWER_TO_AVERAGE 10

 Adafruit_INA219 ina219;
 Adafruit_SSD1306 display(SCREEN_RESET_PIN);

+//Smoothing algorithm http://arduino.cc/en/Tutorial/Smoothing
+float powerValues[PAST_POWER_TO_AVERAGE];      // the readings from the analog input
+int powerValuesIndex = 0;                  // the index of the current reading
+float powerValuesTotal = 0;                  // the running total
+float powerValuesAverage = 0;                // the average

 void setup(void)
 {
@@ -36,7 +42,7 @@
   float outputVolt = ina219.getBusVoltage_V();
   float outputAmp = ina219.getCurrent_mA() / 1000;

-  float outputWatt = outputVolt * outputAmp;
+  float outputWattRaw = outputVolt * outputAmp;

   float shuntVolt = ina219.getShuntVoltage_mV() / 1000;
   float sourceVolt = outputVolt + shuntVolt;
@@ -46,8 +52,23 @@
   display.setCursor(0,0);

+  powerValuesTotal = powerValuesTotal - powerValues[powerValuesIndex];
+  powerValues[powerValuesIndex] = outputWattRaw;
+  powerValuesTotal = powerValuesTotal + powerValues[powerValuesIndex];
+  powerValuesIndex++;
+
+  // if we're at the end of the array...
+  if (powerValuesIndex >= PAST_POWER_TO_AVERAGE) {
+    powerValuesIndex = 0;
+  }
+
+  powerValuesAverage = powerValuesTotal / PAST_POWER_TO_AVERAGE;
+
+
+
+
   display.print("Out Power:   ");
-  display.print(outputWatt, 3);
+  display.print(powerValuesAverage, 3);
   display.println("W");

   display.println();
@@ -79,7 +100,7 @@
   String output = "";
   char buff[10];

-  String outputWattString = dtostrf(outputWatt, 0, 3, buff);
+  String outputWattString = dtostrf(powerValuesAverage, 0, 3, buff);
   output += outputWattString;
   output += " ";


better fit for 10 bit joystick

better fit for 10 bit joystick

--- remap.ino
+++ remap.ino
@@ -36,12 +36,16 @@
   buttonizeStick(buttons, data->cX, data->cY);
 }

+inline uint16_t remapRange(uint8_t x) {
+  return (((uint16_t)x) << 2)+1;
+}
+
 void joystickBasic(const GameCubeData_t* data) {
     didJoystick = true;
-    Joystick.X(data->joystickX);
-    Joystick.Y(255-data->joystickY);
-    Joystick.Z(data->cX);
-    Joystick.Zrotate(data->cY);
+    Joystick.X(remapRange(data->joystickX));
+    Joystick.Y(remapRange(255-data->joystickY));
+    Joystick.Z(remapRange(data->cX));
+    Joystick.Zrotate(remapRange(data->cY));
 }

 void joystickPOV(const GameCubeData_t* data) {
@@ -79,15 +83,16 @@
 void joystickDualShoulder(const GameCubeData_t* data) {
     joystickBasic(data);
     joystickPOV(data);
-    Joystick.sliderLeft(2*data->shoulderLeft);
-    Joystick.sliderRight(2*data->shoulderRight);
+    Joystick.sliderLeft(remapRange(data->shoulderLeft));
+    Joystick.sliderRight(remapRange(data->shoulderRight));
 }

 void joystickUnifiedShoulder(const GameCubeData_t* data) {
     joystickBasic(data);
     joystickPOV(data);
-    //Joystick.sliderLeft(0);
-    Joystick.sliderRight(255+data->shoulderRight-data->shoulderLeft);
+    uint16_t datum = 512+(data->shoulderRight-(int16_t)data->shoulderLeft)*2;
+    Joystick.sliderLeft(datum);
+    Joystick.sliderRight(datum);
 }

 void joystickNoShoulder(const GameCubeData_t* data) {


[avr] Removed RSSI measuing code from non-RF69, added more verbose OOK floor

--- arduino/Powermon433/Powermon433.ino
+++ arduino/Powermon433/Powermon433.ino
@@ -68,6 +68,7 @@
 static uint32_t g_RxErrStart;
 static uint16_t g_RxErrCnt;
 static uint8_t g_RxOokFloor;
+static bool g_RxOokFloorVerbose;

 #if DPIN_OOK_RX >= 14
 #define VECT PCINT1_vect
@@ -405,7 +406,9 @@
     // The only "extra long" long signals the end of the preamble
     if (width > 1200)
     {
+#if defined(DPIN_RF69_RESET)
       rf69ook_startRssi();
+#endif
       resetDecoder();
       return false;
     }
@@ -478,8 +481,8 @@

 static void printRssi(void)
 {
-  Serial.print(F(" (Rssi -")); Serial.print(g_RxRssi/2, DEC);
-  Serial.println(F(" dBm)"));
+  Serial.print(F(" Rssi: -")); Serial.print(g_RxRssi/2, DEC);
+  Serial.print(F(" dBm, Floor: ")); Serial.print(g_RxOokFloor, DEC);
 }

 static void decodeRxPacket(void)
@@ -501,6 +504,7 @@
     Serial.print(F("NEW DEVICE id="));
     Serial.print(val16, HEX);
     printRssi();
+    Serial.println();
     return;
   }

@@ -518,6 +522,7 @@
   {
     Serial.print(F("CRC ERR"));
     printRssi();
+    Serial.println();
   }
 }

@@ -596,7 +601,9 @@
   {
     if (decodeRxPulse(v) == 1)
     {
+#if defined(DPIN_RF69_RESET)
       g_RxRssi = rf69ook_Rssi();
+#endif
       decodeRxPacket();
       resetDecoder();
     }
@@ -611,8 +618,9 @@
     Serial.print(F("Energy: ")); Serial.print(g_RxWattHours, DEC);
     Serial.print(F(" Wh, Power: ")); Serial.print(g_RxWatts, DEC);
     Serial.print(F(" W, Temp: ")); Serial.print(g_RxTemperature, DEC);
-    Serial.print(F(" F"));
+    Serial.print(F(" F, "));
     printRssi();
+    Serial.print(F(", LowBat: ")); Serial.println(g_RxFlags >> 7, DEC);

     g_RxDirty = false;
   }
@@ -626,6 +634,7 @@
     resetDecoder();
   }

+#if defined(DPIN_RF69_RESET)
   else if (!decoderBusy() && (millis() - g_RxErrStart) > 5000U)
   {
     int8_t offset = 0;
@@ -643,7 +652,13 @@

     g_RxErrStart = millis();
     g_RxErrCnt = 0;
-  }
+
+    if (g_RxOokFloorVerbose)
+    {
+      Serial.print("RxOokFloor="); Serial.println(g_RxOokFloor, DEC);
+    }
+  }
+#endif
 #endif // DPIN_OOK_RX
 }


First pass on rotation

First pass on rotation

--- LudumDare35/LDFunctions.ino
+++ LudumDare35/LDFunctions.ino
@@ -120,3 +120,16 @@
   (*bList) = b;
 }

+void rotatePlayer(Player * p)
+{
+  byte i, j;
+  byte tempArray[25];
+  for(i = 0; i < 5; i++)
+  {
+    for(j = 0; j < 5; j++)
+    {
+      tempArray[j + (-i + 4) * 5]  = p->mask[i + j * 5];
+    }
+  }
+  memcpy(p->mask, tempArray, 25);
+}


Setup the setupables in the setup() function for program

--- payload/payload.ino
+++ payload/payload.ino
@@ -1,30 +1,45 @@
 #include <Wire.h>

-// begin SD card libraries
+// SD card libraries
 #include <BlockDriver.h>
-#include <FreeStack.h>
+//#include <FreeStack.h>
 #include <MinimumSerial.h>
 #include <SdFat.h>
 #include <SdFatConfig.h>
 #include <SysCall.h>
-// end SD card libraries

-#include "Bmp180.h" // RCR header
+// RCR headers
+#include "Setupable.h"
+#include "Bmp180.h"

-namespace rcr {
-namespace level1payload {
+// To shorten RCR namespace, use namespace alias "custom".
+namespace custom = rcr::level1payload;

-Bmp180 bmp;
+custom::Bmp180 bmp;
 File file; // file object
 //SdFatSdio sd_card; // MicroSD card

+// Array of pointers to Setupable-implementing objects which require
+// initialization logic to take place in setup() function.
+// For more info, see "Setupable.h".
+custom::Setupable* setupables[] = { &bmp };
+
 void setup() {
+  // Illuminate LED.
+  pinMode(13, OUTPUT);
+  digitalWrite(13, HIGH);
+
   // Start serial communication.
-  Serial.begin(9600); // in bits/second
+  Serial.begin(9600); // bits/second does not matter for Teensy 3.6
+  Serial.println("In setup.");
+
+  // Setup the custom data structures.
+  for (custom::Setupable* obj : setupables) {
+    obj->Setup();
+  }
 }

 void printBmpData(void) {
-
   Serial.print("Temperature = ");
   Serial.print(bmp.temperature());
   Serial.println(" °C");
@@ -44,5 +59,3 @@
   delay(1000);
 }

-} // namespace level1_payload
-} // namespace rcr


Making the demo more configurable.

Making the demo more configurable.

--- examples/LCD/CosaKeypad/CosaKeypad.ino
+++ examples/LCD/CosaKeypad/CosaKeypad.ino
@@ -22,7 +22,8 @@
  *
  * @section Description
  * Cosa demonstration of DFRobot LCD Keypad shield handler;
- * Simple trace of callback, on_key(), with printout to the LCD.
+ * Simple trace of callback, on_key_down/up(), with printout
+ * of key, name/index, to the LCD as an IOStream.
  *
  * @section Circuit
  * Requires a DFRobot LCD Keypad shield with 16x2 HD44780 LCD
@@ -36,52 +37,53 @@
 #include "Cosa/IOStream.hh"
 #include "Cosa/LCD/Driver/HD44780.hh"

-HD44780::Port port;
-HD44780 lcd(&port);
-IOStream cout(&lcd);
-
 class KeypadTrace : public DFRobotLCDKeypad {
+private:
+  IOStream m_out;
 public:
-  KeypadTrace() : DFRobotLCDKeypad() {}
-  void trace(const char* msg, uint8_t nr);
+  KeypadTrace(IOStream::Device* dev) : DFRobotLCDKeypad(), m_out(dev) {}
   virtual void on_key_down(uint8_t nr) { trace(PSTR("down"), nr); }
   virtual void on_key_up(uint8_t nr) { trace(PSTR("up"), nr); }
+  void trace(const char* msg, uint8_t nr);
 };

 void
 KeypadTrace::trace(const char* msg, uint8_t nr)
 {
-  cout << clear;
+  m_out << clear;
   switch (nr) {
   case NO_KEY:
-    cout << PSTR("NO_KEY");
+    m_out << PSTR("NO_KEY");
     break;
   case SELECT_KEY:
-    cout << PSTR("SELECT_KEY");
+    m_out << PSTR("SELECT_KEY");
     break;
   case LEFT_KEY:
-    cout << PSTR("LEFT_KEY");
+    m_out << PSTR("LEFT_KEY");
     break;
   case DOWN_KEY:
-    cout << PSTR("DOWN_KEY");
+    m_out << PSTR("DOWN_KEY");
     break;
   case UP_KEY:
-    cout << PSTR("UP_KEY");
+    m_out << PSTR("UP_KEY");
     break;
   case RIGHT_KEY:
-    cout << PSTR("RIGHT_KEY");
+    m_out << PSTR("RIGHT_KEY");
     break;
   }
-  cout << ' ' << msg << endl << PSTR("key = ") << nr;
+  m_out << ' ' << msg << endl;
+  m_out << PSTR("key = ") << nr;
 }

-KeypadTrace keypad;
+HD44780::Port port;
+HD44780 lcd(&port);
+KeypadTrace keypad(&lcd);

 void setup()
 {
    Watchdog::begin(16, SLEEP_MODE_IDLE, Watchdog::push_timeout_events);
    lcd.begin();
-   cout << PSTR("CosaKeypad: started");
+   lcd.puts_P(PSTR("CosaKeypad: started"));
 }

 void loop()


Highlight the fact that pulse rate is limited.

--- OpenStage/c_userSettings_MEGA_PCB.ino
+++ OpenStage/c_userSettings_MEGA_PCB.ino
@@ -142,13 +142,16 @@
 //
 // The moveToTarget() function is executed when the user travels to a right-button set point
 // or responds to a serial command. It does this using the settings described below. The minimum
-// step size and motor RPM are reported to the serial terminal on bootup.
+// step size and motor RPM are reported to the serial terminal on bootup. Keep speeds below
+// stalling value. Also, remember that the AccelStepper library won't produce pulse rates above
+// about 4 kHz.
 float moveToStepSize=1.0/2.0;
 unsigned int moveToSpeed[maxAxes]={1600,1600,1200,1600};
 unsigned int moveToAccel[maxAxes]={1.0E4,1.0E4,1.0E4,1.0E4};

-
-
+// * Allow for inverting of hat-stick motions
+// to invert hat-stick motion direction set to -1, otherwise set to 1.
+short hatInvert[maxAxes]={1,1,1,1};

 //---------------------------------UNLIKELY TO NEED TO CHANGE THESE-------------------------------


Fixed a syntax error in a case I apparently never used.

--- examples/Ticon2011/Ticon2011.ino
+++ examples/Ticon2011/Ticon2011.ino
@@ -23,7 +23,7 @@
 // More described below. I used this switch because I had an Arduino in the
 // house when I was writing new programs, then ran outside in the cold with my
 // laptop to reprogram the Teensy that was running the real lights.
-#define ARDUINO 1
+#define ARDUINO_HW 1

 #include <G35String.h>
 #include <G35StringGroup.h>
@@ -35,7 +35,7 @@
 #include <IRremote.h>
 #endif

-#ifdef ARDUINO
+#ifdef ARDUINO_HW
 // A regular Arduino. First string on pin 13, second on 12.
 G35String lights_1(13, 50, 50, 0, false);
 G35String lights_2(12, 41);


send timer mode when checking

send timer mode when checking

--- _04-lcd-dust/a-01-esp01-i2c/a-01-esp01-i2c.ino
+++ _04-lcd-dust/a-01-esp01-i2c/a-01-esp01-i2c.ino
@@ -128,7 +128,8 @@

 volatile bool bac_timer_mode = false;
 volatile bool bhaveData = false;
-unsigned long timerMillis;
+unsigned long timerMillis = 0;
+bool btimerFirst = true;

 String clientName;
 String payload;
@@ -280,13 +281,27 @@
   if ( receivedpayload == "{\"CHECKING\":\"1\"}")
   {
     String check_payload = "ac status: ";
-    if (data_curr.ac_mode == 0)
-    {
-      check_payload += "off";
+    if (bac_timer_mode)
+    {
+      if (data_curr.ac_mode == 0)
+      {
+        check_payload += "timer:off";
+      }
+      else
+      {
+        check_payload += "timer:on";
+      }
     }
     else
     {
-      check_payload += "on";
+      if (data_curr.ac_mode == 0)
+      {
+        check_payload += "off";
+      }
+      else
+      {
+        check_payload += "on";
+      }
     }
     check_payload += "\r\n";
     check_payload += "ac temp set : ";
@@ -784,7 +799,7 @@
     data_mqtt.humidity    = DHT.getHumidity();
   }

-  sentMills = timerMillis = millis();
+  sentMills = millis();
   lcd.clear();
   lcd_redraw();
   attachInterrupt(SQWV_PIN, alm_isr, FALLING);
@@ -887,7 +902,7 @@
         {
           digitalClockDisplay();
           displayTimermode();
-
+
           if (!Rtc.IsDateTimeValid())
           {
             lcd.setCursor(18, 0);
@@ -941,7 +956,7 @@

       if (bac_timer_mode)
       {
-        if ((millis() - timerMillis) > AC_TIMER_INTERVAL)
+        if ((millis() - timerMillis) > AC_TIMER_INTERVAL || btimerFirst)
         {
           if (data_esp.ac_mode == 0)
           {
@@ -951,7 +966,8 @@
           {
             data_esp.ac_mode = 0;
           }
-          bhaveData = true;
+          btimerFirst = false;
+          bhaveData   = true;
           timerMillis = millis();
         }
       }


Fixed bug in ValueFrq condition

Fixed bug in ValueFrq condition

/cc @noah95

--- arduino/fasnacht/fasnacht.ino
+++ arduino/fasnacht/fasnacht.ino
@@ -108,7 +108,7 @@
       digitalWrite(5, 1); //D
       Serial.println("B OFF D ON  ");
     }
-    if( (ValueFrq > 440) && (ChannelFrq <= 460) ) {
+    if( (ValueFrq > 440) && (ValueFrq <= 460) ) {
       digitalWrite(3, 1); //B
       digitalWrite(5, 1); //D
       Serial.println("B ON  D ON  ");


try writeRect to display bitmap

try writeRect to display bitmap

I thought I would try out using the writeRect function I added to see if
it would speed up drawing the bitmap.  I have it alternate drawing,
using the old way and with writeRect.  Times did improve from: 1026ms to
787ms

--- examples/spitftbitmap/spitftbitmap.ino
+++ examples/spitftbitmap/spitftbitmap.ino
@@ -30,6 +30,7 @@
 #define SD_CS 4

 void setup(void) {
+  delay(2000);
   Serial.begin(9600);

   tft.begin();
@@ -45,6 +46,16 @@
 }

 void loop() {
+  delay(5000);
+  Serial.println("Try using writeRect");
+  tft.fillScreen(ILI9341_GREEN);
+  bmpDrawWriteRect("purple.bmp", 0, 0);
+
+  delay(5000);
+  Serial.println("Using pushCOlor");
+  tft.fillScreen(ILI9341_BLUE);
+  bmpDraw("purple.bmp", 0, 0);
+
 }

 // This function opens a Windows Bitmap (BMP) file and
@@ -167,6 +178,121 @@
   if(!goodBmp) Serial.println(F("BMP format not recognized."));
 }

+
+//===========================================================
+// Try Draw using writeRect
+void bmpDrawWriteRect(char *filename, uint8_t x, uint16_t y) {
+
+  File     bmpFile;
+  int      bmpWidth, bmpHeight;   // W+H in pixels
+  uint8_t  bmpDepth;              // Bit depth (currently must be 24)
+  uint32_t bmpImageoffset;        // Start of image data in file
+  uint32_t rowSize;               // Not always = bmpWidth; may have padding
+  uint8_t  sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel)
+  uint8_t  buffidx = sizeof(sdbuffer); // Current position in sdbuffer
+  boolean  goodBmp = false;       // Set to true on valid header parse
+  boolean  flip    = true;        // BMP is stored bottom-to-top
+  int      w, h, row, col;
+  uint8_t  r, g, b;
+  uint32_t pos = 0, startTime = millis();
+
+  uint16_t awColors[320];  // hold colors for one row at a time...
+
+  if((x >= tft.width()) || (y >= tft.height())) return;
+
+  Serial.println();
+  Serial.print(F("Loading image '"));
+  Serial.print(filename);
+  Serial.println('\'');
+
+  // Open requested file on SD card
+  if ((bmpFile = SD.open(filename)) == NULL) {
+    Serial.print(F("File not found"));
+    return;
+  }
+
+  // Parse BMP header
+  if(read16(bmpFile) == 0x4D42) { // BMP signature
+    Serial.print(F("File size: ")); Serial.println(read32(bmpFile));
+    (void)read32(bmpFile); // Read & ignore creator bytes
+    bmpImageoffset = read32(bmpFile); // Start of image data
+    Serial.print(F("Image Offset: ")); Serial.println(bmpImageoffset, DEC);
+    // Read DIB header
+    Serial.print(F("Header size: ")); Serial.println(read32(bmpFile));
+    bmpWidth  = read32(bmpFile);
+    bmpHeight = read32(bmpFile);
+    if(read16(bmpFile) == 1) { // # planes -- must be '1'
+      bmpDepth = read16(bmpFile); // bits per pixel
+      Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth);
+      if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed
+
+        goodBmp = true; // Supported BMP format -- proceed!
+        Serial.print(F("Image size: "));
+        Serial.print(bmpWidth);
+        Serial.print('x');
+        Serial.println(bmpHeight);
+
+        // BMP rows are padded (if needed) to 4-byte boundary
+        rowSize = (bmpWidth * 3 + 3) & ~3;
+
+        // If bmpHeight is negative, image is in top-down order.
+        // This is not canon but has been observed in the wild.
+        if(bmpHeight < 0) {
+          bmpHeight = -bmpHeight;
+          flip      = false;
+        }
+
+        // Crop area to be loaded
+        w = bmpWidth;
+        h = bmpHeight;
+        if((x+w-1) >= tft.width())  w = tft.width()  - x;
+        if((y+h-1) >= tft.height()) h = tft.height() - y;
+
+        for (row=0; row<h; row++) { // For each scanline...
+
+          // Seek to start of scan line.  It might seem labor-
+          // intensive to be doing this on every line, but this
+          // method covers a lot of gritty details like cropping
+          // and scanline padding.  Also, the seek only takes
+          // place if the file position actually needs to change
+          // (avoids a lot of cluster math in SD library).
+          if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
+            pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
+          else     // Bitmap is stored top-to-bottom
+            pos = bmpImageoffset + row * rowSize;
+          if(bmpFile.position() != pos) { // Need seek?
+            bmpFile.seek(pos);
+            buffidx = sizeof(sdbuffer); // Force buffer reload
+          }
+
+          for (col=0; col<w; col++) { // For each pixel...
+            // Time to read more pixel data?
+            if (buffidx >= sizeof(sdbuffer)) { // Indeed
+              bmpFile.read(sdbuffer, sizeof(sdbuffer));
+              buffidx = 0; // Set index to beginning
+            }
+
+            // Convert pixel from BMP to TFT format, push to display
+            b = sdbuffer[buffidx++];
+            g = sdbuffer[buffidx++];
+            r = sdbuffer[buffidx++];
+            awColors[col] = tft.color565(r,g,b);
+          } // end pixel
+          tft.writeRect(0, row, w, 1, awColors);
+        } // end scanline
+        Serial.print(F("Loaded in "));
+        Serial.print(millis() - startTime);
+        Serial.println(" ms");
+      } // end goodBmp
+    }
+  }
+
+  bmpFile.close();
+  if(!goodBmp) Serial.println(F("BMP format not recognized."));
+}
+
+
+
 // These read 16- and 32-bit types from the SD card file.
 // BMP data is stored little-endian, Arduino is little-endian too.
 // May need to reverse subscript order if porting elsewhere.


Update TeleInfo_exemple.ino

Update TeleInfo_exemple.ino

--- firmware/examples/TeleInfo_exemple.ino
+++ firmware/examples/TeleInfo_exemple.ino
@@ -5,8 +5,7 @@
    On utilise la pin RX du Spark Core, et un optocoupleur.
 */

-#include "application.h"
-#include "teleinfo/TeleInfo.h"
+#include "TeleInfo/TeleInfo.h"

 // ======== MAIN ============


Use low byte for blink count

Use low byte for blink count

--- teensy/snes_controller_emu.ino
+++ teensy/snes_controller_emu.ino
@@ -96,12 +96,14 @@
 			switch(high)
 			{
 				case 0: // connected
-					for(int i = 0; i < 3; i++)
+					if(low > 10) low = 10;
+					else if(low < 1) low = 1;
+					for(int i = 0; i < low; i++)
 					{
 						digitalWrite(PIN_LED, LOW);
-						delay(250);
+						delay(50);
 						digitalWrite(PIN_LED, HIGH);
-						delay(250);
+						delay(50);
 					}
 					digitalWrite(PIN_LED, HIGH);
 					break;


INIT Switches Code

INIT Switches Code