further effects for duino says game

further effects for duino says game

it's now much faster but also harder.

--- arduino/duinosays/duinosays.ino
+++ arduino/duinosays/duinosays.ino
@@ -102,17 +102,17 @@
     uint8_t x;
     uint8_t y;
     ScreenButtonId btn;
-    uint16_t normalColor;
+    uint8_t normalColor[3];
     uint16_t pressedColor;
     bool isEnabled;
     bool isPressed;
 public:
-    Button(ScreenButtonId btn, uint8_t x, uint8_t y, uint16_t normalColor, uint16_t pressedColor):
-        x(x), y(y), btn(btn), normalColor(normalColor), pressedColor(pressedColor), isEnabled(true) {};
+    Button(ScreenButtonId btn, uint8_t x, uint8_t y, uint8_t normalColorR, uint8_t normalColorG, uint8_t normalColorB, uint16_t pressedColor):
+        x(x), y(y), btn(btn), normalColor({normalColorR, normalColorG, normalColorB}), pressedColor(pressedColor), isEnabled(true) {};
     void setEnabled(bool on) {
         isEnabled = on;
     }
-    uint16_t getNormalColor() {
+    uint8_t* getNormalColor() {
         return normalColor;
     }
     bool getIsPressed() {
@@ -143,20 +143,20 @@
     DuinoSays():
         mode(DSMODE_MAINMENU),
         display(0),
-        btnTopLeft(SCREENBUTTON_TOPLEFT, 2, 16, buffer.rgb(192,0,0), buffer.rgb(255,0,0)),
-        btnTopRight(SCREENBUTTON_TOPRIGHT, 94, 16, buffer.rgb(0,192,0), buffer.rgb(0,255,0)),
-        btnBottomLeft(SCREENBUTTON_BOTTOMLEFT, 2, 48, buffer.rgb(192,192,0), buffer.rgb(255,255,0)),
-        btnBottomRight(SCREENBUTTON_BOTTOMRIGHT, 94, 48, buffer.rgb(0,0,192), buffer.rgb(64,64,255))
+        btnTopLeft(SCREENBUTTON_TOPLEFT, 2, 16, 192,0,0, buffer.rgb(255,0,0)),
+        btnTopRight(SCREENBUTTON_TOPRIGHT, 94, 16, 0,192,0, buffer.rgb(0,255,0)),
+        btnBottomLeft(SCREENBUTTON_BOTTOMLEFT, 2, 48, 192,192,0, buffer.rgb(255,255,0)),
+        btnBottomRight(SCREENBUTTON_BOTTOMRIGHT, 94, 48, 0,0,192, buffer.rgb(64,64,255))
     {

     }

     Button* getButton(uint8_t n) {
         switch (n%4) {
-        case 0: return &btnTopLeft;
-        case 1: return &btnTopRight;
-        case 2: return &btnBottomLeft;
-        case 3: return &btnBottomRight;
+        case SCREENBUTTON_TOPLEFT: return &btnTopLeft;
+        case SCREENBUTTON_TOPRIGHT: return &btnTopRight;
+        case SCREENBUTTON_BOTTOMLEFT: return &btnBottomLeft;
+        case SCREENBUTTON_BOTTOMRIGHT: return &btnBottomRight;
         }
         return 0;
     }
@@ -249,17 +249,29 @@
     void loopPlaying() {
         drawButtons();
         if (isShowingColors) {
+            const uint8_t progressCounterMaxBit = 2;
             if (currentStep == 0) {
                 buffer.drawText(stringBuffer.start()->load(PSTR("duino says ..."))->get(),16,28,buffer.rgb(255,128,32), &virtualDJ_5ptFontInfo);
             }
             if (currentStep <= currentLevel && currentStep > 0) {
-                const uint8_t w = 4 + progressCounter, h = 4 + progressCounter;
+                const uint8_t w = 4 + progressCounter, h = w;
                 uint8_t col = getColor(currentStep);
-                Button *button = getButton(col);
-                buffer.drawRect(48-w/2,32-h/2,w,h)->filledRect(button->getNormalColor());
-                buffer.drawText(stringBuffer.start()->put(currentStep)->get(),44,52,buffer.rgb(255,128,32), &virtualDJ_5ptFontInfo);
-            }
-            if (progressCounter++ > 30) {
+                Button* button = getButton(col);
+                uint8_t* btnColor = button->getNormalColor();
+                uint16_t rectColor = buffer.rgb(
+                                                btnColor[0] * progressCounter >> progressCounterMaxBit,
+                                                btnColor[1] * progressCounter >> progressCounterMaxBit,
+                                                btnColor[2] * progressCounter >> progressCounterMaxBit);
+                buffer.drawRect(48-w/2,32-h/2,w,h)->filledRect(rectColor);
+                buffer.drawText(stringBuffer.start()->put(currentStep)->put(":")->put(currentLevel)->get(),42,52,buffer.rgb(255,128,32), &virtualDJ_5ptFontInfo);
+                if (progressCounter == 0) {
+                    particleSystem.spawn(4|col, 48,32,800,800, 24);
+                    particleSystem.spawn(4|col, 48,32,800,-800, 24);
+                    particleSystem.spawn(4|col, 48,32,-800,-800, 24);
+                    particleSystem.spawn(4|col, 48,32,-800,800, 24);
+                }
+            }
+            if (progressCounter++ > (1<<progressCounterMaxBit)) {
                 currentStep += 1;
                 progressCounter = 0;
                 if (currentStep > currentLevel) {
@@ -283,7 +295,7 @@
             if (currentStep > currentLevel) {
                 nextLevel();
             } else {
-                buffer.drawText(stringBuffer.start()->put(currentStep)->get(),44,52,buffer.rgb(255,128,32), &virtualDJ_5ptFontInfo);
+                buffer.drawText(stringBuffer.start()->put(currentStep)->put(":")->put(currentLevel)->get(),42,52,buffer.rgb(255,128,32), &virtualDJ_5ptFontInfo);
             }
         }

@@ -291,8 +303,8 @@
     }

     void loopGameOver() {
-        buffer.drawText(stringBuffer.start()->load(PSTR("game over"))->get(),16,28,buffer.rgb(255,128,32), &virtualDJ_5ptFontInfo);
-        buffer.drawText(stringBuffer.start()->load(PSTR("score: "))->put(currentLevel)->get(),24,38,buffer.rgb(192,192,192), &virtualDJ_5ptFontInfo);
+        buffer.drawText(stringBuffer.start()->load(PSTR("game over"))->get(),20,28,buffer.rgb(255,128,32), &virtualDJ_5ptFontInfo);
+        buffer.drawText(stringBuffer.start()->load(PSTR("score: "))->put(currentLevel)->get(),28,38,buffer.rgb(192,192,192), &virtualDJ_5ptFontInfo);
         if (progressCounter < 50) {
             progressCounter++;
         } else {
@@ -329,14 +341,15 @@
 };

 void Particle::draw(DuinoSays* duinoSays) {
-    const int height = 24;
+    const uint8_t rel = 255 - frameAge * 255 / maxAge;
+    const bool isButtonParticle = type < 4;
+    const int height = isButtonParticle ? 24 : 8 * rel >> 8;
     frameAge+=1;

-    const uint8_t rel = 255 - frameAge * 255 / maxAge;
-    const int width = 16 * rel >> 8;
+    const int width = isButtonParticle ? 16 * rel >> 8 : height;

     uint8_t r = 255, g = 0, b = 255;
-    switch (type) {
+    switch (type & 3) {
         case ParticleType::topLeftButton: r = 255, g = 64, b = 32; break;
         case ParticleType::bottomLeftButton: r = 255, g = 255, b = 64; break;
         case ParticleType::topRightButton: r = 32, g = 255, b = 32; break;
@@ -346,8 +359,14 @@
     duinoSays->buffer.drawRect((x>>8) - width / 2,(y>>8) - height / 2,width,height)->filledRect(duinoSays->buffer.rgb(rel * r >> 8,rel * g >> 8,rel * b >> 8));
     x+=vx;
     y+=vy;
-    vx -= vx>>2;
-    vy -= vy>>2;
+    if ( isButtonParticle) {
+        vx -= vx>>2;
+        vy -= vy>>2;
+    } else {
+        vx -= (vy>>2) + (vx >> 5);
+        vy -= (-vx>>2) + (vy >> 5);
+    }
+
 }

 template<uint8_t maxParticles>
@@ -367,8 +386,9 @@
     const int width = on ? 8 : 6;
     const int height = on ? 24 : 26;
     const int xOffset = isEnabled ? 0 : ((x > 48) * 2 - 1) * 3;
-
-    duinoSays->buffer.drawRect(x - width / 2 + xOffset,y - height / 2,width,height)->filledRect(on ? pressedColor : normalColor);
+    const uint16_t normalColor565 = duinoSays->buffer.rgb(normalColor[0], normalColor[1], normalColor[2]);
+
+    duinoSays->buffer.drawRect(x - width / 2 + xOffset,y - height / 2,width,height)->filledRect(on ? pressedColor : normalColor565);
     if (on && ScreenButtonState::isButtonActivated(btn)) {
         isPressed = true;
         duinoSays->particleSystem.spawn(btn, x,y,x<48?4000:-4000,0, 8);


firebase: support quoted ssid and empty passwords

--- firebase/firebase.ino
+++ firebase/firebase.ino
@@ -26,6 +26,7 @@
   char ssid[32];
   char password[32];
 } cred;
+const int maxWifiConnectAttemps = 20;

 String buffer;

@@ -38,26 +39,34 @@
   Serial.println("!I #!/dev/fail");
   Serial.print("!I token: ");
   Serial.println(cred.token);
+  bool connected = false;
   if (strlen(cred.ssid) > 0) {
-    wifiConnect();
+    connected = wifiConnect();
+  }
+  if (!connected) {
+    Serial.println("!E no wifi connection");
   }
 }

 bool wifiConnect() {
-  Serial.print("!I connecting to wifi");
+  Serial.println("!I connecting to wifi");
+  Serial.print("!I ssid: ");
+  Serial.println(cred.ssid);
+  Serial.print("!I ");
   WiFi.begin(cred.ssid, cred.password);
-  for (int i = 0; i < 20; i++) {
+  for (int i = 0; i < maxWifiConnectAttemps; i++) {
     delay(500);
     Serial.print(".");
     if (WiFi.status() == WL_CONNECTED) {
       Serial.println("");
-      Serial.print("!I wifi connected: ");
-      Serial.println(WiFi.localIP());
+      Serial.println("!I wifi connected");
+      Serial.print("!I ip: ");
+      Serial.println(WiFi.localIP());
       return true;
     }
   }
   Serial.println("");
-  Serial.println("!I wifi connection failed");
+  Serial.println("!E wifi connection failed");
   return false;
 }

@@ -66,6 +75,13 @@
        "Host: " + host + "\r\n" +
        "User-Agent: Chiplet\r\n" +
        "Connection: close\r\n";
+}
+
+String unquote(String s) {
+  if (s[0] == '"' && s[s.length()-1] == '"') {
+    return s.substring(1, s.length()-1);
+  }
+  return s;
 }

 void loop() {
@@ -96,13 +112,18 @@
     } else if (data.startsWith("AT+CWJAP=")) {
       String ssidPwd = data.substring(9);
       int i = ssidPwd.indexOf(",");
-      ssidPwd.substring(0, i).toCharArray(cred.ssid, sizeof(cred.token));
-      ssidPwd.substring(i+1).toCharArray(cred.password, sizeof(cred.password));
+      unquote(ssidPwd.substring(0, i)).toCharArray(cred.ssid, sizeof(cred.token));
+      if (i != -1) {
+        unquote(ssidPwd.substring(i+1)).toCharArray(cred.password, sizeof(cred.password));
+      } else {
+        cred.password[0] = '\0';
+      }
       Serial.println("!I ssid: " + String(cred.ssid));
       Serial.println("!I password: " + String(cred.password));
       if (wifiConnect()) {
        EEPROM.put(0, cred);
-       EEPROM.commit();
+       EEPROM.commit();
+       Serial.println("OK");
       }
     } else {
        Serial.println("!E usage:");
@@ -111,6 +132,7 @@
        Serial.println("!E      payload");
        Serial.println("!E TOKEN token");
        Serial.println("!E AT+CWJAP=ssid,passwd");
+       Serial.println("!E AT+CWSAP=ssid");
     }
   }


- reactivated warum period after testing - changed DEBUG_PRINTLN to Serial.print to get MAC printed correctly at startup

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -57,8 +57,8 @@
   Serial.println("## Particulate Matter Sensor ##");
   Serial.print("Software version: ");
   Serial.println(SOFTWARE_VERSION);
-  DEBUG_PRINTLN("Device Identifier (MAC): ");
-  DEBUG_PRINTLN(strMac);
+  Serial.print("Device Identifier (MAC): ");
+  Serial.println(strMac);

   WIFI_MULTI_APS


no message

no message

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -2,18 +2,11 @@
 #include <VarSpeedServo.h>
 #include <EEPROM.h>

-<<<<<<< HEAD
 VarSpeedServo servoL;
 VarSpeedServo servoR;
 VarSpeedServo servoRot;
 VarSpeedServo servoHandRot;
 VarSpeedServo servoHand;
-=======
-int  heightTemp  = 0, stretchTemp = 0, rotationTemp = 0, handRotTemp = 0;
-char stateMachine = 0, counter = 0;
-char dataBuf[8] = {0};
-byte rxBuf = 0;
->>>>>>> bea2b19c183c0fccc0dbb2e7aeadd60bfa027926

 UF_uArm uarm;


- blink green when open - another tiny accel adjustment

--- GeheimTuer.ino
+++ GeheimTuer.ino
@@ -112,8 +112,8 @@
     brake: false
   },
   { // accelerate and keep running
-    maxMillis: 2000,
-    stepMillis: 5,
+    maxMillis: 1900,
+    stepMillis: 4,
     factor: 1,
     add: 1,
     minPWM: 0,
@@ -213,7 +213,7 @@
 // TODO: use structured profiles
 const unsigned long ledSolidInterval = 250; // constantly update LED stripe in solid mode
 const unsigned long ledFadeInterval = 20;
-const unsigned long ledBlinkInterval = 1000;
+const unsigned long ledBlinkInterval = 500;
 const unsigned long ledMoveInterval = 250; // shift LED window every X ms
 unsigned long ledMillis = 0;

@@ -427,7 +427,7 @@
         debug(currentMillis, F("Total ms: "));
         Serial.println(driveTotalMillis);
         openMillis = 0;
-        setLeds1(green, ledSolid);
+        setLeds1(green, ledBlink);
         doorState = doorOpen;
         break;
       }


extend map

extend map

extend map and now no longer skips the last map step


Added global variables and decode command function

--- Arduino/Arduino.ino
+++ Arduino/Arduino.ino
@@ -6,6 +6,51 @@
 #define BUFFSIZE   255
 #define MAX_POWER  400
 #define DELAY 50
+// Android --> Arduino codes
+#define CMD_NULL_VALUE 0
+#define CMD_MOVE_FORWARD 1
+#define CMD_MOVE_BACKWARD 6
+#define CMD_STOP 2
+#define CMD_LEFT 3
+#define CMD_RIGHT 4
+#define CMD_SHOOT 5
+#define CMD_SEARCH 10
+
+// Arduino --> Aandroid codes
+// Message types
+#define INFO = 0;
+#define STATE = 1;
+// States
+#define IDLE = 100;
+#define SEARCHING = 101;
+#define HUNTING = 102;
+#define EMERGENCY = 103;
+// Actions
+#define STOPPED = 150;
+#define MOVING = 151;
+// Infos
+#define SHOOTED = 201;
+#define RELOADED = 202;
+#define DISTANCE = 203;
+
+// Motors definition
+//Ch A = LEFT, Ch B = RIGTH
+const int
+PWM_LEFT   = 3,
+DIR_LEFT   = 12,
+BRAKE_LEFT = 9,
+SNS_LEFT  = A0;
+const int
+PWM_RIGHT   = 11,
+DIR_RIGHT   = 13,
+BRAKE_RIGHT = 8,
+SNS_RIGHT  = A1;
+
+int
+command,
+param1,
+param2;
+

 // Start Accessory Descriptor. It's how Arduino identifies itself in Android.
@@ -21,15 +66,16 @@
 USBHost Usb;
 ADK adk(&Usb, manufacturer, model, accessoryName, versionNumber, url, serialNumber);
 // End ADK configuration
-bool DEBUG_MODE = true;
-
+// Debug mode for communication
+bool COM_DEBUG_MODE = false;
+// Debug mode for movment
+bool MOV_DEBUG_MODE = true;
 uint8_t inBuffer[BUFFSIZE];
 uint8_t outBuffer[BUFFSIZE];
 char inStringBuffer[BUFFSIZE];
 char outStringBuffer[BUFFSIZE];
 uint32_t bytesRead = 0;

-DualMC33926MotorShield tank;

 // Test Variabiles
 int randomint;
@@ -39,11 +85,11 @@
   Serial.begin(115200);
   delay(1000);
   Serial.println("All power to the engines!");
-  tank.init();
+
 }

 void loop() {
-  if (DEBUG_MODE) {
+  if (COM_DEBUG_MODE) {
     Serial.print(".");
   }
   Usb.Task();
@@ -51,11 +97,18 @@
   if (adk.isReady()) {
     char*a;
     if (strlen(a = readFromADK()) > 0) {
-      Serial.println(strlen(a));
+      if (decodeCommand(a, &command, &param1, &param2)){
+      Serial.println("Fuori");
+      Serial.println(command);
+      Serial.println(param1);
+      Serial.println(param2);
+      }else{
+      Serial.print("Command ");Serial.print(command);Serial.print(", param1 ");Serial.print(param1);Serial.print(", param2 ");Serial.print(param2);Serial.println(", is not valid!");
+      }
     } else {
       Serial.print("*");
     }
-    sendToADK( random(0,2), random(0,4) + random(1,3)*100, random(150,152));
+    sendToADK( random(0, 2), random(0, 4) + random(1, 3) * 100, random(150, 152));
   }
   delay(DELAY);
 }
@@ -65,7 +118,7 @@
   memset(inStringBuffer, 0, BUFFSIZE);
   if (bytesRead > 0) {
     memcpy(inStringBuffer, inBuffer, bytesRead);
-    if (DEBUG_MODE) {
+    if (COM_DEBUG_MODE) {
       Serial.print("\nReceiving | ");
       Serial.print(inStringBuffer);
       Serial.print(" | ");
@@ -82,7 +135,7 @@
   sprintf(outStringBuffer, "%d,%d,%d", command, param1, param2);
   memcpy(outBuffer, outStringBuffer, BUFFSIZE);
   adk.write(strlen(outStringBuffer), outBuffer);
-  if (DEBUG_MODE) {
+  if (COM_DEBUG_MODE) {
     Serial.print("\nSending | ");
     Serial.print(outStringBuffer);
     Serial.print(" | ");
@@ -98,10 +151,10 @@
     last_send = time;
     randomint = random(-1500, 1500);
     memset(outStringBuffer, 0, BUFFSIZE);
-    sprintf(outStringBuffer, "%d,%d,%d",command, param1, param2);
+    sprintf(outStringBuffer, "%d,%d,%d", command, param1, param2);
     memcpy(outBuffer, outStringBuffer, BUFFSIZE);
     adk.write(strlen(outStringBuffer), outBuffer);
-    if (DEBUG_MODE) {
+    if (COM_DEBUG_MODE) {
       Serial.print("\nSending | ");
       Serial.print(outStringBuffer);
       Serial.print(" | ");
@@ -112,9 +165,38 @@
   delay(DELAY / 10);
 }

-
+bool decodeCommand(char* incoming, int* command, int* param1, int* param2) {
+  // Incoming message pattern command,param1,param2
+  char delimiter = ',';
+  *command = atoi(strtok(incoming, &delimiter));
+  *param1 = atoi(strtok(NULL, &delimiter));
+  *param2 = atoi(strtok(NULL, &delimiter));
+  //checking validity of decoded commanda
+  if (*command == CMD_MOVE_FORWARD && (*param1 == CMD_NULL_VALUE || *param2 == CMD_NULL_VALUE)) {
+    return false;
+  }
+  if (*command == CMD_MOVE_BACKWARD && (*param1 == CMD_NULL_VALUE || *param2 == CMD_NULL_VALUE)) {
+    return false;
+  }
+  if (*command == CMD_STOP  && *param2 != CMD_NULL_VALUE) {
+    return false;
+  }
+  if (*command == CMD_LEFT  && *param2 != CMD_NULL_VALUE) {
+    return false;
+  }
+  if (*command == CMD_RIGHT && *param2 != CMD_NULL_VALUE) {
+    return false;
+  }
+  if (COM_DEBUG_MODE || MOV_DEBUG_MODE) {
+    Serial.println(*command);
+    Serial.println(*param1);
+    Serial.println(*param2);
+  }
+  return true;
+
+
+}
 void stopEngine() {
-  tank.setM1Speed(0);
-  tank.setM2Speed(0);
-}
-
+
+}
+


simplify the remote to accept commands, something else should be sending them

--- ir-duino/ir-duino.ino
+++ ir-duino/ir-duino.ino
@@ -7,12 +7,6 @@
 #define BLINKLED_OFF()  (digitalWrite(BLINKLED, LOW))

 IRsend irsend;
-
-void debugVars(int loopCount) {
-    Serial.println((String) "loop " + loopCount);
-}
-
-int loopCount = 0;

 void setup() {
     Serial.begin(115200); //You may alter the BAUD rate here as needed
@@ -28,7 +22,7 @@

     while (Serial.available()) {
         delay(3);  //delay to allow buffer to fill
-        if (Serial.available() >0) {
+        if (Serial.available() > 0) {
             char c = Serial.read();  //gets one byte from serial buffer
             readString += c; //makes the string readString
         }
@@ -38,11 +32,7 @@
         return;
     }

-    loopCount += 1;
-    debugVars(loopCount);
-
-
-    if (readString == "r") {
+    if (readString == "... ") {
         if (lastString.length() <= 0) {
             Serial.println((String) "Command not saved");
             return;
@@ -52,157 +42,17 @@
     }
     lastString = readString;

-    if (readString.substring(0,2) == "yama ") {
-        return handleYamaha(readString.substring(2));
-    } else if (readString.substring(0,2) == "sams ") {
-        return handleSamsung(readString.substring(2));
+    if (readString.substring(4,6) == "0x") {
+        long decimal_answer = strtol(readString.substring(4).c_str(), NULL, 16);
+
+        if (readString.substring(0,4) == "nec ") {
+            irsend.sendNEC(decimal_answer, 32);
+            return;
+        } else if (readString.substring(0,4) == "sam ") {
+            irsend.sendSAMSUNG(decimal_answer, 32);
+            return;
+        }
     }

-    Serial.println((String) "Unknown command: " + readString);
+    Serial.println((String) "Unknown command: [" + readString + "]");
 }
-
-void handleSamsung(String command) {
-    String message = "handleSamsung: ";
-    Serial.println(message + command);
-
-    if (command.substring(0,2) == "0x") {
-        long decimal_answer = strtol(command.c_str(), NULL, 16);
-        Serial.println(decimal_answer);
-        return sendCommand_Samsung(command, decimal_answer, 32);
-    }
-    //else if (command == "vd") return sendCommand_Samsung(command, SAMSUNG_KEY_VOLUMEDOWN, 32);
-    //else if (command == "vu") return sendCommand_Samsung(command, SAMSUNG_KEY_VOLUMEUP, 32);
-    //else if (command == "vm") return sendCommand_Samsung(command, SAMSUNG_MUTING, 32);
-}
-
-void sendCommand_Samsung(String command, unsigned long data, int bits) {
-    String message = "Samsung: found command: ";
-    Serial.println(message + command);
-    irsend.sendSAMSUNG(data, bits);
-    delay(1000);
-
-    for (int i = 0; i < 3; i++) {
-        Serial.println(message + command);
-        irsend.sendSAMSUNG(data, bits);
-        delay(40);
-    }
-}
-
-// KEY_SLEEP                0x000000005EA18778 // B
-// KEY_POWER                0x000000005EA147B8 // tuner preset group C
-// KEY_MUTE                 0x000000005EA1C738 // tuner preset group D
-// KEY_VOLUMEDOWN           0x000000005EA127D8 // tuner preset group E
-// volume^                  0x000000005EA1A758 // tuner preset group sub change
-
-#define YAMAHA_SOURCE_PHONO             0x5EA128D7
-#define YAMAHA_SOURCE_CD                0x5EA1A857
-#define YAMAHA_SOURCE_TUNER             0x5EA16897
-#define YAMAHA_SOURCE_VCR_1             0x5EA1F00F
-#define YAMAHA_SOURCE_DVR               0x5EA1C837
-#define YAMAHA_SOURCE_DVD               0x5EA1837C
-
-#define YAMAHA_EFFECT_HALLS             0x5EA111EE
-#define YAMAHA_EFFECT_CLUBS             0x5EA1916E
-#define YAMAHA_EFFECT_SPORTS            0x5EA151AE
-#define YAMAHA_EFFECT_MONO_MOVIE        0x5EA1D12E
-#define YAMAHA_EFFECT_PROLOGIC          0x5EA1B14E // neo6/PL II/Pro Logic
-#define YAMAHA_DSP_EFFECT_ONOFF         0x5EA16A95 // straight / 7chan
-#define YAMAHA_2CH_7CH                  0x5EA131CE // 2ch/7ch stereo
-#define YAMAHA_PURE_DIRECT              0x5EA1BB44 // pure direct
-
-#define YAMAHA_MUTING                   0x5EA138C7
-#define YAMAHA_KEY_VOLUMEUP             0x5EA158A7
-#define YAMAHA_KEY_VOLUMEDOWN           0x5EA1D827
-
-#define YAMAHA_TUNER_ABCDE              0x5EA148B7
-#define YAMAHA_TUNER_PRESET_1           0x5EA1A758
-#define YAMAHA_TUNER_PRESET_6           0x5EA157A8
-#define YAMAHA_TUNER_PRESET_DOWN        0x5EA18877
-#define YAMAHA_TUNER_PRESET_UP          0x5EA108F7
-
-#define YAMAHA_MENU_UP                  0x5EA1B946
-#define YAMAHA_MENU_DOWN                0x5EA139C6
-#define YAMAHA_MENU_LEFT                0x5EA1F906
-#define YAMAHA_MENU_RIGHT               0x5EA17986
-#define YAMAHA_MENU_ENTER               0x5EA17B84
-#define YAMAHA_MENU_RETURN              0x5EA155AA
-#define YAMAHA_MENU_ON_SCREEN           0x5EA121DE
-#define YAMAHA_MENU_OPTION              0x5EA1D628
-
-#define YAMAHA_OFF                      0x7e81fe01
-#define YAMAHA_SLEEP                    0x5EA1EA15
-#define YAMAHA_ZONE1_ON                 0x7e817e81
-#define YAMAHA_ZONE2_ON                 0x5EA1FB04
-
-#define YAMAHA_PRM_7CH                  0x5EA123DC
-
-// TapeMon                xx0x5EA131CE // 7ch stereo
-// 14                     xx0x5EA1BB44 // pure direct
-// 16                     xx0x5EA1FB04 // zone2 on
-// Effect                 xx0x5EA1837C // source DVD
-// Down                   xx0x5EA123DC // program 7ch
-// VolUp                  0x5EA1B14E // program surround decoder
-
-
-void handleYamaha(String command) {
-    String message = "handleYamaha: ";
-    Serial.println(message + command);
-
-    if (command.substring(0,2) == "0x") {
-        long decimal_answer = strtol(command.c_str(), NULL, 16);
-        Serial.println(decimal_answer);
-        return sendCommand_Yamaha(command, decimal_answer, 32);
-    }
-    else if (command == "off")
-        return sendCommand_Yamaha(command, YAMAHA_OFF, 32);
-    else if (command == "zone1 on")
-        return sendCommand_Yamaha(command, YAMAHA_ZONE1_ON, 32);
-    else if (command == "zone2 on")
-        return sendCommand_Yamaha(command, YAMAHA_ZONE2_ON, 32);
-    else if (command == "vd")
-        return sendCommand_Yamaha(command, YAMAHA_KEY_VOLUMEDOWN, 32);
-    else if (command == "vu")
-        return sendCommand_Yamaha(command, YAMAHA_KEY_VOLUMEUP, 32);
-    else if (command == "vm")
-        return sendCommand_Yamaha(command, YAMAHA_MUTING, 32);
-    else if (command == "setup")
-        return sendCommand_Yamaha(command, YAMAHA_MENU_ON_SCREEN, 32);
-    else if (command == "up")
-        return sendCommand_Yamaha(command, YAMAHA_MENU_UP, 32);
-    else if (command == "down")
-        return sendCommand_Yamaha(command, YAMAHA_MENU_DOWN, 32);
-    else if (command == "left")
-        return sendCommand_Yamaha(command, YAMAHA_MENU_LEFT, 32);
-    else if (command == "right")
-        return sendCommand_Yamaha(command, YAMAHA_MENU_RIGHT, 32);
-    else if (command == "enter")
-        return sendCommand_Yamaha(command, YAMAHA_MENU_ENTER, 32);
-    else if (command == "return")
-        return sendCommand_Yamaha(command, YAMAHA_MENU_RETURN, 32);
-    else if (command == "reset") {
-        sendCommand_Yamaha(command, YAMAHA_2CH_7CH, 32);
-        return;
-    }
-    else if (command == "source cd")
-        return sendCommand_Yamaha(command, YAMAHA_SOURCE_CD, 32);
-    else if (command == "source dvd")
-        return sendCommand_Yamaha(command, YAMAHA_SOURCE_DVD, 32);
-    else if (command == "source tuner")
-        return sendCommand_Yamaha(command, YAMAHA_SOURCE_TUNER, 32);
-    else if (command == "tuner up")
-        return sendCommand_Yamaha(command, YAMAHA_TUNER_PRESET_UP, 32);
-    else if (command == "tuner down")
-        return sendCommand_Yamaha(command, YAMAHA_TUNER_PRESET_DOWN, 32);
-    else {
-        command = "0x000000005EA1" + command;
-        long decimal_answer = strtol(command.c_str(), NULL, 16);
-        Serial.println(decimal_answer);
-        return sendCommand_Yamaha(command, decimal_answer, 32);
-    }
-}
-
-void sendCommand_Yamaha(String command, unsigned long data, int bits) {
-    Serial.println((String) "Found command: " + command);
-    irsend.sendNEC(data, bits);
-}
-


Fix the wait for wifi connection

Fix the wait for wifi connection

--- barf_esp8266.ino
+++ barf_esp8266.ino
@@ -62,7 +62,7 @@

 	// If a timeout of 0 is used this might try forever, locking up the code.
 	unsigned long before = millis();
-	while (is_connected()) {
+	while (!is_connected()) {
 		if (timeout && millis() - before > timeout) {
 			return;
 		}


à finir de débuguer cf commentaire debut de fichier

--- calibrateur.ino
+++ calibrateur.ino
@@ -7,6 +7,7 @@
 # Program principal:

+//a faire pour prochaine fois : pendant les grandes course vérifier si avec le nouveauc compteur qui peut etre négatif ça marche bien. autre point de suspissionde bug : la vitesse qui est trop élevé et que le servo n'arrive pas à suivre.

 //afaire : faire un réinit propre car si on fait 2 étalonnage à la suite ca marche pas
@@ -43,10 +44,10 @@

 //------------------------------------------------------------------------------
 #define DELTA 150
-#define TEMPOSLEEP 800
+#define TEMPOSLEEP 2000
 //en ms le temps d'etre sur que le servo ait bougé
 //d'un increment quand on fait les mesure à la roue codeuse
-
+#define PINVOIEB 3 //la pin surlaquelle est branché la voie B
 #define ERREURCOMPTAGE 10 //la tolérance de comptage avant que l'on estime que le servo est arrivé au bout
 #define NBRCYCLE_AR 10 //nbre de cycle d'aller et retour pour la fin des mesure de caractérisation et nbr de cycle pour la mesure des PWMIN et PWMMAX
 #define TEMPO_STAT 200 // tempo pour laisser le servo avancer lors des mesures
@@ -195,7 +196,7 @@

 //------------------------------------------------------------------------------
 //La tache Scoop
-defineTask(reflechi)
+defineTask(reflechi,250)
     void reflechi::setup(){ }
     void reflechi::loop()
     //defineTimerRun(reflechi,40)
@@ -295,7 +296,7 @@
                             Serial.println(F("retour au début de procédure"));
                             etatCalibrateur=USB;
                         }
-                    if (ERREURCOMPTAGE*3>compteurRef)
+                    if (ERREURCOMPTAGE*3>abs(compteurRef))
                     {
                         Serial.println(F("ce serait bien que la marge d'erreur soit de l'ordre de 30% de la mesure de reference"));
                         Serial.println(F("je vais faire autre chose.... Programme a recompiler"));
@@ -364,7 +365,7 @@
                             leServo.setObjectif(leServo.getMax());
                             sleep(TEMPO_STAT);
                             Serial.print("cmpt="); Serial.println(compteur);
-                            while (compteur>compteurRef+20)
+                            while (abs(compteur)>abs(compteurRef)+20)
                                 {
                                     compteurRef=compteur;
                                     Serial.print("yop");
@@ -579,6 +580,7 @@
 void setup()
 {
   int vitesseDinit;
+  pinMode(PINVOIEB, INPUT);
     Serial.begin(57600);
     //potence.setPotence();
   lePotar.init();
@@ -602,14 +604,22 @@
     temp=millis();
     //etatCalibrateur=3; fait dans l'init de la variable
     affichage.affiche(POTAR);
-    attachInterrupt(0, updatePulseCompteur, CHANGE ); // Int0= la pin N°2 sur un UNO
+    attachInterrupt(0, updatePulseCompteur, RISING ); // Int0= la pin N°2 sur un UNO
 }
  void updatePulseCompteur()
 {
-    compteur++;
+    if (digitalRead(PINVOIEB))
+		{compteur++;       }
+	else
+		{compteur--;}
+
 }

-
+int freeRam () {
+    extern int __heap_start, *__brkval;
+    int v;
+    return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
+}

 void loop ()
@@ -619,8 +629,10 @@
         {
             temp=millis();
 			Serial.println();
-            Serial.print("stackLeft=");
+            Serial.print("stackLeftScoop=");
             Serial.println(reflechi.stackLeft());
+			Serial.print("freeRam=");
+            Serial.println(freeRam());
         }

 }


finalited LDR; gCycleCounter introduced

finalited LDR; gCycleCounter introduced

--- TreibBoje1.ino
+++ TreibBoje1.ino
@@ -1,7 +1,7 @@
 //
 // File   : TreibBoje1.ino
 //
-// Purpose: Frame for fun project 'Treibbojen' (experimental)
+// Purpose: Frame for fun project 'Treibboje1' (experimental)
 //
 // $Id$
 //
@@ -58,7 +58,7 @@

 #ifdef USE_LDR
  // define a pin for Photo resistor (ADC input!)
- #define LDR_PIN     0
+ #define LDR_PIN    14
 #endif // USE_LDR

 // Data wire is plugged into port 2 on the Arduino
@@ -83,6 +83,9 @@
 // sensor #5
 DeviceAddress gSensor5 = { 0x28, 0x6B, 0x84, 0xDF, 0x06, 0x00, 0x00, 0xBB };

+// a global cycle counter
+static uint16_t gCycleCounter = 0;
+
 /**
  * Initialization
  */
@@ -115,7 +118,7 @@
   //theSender.setProtocol(1);  // -> setPulseLength(350); '0' = 1,3
 #endif // SEND_DATA

-#ifdef SCAN_SENSORS
+#if (defined SCAN_SENSORS) && (defined DEBUG)
   // locate devices on the bus
   Serial.print(F("Locating devices..."));
   Serial.print(F("Found "));
@@ -147,7 +150,7 @@
       sensors.setResolution(addr, TEMPERATURE_PRECISION);
     }
   }
-#endif // SCAN_SENSORS
+#endif // SCAN_SENSORS && DEBUG

 #ifdef USE_LDR
   //           PhotoR     10K
@@ -156,6 +159,9 @@
   // Pin 0 o----------+
   //
   pinMode( LDR_PIN, INPUT );
+
+  // change range and resolution of analog pin, default
+  analogReference(DEFAULT);
 #endif // USE_LDR
 }

@@ -185,13 +191,16 @@
 //  D11 D10 D9 D8 | D7 D6 D5 D4 | D3 D2 D1 D0
 //   a2  a1 a0 d8   d7 d6 d5 d4   d3 d2 d1 d0
 //
+// - a2a1a0 = 0 specifies the cycle counter
+// - a2a1a0 = 1..5 specifies the temperature sensors
+//            which therefor operate in 9 bit mode
+// - a2a1a0 = 6 specifies the LDR message
 // - a2a1a0 = 7 specifies sync messages
-// - a2a1a0 = 1..5 specified the temperature sensors
-//            which therefor operate in 9 bit mode
 //
 #ifdef SEND_DATA
  #define SEND_SYNC(_x) theSender.send((_x & 0x1ff) | 0x0e00, 12)
- #define SEND_LDR(_x) theSender.send((_x & 0x1ff), 12)
+ #define SEND_CYCLE_COUNTER() theSender.send((gCycleCounter & 0x1ff), 12)
+ #define SEND_LDR(_x) theSender.send((_x & 0x1ff) | (0x0600 << 1), 12)
  #define SEND_T1(_x) theSender.send((_x & 0x1ff) | (0x0100 << 1), 12)
  #define SEND_T2(_x) theSender.send((_x & 0x1ff) | (0x0200 << 1), 12)
  #define SEND_T3(_x) theSender.send((_x & 0x1ff) | (0x0300 << 1), 12)
@@ -199,6 +208,7 @@
  #define SEND_T5(_x) theSender.send((_x & 0x1ff) | (0x0500 << 1), 12)
 #else
  #define SEND_SYNC(_x) {}
+ #define SEND_CYCLE_COUNTER() {}
  #define SEND_LDR(_x) {}
  #define SEND_T1(_x) {}
  #define SEND_T2(_x) {}
@@ -220,6 +230,11 @@
 #endif // SEND_DATA

   SEND_SYNC(1);
+
+  SEND_CYCLE_COUNTER();
+#ifdef DEBUG
+  Serial << "# " << gCycleCounter << endl;
+#endif // DEBUG

 #ifdef READ_SENSORS
   if ( sensors.getDeviceCount() > 0 ) {
@@ -294,6 +309,8 @@
 #endif // USE_LDR

   SEND_SYNC(2);
+
+  gCycleCounter = ( gCycleCounter == 0x1ff ) ? 0 : (gCycleCounter+1);
 }

 /**
@@ -330,4 +347,4 @@
   Serial.println();
 }

-
+


chnage #49

chnage #49

https://github.com/tschaban/AFE-Firmware/issues/49

--- T0/src/AFE-MQTT.ino
+++ T0/src/AFE-MQTT.ino
@@ -101,7 +101,10 @@
             */
             break;
           }
-          delay(durationBetweenConnectionAttempts * 1000);
+          Led.on();
+          delay(durationBetweenConnectionAttempts * 500);
+          Led.off();
+          delay(durationBetweenConnectionAttempts * 500);
           /* Serial << "."; */
         }
       }


Delete trabajoEmpotrados.ino

Delete trabajoEmpotrados.ino

Borrado el maldito empotrados.ino

--- trabajoEmpotrados.ino
+++ trabajoEmpotrados.ino
@@ -1,222 +0,0 @@
-#include "Enumerations.h"
-#include "ProcessCommands.h"
-#include "ComunicacionBluetooth.h"
-
-const int DEDOS = 4;
-
-//state of the hand
-int flexs[DEDOS];
-int pressures[DEDOS];
-
-//previous state of the hand
-int previousFlexs[DEDOS];
-int previousPressures[DEDOS];
-
-//processed state of hand
-ClickButton buttons[DEDOS];
-boolean flexorActived[DEDOS]; //the value of them is stored in flexs (no need to process them)
-
-
-//values of the flex sensor
-const int minimumSensorFlex = 10;
-const int maximumSensorFlex = 40;
-//values which will use with the flex sensor
-const int minimumFlex = 0;
-const int maximumFlex = 100;
-//dead zone flexion
-const int deadFlexion=20;
-
-//values of the pressure sensor
-const int minimumSensorPressure = 10;
-const int maximumSensorPressure = 40;
-//values which will use with the pressure sensor
-const int minimumPressure = 0;
-const int maximumPressure = 100;
-//dead zone pressure
-const int deadPressure = 10;
-//strong pressure
-const int strongPressure = 50;
-
-//time of pressing sensor
-unsigned long timePressure[DEDOS];
-unsigned long timer=0;
-unsigned long timeResponse=200;
-
-const int FLEXOR = 1;
-const int PRESSURE = 2;
-
-//pins of sensors
-int flexSensorPin[DEDOS];
-int pressureSensorPin[DEDOS];
-
-
-/**
- * Read a concrete sensor given the type of sensor and the number
- */
-int valueOfSensor(int typeSensor, int sensor){
-  int valueSensor = 0;
-  int valueFinal = 0;
-
-  if(typeSensor == FLEXOR){
-    valueSensor = analogRead(flexSensorPin[sensor]);
-    Serial.println("Flexor: " + valueSensor);
-    valueFinal = map(valueSensor, minimumSensorFlex, maximumSensorFlex, minimumFlex, maximumFlex);
-    Serial.println("Flexor process: " + valueFinal);
-
-  }
-  else if(typeSensor == PRESSURE){
-    valueSensor = analogRead(pressureSensorPin[sensor]);
-    Serial.println("Pressure: " + valueSensor);
-    valueFinal = map(valueSensor, minimumSensorPressure, maximumSensorPressure, minimumPressure, maximumPressure);
-    Serial.println("Pressure process: " + valueFinal);
-
-  }
-
-  Serial.println();
-  return valueFinal;
-}
-
-/**
- * Read the whole state of the hand (flexion and contact)
- */
-void readState(){
-  //read the values of the flex's sensors
-  for (int i=0; i<DEDOS; i++){
-    flexs[i] = valueOfSensor(FLEXOR, i);
-  }
-
-  //read the values of the pressure's sensors
-  for (int i=0; i<DEDOS; i++){
-    pressures[i] = valueOfSensor(PRESSURE, i);
-  }
-}
-
-/**
- * Dado el delay de la ultima vez que se proceso y el boton que se quiere mirar
- * se comprueba si ha habido pulsacion, pulsacion fuerte/larga o nada
- * devuelve un int que corresponde a la enumeracion
- */
-ClickButton processButton(int delay, int button){
-  int compareStates= ((previousPressures[button]-deadPressure) > 0) ? 1:0;
-  compareStates= ((pressures[button]-deadPressure) > 0) ? compareStates+1:compareStates;
-  boolean touch=false;
-  boolean strong=false;
-
-  //comprobamos fuerza, si la supera, es strong y touch
-  if(pressures[button]>=(strongPressure+deadPressure)){
-    strong=true;
-    touch=true;
-
-    //boton pulsado antes y despulsado, cuenta como toque
-  }
-  else  if( compareStates == 2 ){
-    touch=true;
-
-    //boton se mantiene pulsado
-  }
-  else if(compareStates == 3){
-    //sumamos el tiempo transcurrido
-    timePressure[button]+=delay;
-    //si ha superado el tiempo, cuenta como toque
-    if(timePressure[button]>timeResponse){
-      touch=true;
-    }
-  }
-
-  //procesamos resultado
-  if(touch){
-    //seteamos el actual valor como no pulsado para que no se vuelva a tener en cuenta el siguiente frame
-    pressures[button]=0;
-    //igualmente reseteamos su tiempo transcurrido
-    timePressure[button]=0;
-
-    //proceso fuerza y accion
-    if(strong){
-      return long_click;
-    }
-    else{
-      return normal_click;
-    }
-  }
-  return no_click;
-}
-
-/**
- * Proceso el estado al completo de la mano y actuo en consecuencia
- */
-int processState(int delay){
-  //ante el procesado, escribir por pantalla que accion ha realizado, despues
-  //refinamos haciendo los envios por bluetooth
-
-  //comprobamos...
-  for (int i=0; i<DEDOS; i++){
-    //comprobamos botones
-    buttons[i]=processButton(delay, i);
-    switch(buttons[i]){
-    case normal_click:
-      Serial.println("Click normal de "+i);
-      break;
-    case long_click:
-      Serial.println("Click fuerte de "+i);
-      break;
-    case no_click:
-      break;
-    }
-
-    //comprobamos flexores
-    if((flexs[i]-deadFlexion) > 0){
-      flexorActived[i]=true;
-    }
-    else{
-      flexorActived[i]=false;
-    }
-  }
-}
-
-/**
- * Mueve el estado actual a un estado previo para poder leer el siguiente estado
- */
-void nextState(){
-  for (int i=0; i<DEDOS; i++){
-    previousFlexs[i] = flexs[i];
-    previousPressures[i] = pressures[i];
-  }
-}
-
-
-
-
-
-
-
-
-void setup(){
-  Serial.begin(9600);
-
-  //TODO setear los pines
-  pressures[0]=8;
-    pressures[0]=10;
-      pressures[0]=12;
-        pressures[0]=14;
-
-
-  for (int i=0; i<DEDOS; i++){
-    timePressure[i]=0;
-    flexorActived[i]=false;
-    flexs[i] = 0;
-    pressures[i] = 0;
-  }
-  //copio los valores al previous
-  readState();
-
-  timer=millis();
-}
-
-void loop(){
-  readState();
-  processState(millis()-timer);
-  //processCommands();
-  timer=millis();
-  nextState();
-}
-


Set TX & RX of SIM900

Set TX & RX of SIM900

--- monitor_client/monitor_client.ino
+++ monitor_client/monitor_client.ino
@@ -5,7 +5,7 @@
 #include "DHT11.h"
 #define DHT11PIN 2
 dht11 DHT11;
-GPRS gprs(PIN_TX, PIN_RX, BAUDRATE,"cmnet");
+GPRS gprs(7, 8, BAUDRATE,"cmnet");
 char target_url[61];
 char buffer[128];

@@ -38,7 +38,7 @@
   if(false == gprs.connect(TCP,"monitor.ourjnu.com", 80)) {
       Serial.println("connect error");
   }else{
-      Serial.println("connect mbed.org success");
+      Serial.println("connect monitor.ourjnu.com success");
   }

   Serial.println("waiting to fetch...");


Update console2modem for Akene shield

Update console2modem for Akene shield

--- console2modem/console2modem.ino
+++ console2modem/console2modem.ino
@@ -3,6 +3,8 @@

 // Akeru UNB modem : S_RX is D4, S_TX is D5
 SoftwareSerial modem(5,4); //uC Rx D5, Tx D4
+// Akene UNB modem : S_RX is D5, S_TX is D4
+//SoftwareSerial modem(4,5); //uC Rx D4, Tx D5

 void setup()
 {


clean up code formatting, and, start off with random instead of always using classic first

--- CocaCola/CocaCola.ino
+++ CocaCola/CocaCola.ino
@@ -164,74 +164,74 @@
 }

 void outsideInOnInsideOutOffBackground(int times, int endingWithLightsOn) {
-  for (int count = 0; count < times; count++) {
-      backgroundOnOutsideIn();
-      delay(ish);
-    if (count + 1 != times || !endingWithLightsOn) {
-      backgroundOffInsideOut();
-          delay(ish);
-    }
-  }
+    for (int count = 0; count < times; count++) {
+        backgroundOnOutsideIn();
+        delay(ish);
+        if (count + 1 != times || !endingWithLightsOn) {
+            backgroundOffInsideOut();
+            delay(ish);
+        }
+    }
 }

 void insideOutOnOutsideInOffBackground(int times, int endingWithLightsOn) {
-  for (int count = 0; count < times; count++) {
-      backgroundOnInsideOut();
-      delay(ish);
-     if (count + 1 != times || !endingWithLightsOn) {
-       backgroundOffOutsideIn();
-     }
-   }
+    for (int count = 0; count < times; count++) {
+        backgroundOnInsideOut();
+        delay(ish);
+        if (count + 1 != times || !endingWithLightsOn) {
+            backgroundOffOutsideIn();
+        }
+    }
 }

 void insideOutOutsideInBackground() {
-  for (int i = 0; random(3, 8); i++) {
-    if (random(0, 2) == 0) {
-      outsideInOnInsideOutOffBackground(random(1, 4), true);
-      delay(minimal);
-
-      insideOutOnOutsideInOffBackground(random(1, 4), false);
-      delay(minimal);
-    } else {
-      insideOutOnOutsideInOffBackground(random(1, 4), true);
-      delay(minimal);
-
-      outsideInOnInsideOutOffBackground(random(1, 4), false);
-      delay(minimal);
-    }
-  }
+    for (int i = 0; random(3, 8); i++) {
+        if (random(0, 2) == 0) {
+            outsideInOnInsideOutOffBackground(random(1, 4), true);
+            delay(minimal);
+
+            insideOutOnOutsideInOffBackground(random(1, 4), false);
+            delay(minimal);
+        } else {
+            insideOutOnOutsideInOffBackground(random(1, 4), true);
+            delay(minimal);
+
+            outsideInOnInsideOutOffBackground(random(1, 4), false);
+            delay(minimal);
+        }
+    }
 }

 void racingOnLeftToRightBackground() {
-  for (int x = 0; x < sizeof(background); x++) {
-    for (int y = 0; y < sizeof(background) - x - 1; y++) {
-      digitalWrite(background[y], PATTERN_ON);
-      delay(minimal);
-      digitalWrite(background[y], PATTERN_OFF);
-      delay(none);
-    }
-
-    digitalWrite(background[sizeof(background) - x - 1], PATTERN_ON);
-    delay(minimal);
-  }
+    for (int x = 0; x < sizeof(background); x++) {
+        for (int y = 0; y < sizeof(background) - x - 1; y++) {
+            digitalWrite(background[y], PATTERN_ON);
+            delay(minimal);
+            digitalWrite(background[y], PATTERN_OFF);
+            delay(none);
+        }
+
+        digitalWrite(background[sizeof(background) - x - 1], PATTERN_ON);
+        delay(minimal);
+    }
 }

 void blinkBackgroundPairLeftToRight() {
-  int half = sizeof(background) / 2;
-
-  for (int count = 0; count < random(5, 10); count++) {
-    for (int x = 0; x < half; x++) {
-      digitalWrite(background[x], PATTERN_ON);
-      delay(none);
-      digitalWrite(background[x + half], PATTERN_ON);
-      delay(minimal);
-
-      digitalWrite(background[x], PATTERN_OFF);
-      delay(none);
-      digitalWrite(background[x + half], PATTERN_OFF);
-      delay(none);
-    }
-  }
+    int half = sizeof(background) / 2;
+
+    for (int count = 0; count < random(5, 10); count++) {
+        for (int x = 0; x < half; x++) {
+            digitalWrite(background[x], PATTERN_ON);
+            delay(none);
+            digitalWrite(background[x + half], PATTERN_ON);
+            delay(minimal);
+
+            digitalWrite(background[x], PATTERN_OFF);
+            delay(none);
+            digitalWrite(background[x + half], PATTERN_OFF);
+            delay(none);
+        }
+    }
 }

 void blinkLetters(int times) {
@@ -245,117 +245,117 @@
 }

 void blinkBackground(int times) {
-  for (int x = 0; x < times; x++) {
-      backgroundAllOff();
-      delay(blinky);
-
-      backgroundAllOn();
-      delay(blinky);
-  }
-
-  delay(normal);
+    for (int x = 0; x < times; x++) {
+        backgroundAllOff();
+        delay(blinky);
+
+        backgroundAllOn();
+        delay(blinky);
+    }
+
+    delay(normal);
 }

 void blinkAllOnRandom() {
-  int state[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-
-  for (int i = 0; i < sizeof(state); i++) {
-    state[i] = 0;
-  }
-
-  int on = 0;
-
-  while (on != sizeof(state)) {
-    int value = random(0, sizeof(state));
-    if (state[value]) {
-      continue;
-    }
-
-    state[value] = 1;
-    int pin = Lights[value];
-    digitalWrite(pin, PATTERN_ON);
-    on++;
-
-    delay(minimal);
-  }
+    int state[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+    for (int i = 0; i < sizeof(state); i++) {
+        state[i] = 0;
+    }
+
+    int on = 0;
+
+    while (on != sizeof(state)) {
+        int value = random(0, sizeof(state));
+        if (state[value]) {
+            continue;
+        }
+
+        state[value] = 1;
+        int pin = Lights[value];
+        digitalWrite(pin, PATTERN_ON);
+        on++;
+
+        delay(minimal);
+    }
 }

 void blinkBackgroundOnRandom() {
-  int state[] = { 0, 0, 0, 0, 0, 0 };
-
-  for (int i = 0; i < sizeof(state); i++) {
-    state[i] = 0;
-  }
-
-  int on = 0;
-
-  while (on != sizeof(state)) {
-    int value = random(0, sizeof(state));
-    if (state[value]) {
-      continue;
-    }
-
-    state[value] = 1;
-    int pin = background[value];
-    digitalWrite(pin, PATTERN_ON);
-    on++;
-
-    delay(minimal);
-  }
+    int state[] = { 0, 0, 0, 0, 0, 0 };
+
+    for (int i = 0; i < sizeof(state); i++) {
+        state[i] = 0;
+    }
+
+    int on = 0;
+
+    while (on != sizeof(state)) {
+        int value = random(0, sizeof(state));
+        if (state[value]) {
+            continue;
+        }
+
+        state[value] = 1;
+        int pin = background[value];
+        digitalWrite(pin, PATTERN_ON);
+        on++;
+
+        delay(minimal);
+    }
 }

 void blinkLettersOnRandom() {
-	// from: int state[] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
-  int state[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-
-  for (int i = 0; i < sizeof(state); i++) {
-    state[i] = 0;
-  }
-
-  int on = 0;
-
-  while (on != sizeof(state)) {
-    int value = random(0, sizeof(state));
-    if (state[value]) {
-      continue;
-    }
-
-    state[value] = 1;
-    int pin = letters[value];
-    digitalWrite(pin, PATTERN_ON);
-    on++;
-
-    delay(minimal);
-  }
+    // from: int state[] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
+    int state[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+    for (int i = 0; i < sizeof(state); i++) {
+        state[i] = 0;
+    }
+
+    int on = 0;
+
+    while (on != sizeof(state)) {
+        int value = random(0, sizeof(state));
+        if (state[value]) {
+            continue;
+        }
+
+        state[value] = 1;
+        int pin = letters[value];
+        digitalWrite(pin, PATTERN_ON);
+        on++;
+
+        delay(minimal);
+    }
 }

 void flickerPattern(int flickerLetters, int flickerBackground) {
-  allOn();
-
-  int max = 0;
-  if (flickerLetters == 1) {
-    max += 12;
-  }
-  if (flickerBackground == 1) {
-    max += 8;
-  }
-  int pin = 0;
-  for (int i = 0; i < random(5, max); i++) {
-    if (i % random(1, max / 3) == 0) {
-      if (flickerLetters == 1 && flickerBackground == 1) {
-        pin = random(0, 2) == 0 ? letters[random(0, sizeof(letters))] : background[random(0, sizeof(background))];
-      } else if (flickerBackground == 1) {
-        pin = background[random(0, sizeof(background))];
-      } else {
-        pin = letters[random(0, sizeof(letters))];
-      }
-    }
-
-    digitalWrite(pin, PATTERN_OFF);
-    delay(random(minimal / 2, minimal));
-    digitalWrite(pin, PATTERN_ON);
-    delay(ish);
-  }
+    allOn();
+
+    int max = 0;
+    if (flickerLetters == 1) {
+        max += 12;
+    }
+    if (flickerBackground == 1) {
+        max += 8;
+    }
+    int pin = 0;
+    for (int i = 0; i < random(5, max); i++) {
+        if (i % random(1, max / 3) == 0) {
+            if (flickerLetters == 1 && flickerBackground == 1) {
+                pin = random(0, 2) == 0 ? letters[random(0, sizeof(letters))] : background[random(0, sizeof(background))];
+            } else if (flickerBackground == 1) {
+                pin = background[random(0, sizeof(background))];
+            } else {
+                pin = letters[random(0, sizeof(letters))];
+            }
+        }
+
+        digitalWrite(pin, PATTERN_OFF);
+        delay(random(minimal / 2, minimal));
+        digitalWrite(pin, PATTERN_ON);
+        delay(ish);
+    }
 }

 // Randomness
@@ -367,50 +367,50 @@

 void runTracer() {
     for (int i = 0; i < sizeof(background); i++) {
-      digitalWrite(background[i], PATTERN_ON);
+        digitalWrite(background[i], PATTERN_ON);
         delay(none);
     }
     for (int i = 0; i < sizeof(letters); i++) {
-      digitalWrite(Lights[i], PATTERN_ON);
-      delay(250);
-      digitalWrite(Lights[i], PATTERN_OFF);
-      delay(250);
-    }
-    for(int j=0; j< 3; j++) {
-
-      for (int i = 0; i < sizeof(letters); i++) {
         digitalWrite(Lights[i], PATTERN_ON);
-        delay(none);
-      }
-      delay(250);
-      for (int i = 0; i < sizeof(letters); i++) {
+        delay(250);
         digitalWrite(Lights[i], PATTERN_OFF);
-        delay(none);
-      }
-      delay(250);
+        delay(250);
+    }
+    for (int j = 0; j < 3; j++) {
+
+        for (int i = 0; i < sizeof(letters); i++) {
+            digitalWrite(Lights[i], PATTERN_ON);
+            delay(none);
+        }
+        delay(250);
+        for (int i = 0; i < sizeof(letters); i++) {
+            digitalWrite(Lights[i], PATTERN_OFF);
+            delay(none);
+        }
+        delay(250);

     }
     delay(250);
 }

 void runLetterPattern() {
-  // if new patterns are added, add a new case statement, and bump up the max random value by one
-  switch (random(0, 3)) {
-  case 0: { lettersOnLeftToRight(); break; }
-  case 1: { blinkLetters(random(5, 10)); break; }
-  case 2: { blinkLettersOnRandom(); break; }
-  default: { break; }
-  }
+    // if new patterns are added, add a new case statement, and bump up the max random value by one
+    switch (random(0, 3)) {
+    case 0: { lettersOnLeftToRight(); break; }
+    case 1: { blinkLetters(random(5, 10)); break; }
+    case 2: {  blinkLettersOnRandom(); break; }
+    default: { break; }
+    }
 }

 void runBackgroundPattern() {
-  switch(random(0, 5)) {
-  case 0: { classicBackground(); break; }
-  case 1: { insideOutOutsideInBackground(); break; }
-  case 2: { racingOnLeftToRightBackground(); break; }
-  case 3: { blinkBackground(random(5, 10)); backgroundAllOn(); break; }
-  case 4: { blinkBackgroundOnRandom(); break; }
-  }
+    switch (random(0, 5)) {
+    case 0: { classicBackground(); break; }
+    case 1: { insideOutOutsideInBackground(); break; }
+    case 2: { racingOnLeftToRightBackground(); break; }
+    case 3: { blinkBackground(random(5, 10)); backgroundAllOn(); break; }
+    case 4: { blinkBackgroundOnRandom(); break; }
+    }
 }

 // Arduino loop
@@ -418,50 +418,47 @@
 void loop() {
     allOff();

-
-
-    runClassic();
-  int blinkMin = 1;
-  int blinkMax = 0;
-  int possibility = random(0, 100);
-
-  if (possibility > 95) { // rare things, only happen 5% of the time
-    switch(random(0, 2)) {
-    case 0:
-      flickerPattern(random(0, 2), random(0, 2));
-      blinkMin = 0;
-      break;
-    case 1:
-      blinkAllOnRandom();
-      blinkMax = 3;
-      break;
-    }
-  } else if (possibility > 70) { // less rare things, happen 25% of the time
-    if (random(0, 200) == 0) {
-      runBackgroundPattern();
-      runLetterPattern();
-    } else {
-      blinkMax = 5;
-
-      runLetterPattern();
-
-      for (int i = 0; i < random(1, 5); i++) {
-        runBackgroundPattern();
-
-        if (random(0, 10) == 0) {
-            blinkLetters(random(1, blinkMax));
-        }
-      }
-    }
-  } else if (possibility > 20) { // the classic coca-cola sign pattern, happen 50% of the time
+    int blinkMin = 1;
+    int blinkMax = 0;
+    int possibility = random(0, 100);
+
+    if (possibility > 95) { // rare things, only happen 5% of the time
+        switch (random(0, 2)) {
+        case 0:
+            flickerPattern(random(0, 2), random(0, 2));
+            blinkMin = 0;
+            break;
+        case 1:
+            blinkAllOnRandom();
+            blinkMax = 3;
+            break;
+        }
+    } else if (possibility > 70) { // less rare things, happen 25% of the time
+        if (random(0, 200) == 0) {
+            runBackgroundPattern();
+            runLetterPattern();
+        } else {
+            blinkMax = 5;
+
+            runLetterPattern();
+
+            for (int i = 0; i < random(1, 5); i++) {
+                runBackgroundPattern();
+
+                if (random(0, 10) == 0) {
+                    blinkLetters(random(1, blinkMax));
+                }
+            }
+        }
+    } else if (possibility > 20) { // the classic coca-cola sign pattern, happen 50% of the time
         runClassic();

         blinkMax = 3;
-  } else { // tracer, happens 20% of the time
-    runTracer();
-
-    blinkMax = 1;
-  }
+    } else { // tracer, happens 20% of the time
+        runTracer();
+
+        blinkMax = 1;
+    }

     blinkLetters(random(blinkMin, blinkMax));

@@ -469,4 +466,3 @@

     delay(ish);
 }
-


Use center of screen for detection

Use center of screen for detection

--- BlinkenScreen.ino
+++ BlinkenScreen.ino
@@ -141,7 +141,7 @@
   s.b[3] = s.b[4] = s.b[5] = button == B4 ? 0x01 : 0x00;

   // Test ball collision with paddle, volley if good
-  if (s.b[0] == ball || s.b[5] == ball)
+  if (s.b[1] == ball || s.b[4] == ball)
     dir ^= 1;

   // Draw the ball


Tidying example code

Tidying example code

--- examples/ESP8266_library_test/ESP8266_library_test.ino
+++ examples/ESP8266_library_test/ESP8266_library_test.ino
@@ -31,7 +31,7 @@
   wifi.endSendWithNewline(true); // Will end all transmissions with a newline and carrage return ie println.. default is true

   wifi.begin();
-  wifi.connectToAP("wifissid", "wifipass");
+  wifi.connectToAP("wifissid", "wifipass");
   wifi.connectToServer("192.168.0.28", "2121");
   wifi.send(SERVER, "ESP8266 test app started");
 }


delete wrong example name

delete wrong example name

--- examples/MeasuringAcceleration/measureAcce.ino
+++ examples/MeasuringAcceleration/measureAcce.ino
@@ -1,52 +0,0 @@
-/*****************************************************************************/
-//	Function:  Get the accelemeter of the x/y/z axis.
-//  Hardware:  Grove - 3-Axis Analog Accelerometer
-//	Arduino IDE: Arduino-1.0
-//	Author:	 Frankie.Chu
-//	Date: 	 Jan 11,2013
-//	Version: v1.0
-//	by www.seeedstudio.com
-//
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License, or (at your option) any later version.
-//
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
-//
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-//
-/*******************************************************************************/
-
-#include "ADXL335.h"
-
-ADXL335 accelerometer;
-void setup()
-{
-	Serial.begin(9600);
-	accelerometer.begin();
-}
-void loop()
-{
-	int x,y,z;
-	accelerometer.getXYZ(&x,&y,&z);
-	Serial.println("value of X/Y/Z: ");
-	Serial.println(x);
-	Serial.println(y);
-	Serial.println(z);
-	float ax,ay,az;
-	accelerometer.getAcceleration(&ax,&ay,&az);
-	Serial.println("accleration of X/Y/Z: ");
-	Serial.print(ax);
-	Serial.println(" g");
-	Serial.print(ay);
-	Serial.println(" g");
-	Serial.print(az);
-	Serial.println(" g");
-	delay(500);
-}


reformatted file

reformatted file

--- ATtiny10Programmer/ATtiny10Programmer.ino
+++ ATtiny10Programmer/ATtiny10Programmer.ino
@@ -76,11 +76,11 @@
 //    (HVP)   D9 |---       | 6 (RESET#/PB3)
 //               |          |
 //
-//	-[R]-  =  2.2kΩ resistor
-//
-//	2011.12.08:		Original image by pcm1723
-//
-//	2014.09.26 bd:  The pcm1723 image had resistors on D10, D12, and D13.
+//  -[R]-  =  2.2kΩ resistor
+//
+//  2011.12.08:     Original image by pcm1723
+//
+//  2014.09.26 bd:  The pcm1723 image had resistors on D10, D12, and D13.
 //                  Both the Arduino Nano and the ATtiny10 operate at 5V and
 //                  are rated at 40mA per pin (ATtiny reference §16.1 p. 115,
 //                  Nano via online) so I'm getting rid of all the resistors
@@ -125,162 +125,162 @@
 #include "pins_arduino.h"

 enum ArduinoPortBBits {
-	kPortBSS			=	1 << 2,
-	kPortBMOSI			=	1 << 3,
-	kPortBMISO			=	1 << 4,
-	kPortBSCK			=	1 << 5,
+    kPortBSS            =   1 << 2,
+    kPortBMOSI          =   1 << 3,
+    kPortBMISO          =   1 << 4,
+    kPortBSCK           =   1 << 5,
 };

 enum ATtiny4_5_9_10AddressSpace {
-	// §5.2
-	kTiny4IO			=	0x0000,	// 0x0000 - 0x003f
-	kTiny4SRAM			=	0x0040,	// 0x0040 - 0x005f
-	kTiny4Reserved0		=	0x0060,	// 0x0060 - 0x3eff
-	kTiny4NVMLock		=	0x3f00,	// 0x3f00 - 0x3f01
-	kTiny4Reserved1		=	0x3f02,	// 0x3f02 - 0x3f3f
-	kTiny4Configuration	=	0x3f40, // 0x3f40 - 0x3f41
-	kTiny4Reserved2		=	0x3f42,	// 0x3f42 - 0x3f7f
-	kTiny4Calibration	=	0x3f80,	// 0x3f80 - 0x3f81
-	kTiny4Reserved3		=	0x3f82,	// 0x3f82 - 0x3fbf
-	kTiny4DeviceId		=	0x3fc0, // 0x3fc0 - 0x3fc3
-	kTiny4Reserved4		=	0x3fc4,	// 0x3fc4 - 0x3fff
-	kTiny4Flash			=	0x4000, // 0x4000 - 0x41ff (tiny 4/5), 0x4000 - 0x43ff (tiny 9/10)
+    // §5.2
+    kTiny4IO            =   0x0000, // 0x0000 - 0x003f
+    kTiny4SRAM          =   0x0040, // 0x0040 - 0x005f
+    kTiny4Reserved0     =   0x0060, // 0x0060 - 0x3eff
+    kTiny4NVMLock       =   0x3f00, // 0x3f00 - 0x3f01
+    kTiny4Reserved1     =   0x3f02, // 0x3f02 - 0x3f3f
+    kTiny4Configuration =   0x3f40, // 0x3f40 - 0x3f41
+    kTiny4Reserved2     =   0x3f42, // 0x3f42 - 0x3f7f
+    kTiny4Calibration   =   0x3f80, // 0x3f80 - 0x3f81
+    kTiny4Reserved3     =   0x3f82, // 0x3f82 - 0x3fbf
+    kTiny4DeviceId      =   0x3fc0, // 0x3fc0 - 0x3fc3
+    kTiny4Reserved4     =   0x3fc4, // 0x3fc4 - 0x3fff
+    kTiny4Flash         =   0x4000, // 0x4000 - 0x41ff (tiny 4/5), 0x4000 - 0x43ff (tiny 9/10)
 };

 enum ATtinyType {
-	kATtinyUnknown,
-
-	kATtiny4			=	4,
-	kATtiny5			=	5,
-	kATtiny9			=	9,
-	kATtiny10			=	10,
-	kATtiny20			=	20,
-	kATtiny40			=	40,
+    kATtinyUnknown,
+
+    kATtiny4            =   4,
+    kATtiny5            =   5,
+    kATtiny9            =   9,
+    kATtiny10           =   10,
+    kATtiny20           =   20,
+    kATtiny40           =   40,
 };

 enum IntelHexFileType {
-	kIHTypeData			=	0,
-	kIHTypeEOF			=	1,
-	kIHTypeExtSegAddr	=	2,
-	kIHTypeStartSegAddr	=	3,
-	kIHTypeExtLinAddr	=	4,
-	kIHTypeStartLinAddr	=	5,
+    kIHTypeData         =   0,
+    kIHTypeEOF          =   1,
+    kIHTypeExtSegAddr   =   2,
+    kIHTypeStartSegAddr =   3,
+    kIHTypeExtLinAddr   =   4,
+    kIHTypeStartLinAddr =   5,
 };

 enum TPICSS {
-	TPIIR				=	0x0f,	// §14.7.1
-	TPIPCR				=	0x02,	// §14.7.2
-	TPISR				=	0x00,	// §14.7.3
-
-	GT0					=	0x01,	// §14.7.2 guard time bit 0
-	GT1					=	0x02,	// §14.7.2 guard time bit 1
-	GT2					=	0x04,	// §14.7.2 guard time bit 2
-	NVMDisable			=	0x00,	// §14.7.3
-	NVMEnable			=	0x02,	// §14.7.3
-	TPIIdentification	=	0x80,	// §14.7.1
+    TPIIR               =   0x0f,   // §14.7.1
+    TPIPCR              =   0x02,   // §14.7.2
+    TPISR               =   0x00,   // §14.7.3
+
+    GT0                 =   0x01,   // §14.7.2 guard time bit 0
+    GT1                 =   0x02,   // §14.7.2 guard time bit 1
+    GT2                 =   0x04,   // §14.7.2 guard time bit 2
+    NVMDisable          =   0x00,   // §14.7.3
+    NVMEnable           =   0x02,   // §14.7.3
+    TPIIdentification   =   0x80,   // §14.7.1
 };

 // §14.5
 enum TPIInstruction {
-	SIN					=	0x10,	// serial in from i/o space
-	SKEY				=	0xe0,	// serial key signaling
-	SLD					=	0x20,	// serial load from data space
-	SLD_postIncrement	=	0x24,	// serial load from data space with post increment
-	SLDCS				=	0x80,	// serial load from control and status space
-	SOUT				=	0x90,	// serial out to i/o space
-	SST					=	0x60,	// serial store to data space
-	SST_postIncrement	=	0x64,	// serial store to data space with post increment
-	SSTCS				=	0xc0,	// serial store to control and status space
-	SSTPR_high			=	0x69,	// serial store to pointer register high byte
-	SSTPR_low			=	0x68,	// serial store to pointer register low byte
+    SIN                 =   0x10,   // serial in from i/o space
+    SKEY                =   0xe0,   // serial key signaling
+    SLD                 =   0x20,   // serial load from data space
+    SLD_postIncrement   =   0x24,   // serial load from data space with post increment
+    SLDCS               =   0x80,   // serial load from control and status space
+    SOUT                =   0x90,   // serial out to i/o space
+    SST                 =   0x60,   // serial store to data space
+    SST_postIncrement   =   0x64,   // serial store to data space with post increment
+    SSTCS               =   0xc0,   // serial store to control and status space
+    SSTPR_high          =   0x69,   // serial store to pointer register high byte
+    SSTPR_low           =   0x68,   // serial store to pointer register low byte
 };

 enum TPINVM {
-	NVMCMD				=	0x33,	// §15.7.2
-	NVMCSR				=	0x32,	// §15.7.1
-
-	NVMBusy				=	0x80,	// §15.7.1
-	NVMChipErase		=	0x10,	// §15.7.2
-	NVMNop				=	0x00,	// §15.7.2
-	NVMSectionErase		=	0x14,	// §15.7.2
-	NVMWordWrite		=	0x1d,	// §15.7.2
+    NVMCMD              =   0x33,   // §15.7.2
+    NVMCSR              =   0x32,   // §15.7.1
+
+    NVMBusy             =   0x80,   // §15.7.1
+    NVMChipErase        =   0x10,   // §15.7.2
+    NVMNop              =   0x00,   // §15.7.2
+    NVMSectionErase     =   0x14,   // §15.7.2
+    NVMWordWrite        =   0x1d,   // §15.7.2
 };

-ATtinyType				gATtinyType;
-uint16_t				gTPIPointer;
-
-bool tpi_memory_read( uint8_t &data, bool postIncrement = true, bool updateGTPIPointer = true );
-bool tpi_memory_write( uint8_t data, bool postIncrement = true, bool updateGTPIPointer = true );
+ATtinyType              gATtinyType;
+uint16_t                gTPIPointer;
+
+bool tpi_memory_read(uint8_t &data, bool postIncrement = true, bool updateGTPIPointer = true);
+bool tpi_memory_write(uint8_t data, bool postIncrement = true, bool updateGTPIPointer = true);

 uint16_t get_free_memory() {
-  uint16_t				v;
-  extern uint16_t		__heap_start, *__brkval;
-
-  return (uint16_t) &v - ( __brkval ? (uint16_t) &__heap_start : (uint16_t) __brkval );
+  uint16_t              v;
+  extern uint16_t       __heap_start, *__brkval;
+
+  return (uint16_t) &v - (__brkval ? (uint16_t) &__heap_start : (uint16_t) __brkval);
 }

 void setup() {
-	tristate_arduino_spi();		// so we can test the tiny at power on
-
-	Serial.begin( 115200 );
+    tristate_arduino_spi();     // so we can test the tiny at power on
+
+    Serial.begin(115200);
 }

 void loop() {
-	Serial.print( F( "Command [d,e,i,m,u,v,?] > " ) );
-
-	for ( ;; ) {
-		switch ( serial_read() ) {
-			case 'd': case 'D':		tpi_dump_memory();			break;
-			case 'e': case 'E':		tpi_chip_erase();			break;
-			case 'i': case 'I':		tpi_identify_device();		break;
-			case 'm': case 'M':		print_free_memory();		break;
-			case 'u': case 'U':		upload_program();			break;
-			case 'v': case 'V':		print_version();			break;
-
-			case ' ': case '\t': case '\r': case '\n':			continue;
-
-			default: {
-				Serial.println( F( "Commands:" ) );
-				Serial.println( F( "D: Dump memory" ) );
-				Serial.println( F( "E: Erase memory" ) );
-				Serial.println( F( "I: Identify device" ) );
-				Serial.println( F( "M: Print free memory" ) );
-				Serial.println( F( "U: Upload program" ) );
-				Serial.println( F( "V: Print version" ) );
-				Serial.println( F( "?: Help" ) );
-			} break;
-		}
-
-		break;
-	}
+    Serial.print(F("Command [d,e,i,m,u,v,?] > "));
+
+    for (;;) {
+        switch (serial_read()) {
+            case 'd': case 'D':     tpi_dump_memory();          break;
+            case 'e': case 'E':     tpi_chip_erase();           break;
+            case 'i': case 'I':     tpi_identify_device();      break;
+            case 'm': case 'M':     print_free_memory();        break;
+            case 'u': case 'U':     upload_program();           break;
+            case 'v': case 'V':     print_version();            break;
+
+            case ' ': case '\t': case '\r': case '\n':          continue;
+
+            default: {
+                Serial.println(F("Commands:"));
+                Serial.println(F("D: Dump memory"));
+                Serial.println(F("E: Erase memory"));
+                Serial.println(F("I: Identify device"));
+                Serial.println(F("M: Print free memory"));
+                Serial.println(F("U: Upload program"));
+                Serial.println(F("V: Print version"));
+                Serial.println(F("?: Help"));
+            } break;
+        }
+
+        break;
+    }
 }

 void print_free_memory() {
-	Serial.print( F( "Free memory: " ) );
-	Serial.print( get_free_memory() );
-	Serial.println( F( " bytes" ) );
-}
-
-void print_hex( uint16_t value, int8_t nibbles ) {
-	while ( --nibbles > 0 ) {
-		if ( value >> nibbles * 4 & 0x0f ) break;		// if msb is != 0
-
-		Serial.print( F( "0" ) );
-	}
-
-	Serial.print( value, HEX );
+    Serial.print(F("Free memory: "));
+    Serial.print(get_free_memory());
+    Serial.println(F(" bytes"));
+}
+
+void print_hex(uint16_t value, int8_t nibbles) {
+    while (--nibbles > 0) {
+        if (value >> nibbles * 4 & 0x0f) break;     // if msb is != 0
+
+        Serial.print(F("0"));
+    }
+
+    Serial.print(value, HEX);
 }

 void print_version() {
-	Serial.println( F( "Version 1.0" ) );
+    Serial.println(F("Version 1.0"));
 }

 void tristate_arduino_spi() {
-	const uint8_t		kPortBTriState = ~( kPortBSS | kPortBMOSI | kPortBMISO | kPortBSCK );
-
-	DDRB &= kPortBTriState;								// tri-state SPI so ATtiny can be tested
-	PORTB &= kPortBTriState;
+    const uint8_t       kPortBTriState = ~(kPortBSS | kPortBMOSI | kPortBMISO | kPortBSCK);
+
+    DDRB &= kPortBTriState;                             // tri-state SPI so ATtiny can be tested
+    PORTB &= kPortBTriState;
 }

 // I had tons of failures trying to write the ATtiny10 while
@@ -328,497 +328,497 @@
 // :00000001FF

 void upload_program() {
-	uint16_t			address, w;
-	uint8_t *			buffer = NULL, length, *p, *q, type;
-	bool				success = false;
-
-	// The page size of ATtiny4,5,9,10 is 16 bytes (§15.3.2).
-	// AVRStudio generates Intel .hex files with 16-byte data rows
-	// in most cases, though they can be smaller.  The buffer allocation
-	// here is wide enough to receive 64 rows of 16 bytes each, plus
-	// a length byte and an address word, which would be what AVRStudio
-	// should output if all 1024 bytes of the ATtiny9,10 memory is filled.
-	// I don't expect this to overrun in most cases but it is possible if
-	// somehow the .hex file contains lots of smaller-than-page-sized rows.
-	// In that case I recommend writing a small python script or similar
-	// to preprocess the .hex file and convert it into longer rows.
-	// The Intel hex file format is here:
-	// https://en.wikipedia.org/wiki/Intel_HEX
-
-	if ( ! ( p = buffer = (uint8_t *) malloc( 64 * ( 1 + 2 + 16 ) ) ) ) {
-		Serial.println( "Could not allocate enough memory" );
-		goto done;
-	}
-
-	Serial.println( F( "Upload hex file content to serial monitor" ) );
-
-	do {
-		while ( serial_read() != ':' ) ;
-
-		length = serial_decode_byte();
-		address = (uint16_t) serial_decode_byte() << 8;
-		address |= serial_decode_byte();
-		type = serial_decode_byte();
-
-		if ( length ) {
-			if ( type == kIHTypeData ) {
-				*p++ = length;
-				*p++ = address >> 8 & 0xff;
-				*p++ = address & 0xff;
-
-				while ( length-- ) *p++ = serial_decode_byte();
-			} else {
-				while ( length-- ) serial_decode_byte();
-			}
-		}
-
-		serial_decode_byte();			// consume checksum
-	} while ( type != kIHTypeEOF );
-
-	Serial.println( F( "Upload complete" ) );
-
-	tpi_chip_erase();
-
-	Serial.println( F( "Writing flash" ) );
-
-	tpi_enable();
-
-	for ( q = buffer; q < p; ) {
-		length = *q++;
-		address = (uint16_t) *q++ << 8;
-		address |= *q++;
-
-		print_hex( length, 2 );
-		Serial.print( F( " ") );
-		print_hex( address, 4 );
-		Serial.print( F( " ") );
-
-		address |= kTiny4Flash;
-
-		if ( address & 1 ) {
-			address &= ~1;
-			print_hex( *q, 2 );
-			w = 0xff00 | *q++;
-			if ( ! tpi_memory_write_word( address, w ) ) goto done;
-			address += 2;
-			--length;
-		}
-		for ( ; length > 1; address += 2, length -= 2 ) {
-			print_hex( *q, 2 );
-			w = (uint16_t) *q++ << 8;
-			print_hex( *q, 2 );
-			w |= *q++;
-			if ( ! tpi_memory_write_word( address, w ) ) goto done;
-		}
-		if ( length ) {
-			print_hex( *q, 2 );
-			w = (uint16_t) *q++ << 8 | 0xffu;
-			if ( ! tpi_memory_write_word( address, w ) ) goto done;
-		}
-
-		Serial.println( F( " OK" ) );
-	}
-
-	Serial.println( F( "Done" ) );
-
-	success = true;
+    uint16_t            address, w;
+    uint8_t *           buffer = NULL, length, *p, *q, type;
+    bool                success = false;
+
+    // The page size of ATtiny4,5,9,10 is 16 bytes (§15.3.2).
+    // AVRStudio generates Intel .hex files with 16-byte data rows
+    // in most cases, though they can be smaller.  The buffer allocation
+    // here is wide enough to receive 64 rows of 16 bytes each, plus
+    // a length byte and an address word, which would be what AVRStudio
+    // should output if all 1024 bytes of the ATtiny9,10 memory is filled.
+    // I don't expect this to overrun in most cases but it is possible if
+    // somehow the .hex file contains lots of smaller-than-page-sized rows.
+    // In that case I recommend writing a small python script or similar
+    // to preprocess the .hex file and convert it into longer rows.
+    // The Intel hex file format is here:
+    // https://en.wikipedia.org/wiki/Intel_HEX
+
+    if (! (p = buffer = (uint8_t *) malloc(64 * (1 + 2 + 16)))) {
+        Serial.println("Could not allocate enough memory");
+        goto done;
+    }
+
+    Serial.println(F("Upload hex file content to serial monitor"));
+
+    do {
+        while (serial_read() != ':') ;
+
+        length = serial_decode_byte();
+        address = (uint16_t) serial_decode_byte() << 8;
+        address |= serial_decode_byte();
+        type = serial_decode_byte();
+
+        if (length) {
+            if (type == kIHTypeData) {
+                *p++ = length;
+                *p++ = address >> 8 & 0xff;
+                *p++ = address & 0xff;
+
+                while (length--) *p++ = serial_decode_byte();
+            } else {
+                while (length--) serial_decode_byte();
+            }
+        }
+
+        serial_decode_byte();           // consume checksum
+    } while (type != kIHTypeEOF);
+
+    Serial.println(F("Upload complete"));
+
+    tpi_chip_erase();
+
+    Serial.println(F("Writing flash"));
+
+    tpi_enable();
+
+    for (q = buffer; q < p;) {
+        length = *q++;
+        address = (uint16_t) *q++ << 8;
+        address |= *q++;
+
+        print_hex(length, 2);
+        Serial.print(F(" "));
+        print_hex(address, 4);
+        Serial.print(F(" "));
+
+        address |= kTiny4Flash;
+
+        if (address & 1) {
+            address &= ~1;
+            print_hex(*q, 2);
+            w = 0xff00 | *q++;
+            if (! tpi_memory_write_word(address, w)) goto done;
+            address += 2;
+            --length;
+        }
+        for (; length > 1; address += 2, length -= 2) {
+            print_hex(*q, 2);
+            w = (uint16_t) *q++ << 8;
+            print_hex(*q, 2);
+            w |= *q++;
+            if (! tpi_memory_write_word(address, w)) goto done;
+        }
+        if (length) {
+            print_hex(*q, 2);
+            w = (uint16_t) *q++ << 8 | 0xffu;
+            if (! tpi_memory_write_word(address, w)) goto done;
+        }
+
+        Serial.println(F(" OK"));
+    }
+
+    Serial.println(F("Done"));
+
+    success = true;

 done:

-	if ( ! success ) Serial.println( F( "Upload to ATtiny failed" ) );
-
-	if ( buffer ) free( buffer );
-
-	tpi_disable();
+    if (! success) Serial.println(F("Upload to ATtiny failed"));
+
+    if (buffer) free(buffer);
+
+    tpi_disable();
 }

 uint8_t serial_decode_byte() {
-	uint8_t				b0, b1;
-
-	b0 = serial_read();
-	b1 = serial_read();
-
-	return unhex( b0, b1 );
+    uint8_t             b0, b1;
+
+    b0 = serial_read();
+    b1 = serial_read();
+
+    return unhex(b0, b1);
 }

 uint8_t serial_read() {
-	while ( Serial.available() < 1 ) ;
-
-	return Serial.read();
+    while (Serial.available() < 1) ;
+
+    return Serial.read();
 }

 // converts two chars hexadecimal characters to the byte they represent
-uint8_t unhex( uint8_t high, uint8_t low ) {
-	uint8_t				b;
-
-	b = ( high >= '0' && high <= '9' ? high - '0' : ( high & ~0x20 ) - 'A' + 0xa ) << 4;
-	b |= low >= '0' && low <= '9' ? low - '0' : ( low & ~0x20 ) - 'A' + 0xa;
-
-	return b;
+uint8_t unhex(uint8_t high, uint8_t low) {
+    uint8_t             b;
+
+    b = (high >= '0' && high <= '9' ? high - '0' : (high & ~0x20) - 'A' + 0xa) << 4;
+    b |= low >= '0' && low <= '9' ? low - '0' : (low & ~0x20) - 'A' + 0xa;
+
+    return b;
 }

 // ATtiny TPI (Tiny Programming Interface) (§14 pp. 95+)

 bool tpi_chip_erase() {
-	tpi_enable();
-
-	// §15.4.3.1
-	// 1. write the CHIP_ERASE command to the NVMCMD register:
-	tpi_io_write( NVMCMD, NVMChipErase );
-
-	// 2. Start the erase operation by writing a dummy byte to
-	// the high byte of any word location inside the code section
-	tpi_set_pointer( kTiny4Flash + 1 );
-	tpi_memory_write( 0x1 );
-
-	// 3. Wait until the NVMBSY bit has been cleared
-	if ( tpi_nvm_wait() ) Serial.println( F( "Chip erased" ) );
-	else Serial.println( F( "Chip erase failed" ) );
-
-	tpi_disable();
-}
-
-bool tpi_css_read( uint8_t address, uint8_t &data ) {
-	// §14.5.6
-	tpi_serial_write( SLDCS | address );
-
-	return tpi_serial_read( data );
-}
-
-void tpi_css_write( uint8_t address, uint8_t data ) {
-	// §14.5.7
-	tpi_serial_write( SSTCS | address );
-	tpi_serial_write( data );
+    tpi_enable();
+
+    // §15.4.3.1
+    // 1. write the CHIP_ERASE command to the NVMCMD register:
+    tpi_io_write(NVMCMD, NVMChipErase);
+
+    // 2. Start the erase operation by writing a dummy byte to
+    // the high byte of any word location inside the code section
+    tpi_set_pointer(kTiny4Flash + 1);
+    tpi_memory_write(0x1);
+
+    // 3. Wait until the NVMBSY bit has been cleared
+    if (tpi_nvm_wait()) Serial.println(F("Chip erased"));
+    else Serial.println(F("Chip erase failed"));
+
+    tpi_disable();
+}
+
+bool tpi_css_read(uint8_t address, uint8_t &data) {
+    // §14.5.6
+    tpi_serial_write(SLDCS | address);
+
+    return tpi_serial_read(data);
+}
+
+void tpi_css_write(uint8_t address, uint8_t data) {
+    // §14.5.7
+    tpi_serial_write(SSTCS | address);
+    tpi_serial_write(data);
 }

 void tpi_disable() {
-	tpi_css_write( TPISR, NVMDisable );
-
-	digitalWrite( SS, HIGH );							// release RESET
-	delay( 1 );											// tRST min = 400 ns @ Vcc = 5 V
-
-	SPI.end();
-
-	tristate_arduino_spi();
+    tpi_css_write(TPISR, NVMDisable);
+
+    digitalWrite(SS, HIGH);                         // release RESET
+    delay(1);                                       // tRST min = 400 ns @ Vcc = 5 V
+
+    SPI.end();
+
+    tristate_arduino_spi();
 }

 void tpi_dump_memory() {
-	uint8_t				b, i;
-	uint16_t			flashEnd;
-
-	tpi_identify_device();
-
-	tpi_enable();
-	tpi_set_pointer( kTiny4IO );
-
-	switch ( gATtinyType ) {
-		case kATtiny4:
-		case kATtiny5:		flashEnd = 0x0200;		break;
-		case kATtiny9:
-		case kATtiny10:		flashEnd = 0x0400;		break;
-		case kATtiny20:		flashEnd = 0x0800;		break;
-		case kATtiny40:		flashEnd = 0x1000;		break;
-	}
-
-	flashEnd += kTiny4Flash;
-
-	while ( gTPIPointer < flashEnd ) {
-		if ( ! tpi_memory_read( b, true, false ) ) {
-			Serial.println( F( "Failed to read memory" ) );
-			goto done;
-		}
-
-		// read all the memory, but only print
-		// the register, SRAM, config and signature memory
-		if (
-			gTPIPointer >= kTiny4IO && gTPIPointer < kTiny4Reserved0 ||
-			gTPIPointer >= kTiny4NVMLock && gTPIPointer < kTiny4Reserved1 ||
-			gTPIPointer >= kTiny4Configuration && gTPIPointer < kTiny4Reserved2 ||
-			gTPIPointer >= kTiny4Calibration && gTPIPointer < kTiny4Reserved3 ||
-			gTPIPointer >= kTiny4DeviceId && gTPIPointer < kTiny4Reserved4 ||
-			gTPIPointer >= kTiny4Flash && gTPIPointer < flashEnd )
-		{
-			if (
-				gTPIPointer == kTiny4IO ||
-				gTPIPointer == kTiny4NVMLock ||
-				gTPIPointer == kTiny4Configuration ||
-				gTPIPointer == kTiny4Calibration ||
-				gTPIPointer == kTiny4DeviceId ||
-				gTPIPointer == kTiny4Flash )
-			{
-				if ( gTPIPointer != kTiny4IO ) {
-					Serial.println( F( "" ) );
-					Serial.println( F( "" ) );
-				}
-
-				if ( gTPIPointer == kTiny4IO ) Serial.println( F( "Registers, SRAM:" ) );
-				else if ( gTPIPointer == kTiny4NVMLock ) Serial.println( F( "NVM Lock:" ) );
-				else if ( gTPIPointer == kTiny4Configuration ) Serial.println( F( "Configuration:" ) );
-				else if ( gTPIPointer == kTiny4Calibration ) Serial.println( F( "Calibration:" ) );
-				else if ( gTPIPointer == kTiny4DeviceId ) Serial.println( F( "Device ID:" ) );
-				else if ( gTPIPointer == kTiny4Flash ) Serial.println( F( "Flash:" ) );
-
-				Serial.println( F( "" ) );
-
-				for ( i = 0; i < 5; ++i ) Serial.print( F( " " ) );
-				for ( i = 0; i < 16; ++i ) {
-					Serial.print( F( " +" ) );
-					Serial.print( i, HEX );
-				}
-			}
-			if ( ! ( gTPIPointer & 0x000f ) ) {
-				Serial.println( F( "" ) );
-				print_hex( gTPIPointer, 4 );
-				Serial.print( F( ": " ) );
-			}
-			print_hex( b, 2 );
-			Serial.print( F( " " ) );
-		}
-
-		++gTPIPointer;
-
-		if ( gTPIPointer == kTiny4Reserved0 ) tpi_set_pointer( kTiny4NVMLock );
-	}
-
-	Serial.println( F( "" ) );
+    uint8_t             b, i;
+    uint16_t            flashEnd;
+
+    tpi_identify_device();
+
+    tpi_enable();
+    tpi_set_pointer(kTiny4IO);
+
+    switch (gATtinyType) {
+        case kATtiny4:
+        case kATtiny5:      flashEnd = 0x0200;      break;
+        case kATtiny9:
+        case kATtiny10:     flashEnd = 0x0400;      break;
+        case kATtiny20:     flashEnd = 0x0800;      break;
+        case kATtiny40:     flashEnd = 0x1000;      break;
+    }
+
+    flashEnd += kTiny4Flash;
+
+    while (gTPIPointer < flashEnd) {
+        if (! tpi_memory_read(b, true, false)) {
+            Serial.println(F("Failed to read memory"));
+            goto done;
+        }
+
+        // read all the memory, but only print
+        // the register, SRAM, config and signature memory
+        if (
+            gTPIPointer >= kTiny4IO && gTPIPointer < kTiny4Reserved0 ||
+            gTPIPointer >= kTiny4NVMLock && gTPIPointer < kTiny4Reserved1 ||
+            gTPIPointer >= kTiny4Configuration && gTPIPointer < kTiny4Reserved2 ||
+            gTPIPointer >= kTiny4Calibration && gTPIPointer < kTiny4Reserved3 ||
+            gTPIPointer >= kTiny4DeviceId && gTPIPointer < kTiny4Reserved4 ||
+            gTPIPointer >= kTiny4Flash && gTPIPointer < flashEnd)
+        {
+            if (
+                gTPIPointer == kTiny4IO ||
+                gTPIPointer == kTiny4NVMLock ||
+                gTPIPointer == kTiny4Configuration ||
+                gTPIPointer == kTiny4Calibration ||
+                gTPIPointer == kTiny4DeviceId ||
+                gTPIPointer == kTiny4Flash)
+            {
+                if (gTPIPointer != kTiny4IO) {
+                    Serial.println(F(""));
+                    Serial.println(F(""));
+                }
+
+                if (gTPIPointer == kTiny4IO) Serial.println(F("Registers, SRAM:"));
+                else if (gTPIPointer == kTiny4NVMLock) Serial.println(F("NVM Lock:"));
+                else if (gTPIPointer == kTiny4Configuration) Serial.println(F("Configuration:"));
+                else if (gTPIPointer == kTiny4Calibration) Serial.println(F("Calibration:"));
+                else if (gTPIPointer == kTiny4DeviceId) Serial.println(F("Device ID:"));
+                else if (gTPIPointer == kTiny4Flash) Serial.println(F("Flash:"));
+
+                Serial.println(F(""));
+
+                for (i = 0; i < 5; ++i) Serial.print(F(" "));
+                for (i = 0; i < 16; ++i) {
+                    Serial.print(F(" +"));
+                    Serial.print(i, HEX);
+                }
+            }
+            if (! (gTPIPointer & 0x000f)) {
+                Serial.println(F(""));
+                print_hex(gTPIPointer, 4);
+                Serial.print(F(": "));
+            }
+            print_hex(b, 2);
+            Serial.print(F(" "));
+        }
+
+        ++gTPIPointer;
+
+        if (gTPIPointer == kTiny4Reserved0) tpi_set_pointer(kTiny4NVMLock);
+    }
+
+    Serial.println(F(""));

 done:

-	tpi_disable();
+    tpi_disable();
 }

 bool tpi_enable() {
-	uint8_t				data;
-	uint64_t			nvmKey = 0x1289ab45cdd888ffull;	// §14.6
-
-	// §14.3.1, p. 96, enable TPI
-
-	SPI.begin();
-	SPI.setBitOrder( LSBFIRST );
-	SPI.setDataMode( SPI_MODE0 );
-	SPI.setClockDivider( SPI_CLOCK_DIV16 );				// §16.8 2MHz maximum serial programming frequency
-														// I'm using Arduino Nano (16MHz), so set serial clock to 1MHz
-
-	digitalWrite( SS, LOW );							// assert RESET on tiny
-	delay( 1 );											// §16.5 tRST min = 400ns @ Vcc = 5 V
-
-	SPI.transfer( 0xff );								// activate TPI by emitting
-	SPI.transfer( 0xff );								// 16 or more pulses on TPICLK
-														// while holding TPIDATA to "1"
-
-	// §14.7.2
-	tpi_css_write( TPIPCR, GT2 );						// TPIPCR, guard time = 8 idle bits (default=128)
-
-	tpi_serial_write( SKEY );							// enable NVM
-	do { tpi_serial_write( nvmKey & 0xff ); } while ( nvmKey >>= 8 );
-
-	// §14.7.3 wait for NVM to enable
-	do {
-		if ( ! tpi_css_read( TPISR, data ) ) {
-			Serial.println( F( "Failed to enable TPI" ) );
-			return false;
-		}
-	} while ( ! data );
-
-	return true;
+    uint8_t             data;
+    uint64_t            nvmKey = 0x1289ab45cdd888ffull; // §14.6
+
+    // §14.3.1, p. 96, enable TPI
+
+    SPI.begin();
+    SPI.setBitOrder(LSBFIRST);
+    SPI.setDataMode(SPI_MODE0);
+    SPI.setClockDivider(SPI_CLOCK_DIV16);           // §16.8 2MHz maximum serial programming frequency
+                                                    // I'm using Arduino Nano (16MHz), so set serial clock to 1MHz
+
+    digitalWrite(SS, LOW);                          // assert RESET on tiny
+    delay(1);										// §16.5 tRST min = 400ns @ Vcc = 5 V
+
+    SPI.transfer(0xff);                             // activate TPI by emitting
+    SPI.transfer(0xff);                             // 16 or more pulses on TPICLK
+                                                    // while holding TPIDATA to "1"
+
+    // §14.7.2
+    tpi_css_write(TPIPCR, GT2);                     // TPIPCR, guard time = 8 idle bits (default=128)
+
+    tpi_serial_write(SKEY);                         // enable NVM
+    do { tpi_serial_write(nvmKey & 0xff); } while (nvmKey >>= 8);
+
+    // §14.7.3 wait for NVM to enable
+    do {
+        if (! tpi_css_read(TPISR, data)) {
+            Serial.println(F("Failed to enable TPI"));
+            return false;
+        }
+    } while (! data);
+
+    return true;
 }

 bool tpi_identify_device() {
-	uint8_t				b0, b1, b2;
-
-	gATtinyType = kATtinyUnknown;
-
-	tpi_enable();
-	tpi_set_pointer( kTiny4DeviceId );
-
-	if ( ! tpi_memory_read( b0 ) ) goto done;
-	if ( ! tpi_memory_read( b1 ) ) goto done;
-	if ( ! tpi_memory_read( b2 ) ) goto done;
-
-	// §15.3.4
-	if ( b0 == 0x1e ) {
-		switch ( b1 ) {
-			case 0x8f: {
-				switch ( b2 ) {
-					case 0x0a:		gATtinyType = kATtiny4;		break;
-					case 0x09:		gATtinyType = kATtiny5;		break;
-				}
-			} break;
-
-			case 0x90: {
-				switch ( b2 ) {
-					case 0x08:		gATtinyType = kATtiny9;		break;
-					case 0x03:		gATtinyType = kATtiny10;	break;
-				}
-			} break;
-
-			case 0x91: {
-				switch ( b2 ) {
-					case 0x0f:		gATtinyType = kATtiny20;	break;
-				}
-			} break;
-
-			case 0x92: {
-				switch ( b2 ) {
-					case 0x0e:		gATtinyType = kATtiny40;	break;
-				}
-			} break;
-		}
-	}
-
-	if ( gATtinyType ) {
-		Serial.print( F( "ATtiny" ) );
-		Serial.print( gATtinyType );
-		Serial.println( F( " connected" ) );
-	} else {
-		Serial.println( F( "Unable to identify device" ) );
-	}
+    uint8_t             b0, b1, b2;
+
+    gATtinyType = kATtinyUnknown;
+
+    tpi_enable();
+    tpi_set_pointer(kTiny4DeviceId);
+
+    if (! tpi_memory_read(b0)) goto done;
+    if (! tpi_memory_read(b1)) goto done;
+    if (! tpi_memory_read(b2)) goto done;
+
+    // §15.3.4
+    if (b0 == 0x1e) {
+        switch (b1) {
+            case 0x8f: {
+                switch (b2) {
+                    case 0x0a:      gATtinyType = kATtiny4;     break;
+                    case 0x09:      gATtinyType = kATtiny5;     break;
+                }
+            } break;
+
+            case 0x90: {
+                switch (b2) {
+                    case 0x08:      gATtinyType = kATtiny9;     break;
+                    case 0x03:      gATtinyType = kATtiny10;    break;
+                }
+            } break;
+
+            case 0x91: {
+                switch (b2) {
+                    case 0x0f:      gATtinyType = kATtiny20;    break;
+                }
+            } break;
+
+            case 0x92: {
+                switch (b2) {
+                    case 0x0e:      gATtinyType = kATtiny40;    break;
+                }
+            } break;
+        }
+    }
+
+    if (gATtinyType) {
+        Serial.print(F("ATtiny"));
+        Serial.print(gATtinyType);
+        Serial.println(F(" connected"));
+    } else {
+        Serial.println(F("Unable to identify device"));
+    }

 done:

-	tpi_disable();
-
-	return gATtinyType != kATtinyUnknown;
-}
-
-bool tpi_io_read( uint8_t address, uint8_t &data ) {
-	// §14.5.4 SIN 0b0aa1aaaa replace a with 6 address bits
-	tpi_serial_write( SIN | ( address & 0x30 ) << 1 | address & 0x0f );
-
-	return tpi_serial_read( data );
-}
-
-void tpi_io_write( uint8_t address, uint8_t data ) {
-	// §14.5.5 SOUT 0b1aa1aaaa replace a with 6 address bits
-	tpi_serial_write( SOUT | ( address & 0x30 ) << 1 | address & 0x0f );
-	tpi_serial_write( data );
+    tpi_disable();
+
+    return gATtinyType != kATtinyUnknown;
+}
+
+bool tpi_io_read(uint8_t address, uint8_t &data) {
+    // §14.5.4 SIN 0b0aa1aaaa replace a with 6 address bits
+    tpi_serial_write(SIN | (address & 0x30) << 1 | address & 0x0f);
+
+    return tpi_serial_read(data);
+}
+
+void tpi_io_write(uint8_t address, uint8_t data) {
+    // §14.5.5 SOUT 0b1aa1aaaa replace a with 6 address bits
+    tpi_serial_write(SOUT | (address & 0x30) << 1 | address & 0x0f);
+    tpi_serial_write(data);
 }

 // read memory indirectly.  must call tpi_set_pointer() first
-bool tpi_memory_read( uint8_t &data, bool postIncrement, bool updateGTPIPointer ) {
-	tpi_serial_write( postIncrement ? SLD_postIncrement : SLD );
-
-	if ( tpi_serial_read( data ) ) {
-		if ( postIncrement && updateGTPIPointer ) ++gTPIPointer;
-		return true;
-	}
-
-	return false;
+bool tpi_memory_read(uint8_t &data, bool postIncrement, bool updateGTPIPointer) {
+    tpi_serial_write(postIncrement ? SLD_postIncrement : SLD);
+
+    if (tpi_serial_read(data)) {
+        if (postIncrement && updateGTPIPointer) ++gTPIPointer;
+        return true;
+    }
+
+    return false;
 }

 // write memory indirectly.  must call tpi_set_pointer() first
-bool tpi_memory_write( uint8_t data, bool postIncrement, bool updateGTPIPointer ) {
-	tpi_serial_write( postIncrement ? SST_postIncrement : SST );
-	tpi_serial_write( data );
-
-	if ( postIncrement && updateGTPIPointer ) ++gTPIPointer;
-}
-
-bool tpi_memory_write_word( uint16_t address, uint16_t data ) {
-	tpi_io_write( NVMCMD, NVMWordWrite );
-
-	tpi_set_pointer( address );
-	tpi_memory_write( data >> 8 & 0xff );
-	tpi_memory_write( data & 0xff );
-
-	if ( ! tpi_nvm_wait() ) {
-		Serial.println( F( "tpi_memory_write_word() failed" ) );
-		return false;
-	}
-
-	return true;
+bool tpi_memory_write(uint8_t data, bool postIncrement, bool updateGTPIPointer) {
+    tpi_serial_write(postIncrement ? SST_postIncrement : SST);
+    tpi_serial_write(data);
+
+    if (postIncrement && updateGTPIPointer) ++gTPIPointer;
+}
+
+bool tpi_memory_write_word(uint16_t address, uint16_t data) {
+    tpi_io_write(NVMCMD, NVMWordWrite);
+
+    tpi_set_pointer(address);
+    tpi_memory_write(data >> 8 & 0xff);
+    tpi_memory_write(data & 0xff);
+
+    if (! tpi_nvm_wait()) {
+        Serial.println(F("tpi_memory_write_word() failed"));
+        return false;
+    }
+
+    return true;
 }

 bool tpi_nvm_wait() {
-	uint8_t				b;
-
-	do {
-		if ( ! tpi_io_read( NVMCSR, b ) ) return false;
-	} while ( b & NVMBusy );
-
-	return true;
+    uint8_t             b;
+
+    do {
+        if (! tpi_io_read(NVMCSR, b)) return false;
+    } while (b & NVMBusy);
+
+    return true;
 }

 // read TPI 12-bit format byte data via SPI
 // 2 bytes (16 clocks) or 3 bytes (24 clocks)
-bool tpi_serial_read( uint8_t &data ) {
-	uint8_t				b0, b1;
-
-	// keep transmitting high(idle) while waiting for a start bit
-	while ( ( b0 = SPI.transfer( 0xff ) ) == 0xff ) ;
-
-	// get (partial) data bits
-	b1 = SPI.transfer( 0xff );
-
-	// if the first byte(b0) contains less than 4 data bits
-	// we need to get a third byte to get the parity and stop bits
-	if ( ( b0 & 0x0f ) == 0x0f ) SPI.transfer( 0xff );
-
-	// b0 should hold only idle and start bits = 0b01111111
-	// if it doesn't, shift (b1|b0) left until it does.
-	// bd 2014.09.26: b0 == 0xff will cause an infinite loop, so test for it
-	if ( b0 == 0xff ) {
-		Serial.println( F( "tpi_serial_read() got bad data" ) );
-		return false;
-	}
-	while ( b0 != 0x7f ) {
-		b1 <<= 1;
-		if ( b0 & 0x80 ) b1 |= 1;
-		b0 <<= 1;
-		b0 |= 1;									// fill with idle bit
-	}
-
-	// now the data byte is stored in b1
-	data = b1;
-
-	return true;
+bool tpi_serial_read(uint8_t &data) {
+    uint8_t             b0, b1;
+
+    // keep transmitting high(idle) while waiting for a start bit
+    while ((b0 = SPI.transfer(0xff)) == 0xff) ;
+
+    // get (partial) data bits
+    b1 = SPI.transfer(0xff);
+
+    // if the first byte(b0) contains less than 4 data bits
+    // we need to get a third byte to get the parity and stop bits
+    if ((b0 & 0x0f) == 0x0f) SPI.transfer(0xff);
+
+    // b0 should hold only idle and start bits = 0b01111111
+    // if it doesn't, shift (b1|b0) left until it does.
+    // bd 2014.09.26: b0 == 0xff will cause an infinite loop, so test for it
+    if (b0 == 0xff) {
+        Serial.println(F("tpi_serial_read() got bad data"));
+        return false;
+    }
+    while (b0 != 0x7f) {
+        b1 <<= 1;
+        if (b0 & 0x80) b1 |= 1;
+        b0 <<= 1;
+        b0 |= 1;                                    // fill with idle bit
+    }
+
+    // now the data byte is stored in b1
+    data = b1;
+
+    return true;
 }

 // Send a byte in one TPI frame (12 bits: 1 start + 8 data + 1 parity + 2 stop)
 // using 2 SPI data bytes (2 x 8 = 16 clocks) with 4 extra idle bits
-void tpi_serial_write( uint8_t data ) {
-	// compute parity bit
-	uint8_t				parity = data;
-
-	// §14.3.4 p. 97
-	// even parity function is:
-	// d0 ^ d1 ^ d2 ^ d3 ^ d4 ^ d5 ^ d6 ^ d7 ^ 0
-
-	// due to commutativity, this becomes:
-	// d0 ^ d4 ^ d1 ^ d5 ^ d2 ^ d6 ^ d3 ^ d7 ^ 0
-	// due to associativity, this becomes:
-	// ( d0 ^ d4 ) ^ ( d1 ^ d5 ) ^ ( d2 ^ d6 ) ^ ( d3 ^ d7 ) ^ 0
-	parity ^= ( parity >> 4 );		// b[7:4] ^ b[3:0]
-	// which yields:
-	// d0 ^ d1 ^ d2 ^ d3 ^ 0
-	// due to commutativity:
-	// d0 ^ d2 ^ d1 ^ d3 ^ 0
-	// due to associativity:
-	// ( d0 ^ d2 ) ^ ( d1 ^ d3 ) ^ 0
-	parity ^= ( parity >> 2 );		// b[3:2] ^ b[1:0]
-	// which yields:
-	// d0 ^ d1 ^ 0
-	// due to associativity:
-	// ( d0 ^ d1 ) ^ 0
-	parity ^= ( parity >> 1 );		// b[1] ^ b[0]
-	// which yields:
-	// d0 ^ 0
-	// which yields parity bit in d0
-
-	// TPI transmits data in LSBfirst mode and idle is high
-	// 2 idle(high) + 1 start bit(low) + data[4:0]
-	SPI.transfer( 0x03 | data << 3 );
-
-	// data[7:5] + 1 parity + 2 stop bits(high) + 2 idle(high)
-	SPI.transfer( 0xf0 | parity << 3 | data >> 5 );
-}
-
-void tpi_set_pointer( unsigned short address ) {
-	// §14.5.3
-	tpi_serial_write( SSTPR_low );
-	tpi_serial_write( address & 0xff );
-	tpi_serial_write( SSTPR_high );
-	tpi_serial_write( address >> 8 & 0xff );
-
-	gTPIPointer = address;
-}
+void tpi_serial_write(uint8_t data) {
+    // compute parity bit
+    uint8_t             parity = data;
+
+    // §14.3.4 p. 97
+    // even parity function is:
+    // d0 ^ d1 ^ d2 ^ d3 ^ d4 ^ d5 ^ d6 ^ d7 ^ 0
+
+    // due to commutativity, this becomes:
+    // d0 ^ d4 ^ d1 ^ d5 ^ d2 ^ d6 ^ d3 ^ d7 ^ 0
+    // due to associativity, this becomes:
+    // (d0 ^ d4) ^ (d1 ^ d5) ^ (d2 ^ d6) ^ (d3 ^ d7) ^ 0
+    parity ^= (parity >> 4);        // b[7:4] ^ b[3:0]
+    // which yields:
+    // d0 ^ d1 ^ d2 ^ d3 ^ 0
+    // due to commutativity:
+    // d0 ^ d2 ^ d1 ^ d3 ^ 0
+    // due to associativity:
+    // (d0 ^ d2) ^ (d1 ^ d3) ^ 0
+    parity ^= (parity >> 2);        // b[3:2] ^ b[1:0]
+    // which yields:
+    // d0 ^ d1 ^ 0
+    // due to associativity:
+    // (d0 ^ d1) ^ 0
+    parity ^= (parity >> 1);        // b[1] ^ b[0]
+    // which yields:
+    // d0 ^ 0
+    // which yields parity bit in d0
+
+    // TPI transmits data in LSBfirst mode and idle is high
+    // 2 idle(high) + 1 start bit(low) + data[4:0]
+    SPI.transfer(0x03 | data << 3);
+
+    // data[7:5] + 1 parity + 2 stop bits(high) + 2 idle(high)
+    SPI.transfer(0xf0 | parity << 3 | data >> 5);
+}
+
+void tpi_set_pointer(unsigned short address) {
+    // §14.5.3
+    tpi_serial_write(SSTPR_low);
+    tpi_serial_write(address & 0xff);
+    tpi_serial_write(SSTPR_high);
+    tpi_serial_write(address >> 8 & 0xff);
+
+    gTPIPointer = address;
+}


Update the main program overview comment

--- demo_sdcard_gps/demo_sdcard_gps.ino
+++ demo_sdcard_gps/demo_sdcard_gps.ino
@@ -3,10 +3,9 @@
  * created: 20160611
  * author(s): mr-augustine
  *
- * This file orchestrates the sdcard_gps demo.
- *
- * For now, the program will write a loop iteration value to a numbered
- * data file.
+ * This file orchestrates the sdcard_gps demo. GPS data are continuously
+ * parsed and stored to the statevars variable. And the statevars are
+ * continuously written to a file on the SD card.
  */
 #include <stdint.h>


cosmetics

cosmetics

--- examples/RS485_HalfDuplex/RS485_HalfDuplex.ino
+++ examples/RS485_HalfDuplex/RS485_HalfDuplex.ino
@@ -3,7 +3,8 @@
   RS485_HalfDuplex.pde - example using ModbusMaster library

   This example is tested against an EPSolar LS2024B solar charge controller.
-  See here for protocol specs: http://www.solar-elektro.cz/data/dokumenty/1733_modbus_protocol.pdf
+  See here for protocol specs:
+  http://www.solar-elektro.cz/data/dokumenty/1733_modbus_protocol.pdf

   This file is part of ModbusMaster.

@@ -61,7 +62,7 @@

   // Modbus slave ID 1
   node.begin(1, Serial);
-  // Hook up callbacks allowing us to configure the RS485 transceiver correctly
+  // Callbacks allow us to configure the RS485 transceiver correctly
   node.preTransmission(preTransmission);
   node.postTransmission(postTransmission);
 }
@@ -79,13 +80,15 @@

   // Read 16 registers starting at 0x3100)
   result = node.readInputRegisters(0x3100, 16);
-  if (result == node.ku8MBSuccess) {
+  if (result == node.ku8MBSuccess)
+  {
     Serial.print("Vbatt: ");
     Serial.println(node.getResponseBuffer(0x04)/100.0f);
     Serial.print("Vload: ");
     Serial.println(node.getResponseBuffer(0xC0)/100.0f);
     Serial.print("Pload: ");
-    Serial.println((node.getResponseBuffer(0x0D) + node.getResponseBuffer(0x0E) << 16)/100.0f);
+    Serial.println((node.getResponseBuffer(0x0D) +
+                    node.getResponseBuffer(0x0E) << 16)/100.0f);
   }

   delay(1000);


updated parallel out 2

updated parallel out 2

--- proj/parallel_out_test_2/parallel_out_test_2.ino
+++ proj/parallel_out_test_2/parallel_out_test_2.ino
@@ -11,6 +11,9 @@
 // WS2811_PORTD: 25,26,27,28,14,15,29,11
 //

+CRGBPalette16 gPalette;
+uint8_t gHue;
+
 void setup() {
   LEDS.addLeds<WS2811_PORTD, NUM_STRIPS>(leds, NUM_LED);
   LEDS.setBrightness(32);
@@ -19,15 +22,47 @@
 }

 void loop() {
-  static uint8_t hue = 0;
+
+  EVERY_N_MILLISECONDS(10) {
+    gHue++;
+  }
+
+  update_RainbowBlack_p();
+  theater_chase();
+
+  // Set the first n leds on each strip to show which strip it is
   for (int i = 0; i < NUM_STRIPS; i++) {
-    for (int j = 0; j < NUM_LED; j++) {
-      leds[(i * NUM_LED) + j] = CHSV((32 * i) + hue + j, 192, 255);
+    for (int j = 0; j <= i; j++) {
+      leds[(i * NUM_LED) + j] = CRGB::Red;
     }
   }

-  hue++;

   LEDS.show();
   LEDS.delay(10);
 }
+
+void theater_chase() {
+  static uint8_t pal_index = 0;
+  EVERY_N_MILLISECONDS(100) {
+    pal_index++;
+  }
+
+  for (uint8_t ss = 0; ss < NUM_STRIPS; ss++) {
+    fill_palette(&(leds[ss*NUM_LED]), NUM_LED, pal_index, 6, gPalette, 60, LINEARBLEND);
+  }
+
+}
+
+// RB|B|B|B repeating
+void update_RainbowBlack_p() {
+  // Instead of blacking out, fill backgroud with rainbow, then
+  // fill every thing with black except
+  fill_rainbow(gPalette, 16, gHue, 10);
+  for (uint8_t i = 0 ; i < 16; i++) {
+    if ( i % 4 == 0) {
+      continue;
+    }
+    gPalette[i] = CRGB::Black;
+  }
+}


tidying up a little...

tidying up a little...

--- epir.ino
+++ epir.ino
@@ -1,18 +1,26 @@
 /*
-inspired by http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1287148367
+*
+* occupy ping pong
+*
+* sven kraeuter for
+*
+* makers & co.
+*
+* http://makersand.co
+*
+* code inspired by http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1287148367
+*
 */

-int calibrationTime = 30;
-
-long unsigned int lowIn;
+byte calibrationTime = 30;

 long unsigned int pause = 1000;

 byte motionCounter = 0;

-int pirPin = 2;
-int ledPin = 9;
-//SETUP
+byte pirPin = 2;
+byte ledPin = 9;
+
 void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
@@ -28,9 +36,6 @@
    Serial.println("SENSOR ACTIVE");
    delay(50);
  }
-
-////////////////////////////
-//LOOP

 void loop(){
   if(digitalRead(pirPin) == HIGH){


Add copyright to RIODuino code

Add copyright to RIODuino code

--- RIODuino/RIODuino.ino
+++ RIODuino/RIODuino.ino
@@ -1,4 +1,9 @@
 /*
+ * FRC 4931 (http://www.evilletech.com)
+ *
+ * Open source software. Licensed under the FIRST BSD license file in the
+ * root directory of this project's Git repository.
+ *
  * This program uses the third-party library NeoPixel.
  * You must download and install this library in order to compile and upload the code.
  * You can download it for free at http://github.com/adafruit/Adafruit_NeoPixel
@@ -89,4 +94,3 @@
 {
   controller.show();
 }
-