     BSD license, all text above must be included in any redistribution
  ****************************************************/
 
+#include "LED_Matrix.h"
+
+// I shouldn't have to re-include these libs included in LED_Matrix.h
+// but I get
+// LED_Matrix.h:10:19: fatal error: Wire.h: No such file or directory  #include <Wire.h>
 #include <Wire.h>
-#include "LED_Matrix.h"
-#include "Adafruit_GFX.h"
-#include "TimerOne.h"
+#include <Adafruit_GFX.h>
+#include <TimerOne.h>
+
+#define DEBUG 0
+
+// ----------------------------------------------------------------------------
+#ifndef FASTIO
+#define DATA_PIN DINV
+#define CLK_PIN DINV
+#define LATCH1_PIN DINV
+#define LATCH2_PIN DINV
+#define LATCH3_PIN DINV
 
 // These go to ground:
-uint8_t _gnd_lines[] = { 5, 6, 7, 8, 12, 11, 10, 9 };
+GPIO_pin_t gnd_line_pins[] = { 5, 6, 7, 8, 12, 11, 10, 9 };
 // Those go to V+
 // A6 and A7 do NOT work as digital pins on Arduino Nano
-uint8_t _columns[] = { 0,  4, A5, A4, A3, A2, A1, A0 };
+// Red LEDs are directly connected.
+// Green LEDs are connected via shift register
+GPIO_pin_t column_pins[] = {  0,  4, A5, A4, A3, A2, A1, A0,
+                              DINV, DINV, DINV, DINV, DINV, DINV, DINV, DINV,
+                              DINV, DINV, DINV, DINV, DINV, DINV, DINV, DINV, };
+
+// ----------------------------------------------------------------------------
+#else
+#define DATA_PIN DINV
+#define CLK_PIN DINV
+#define LATCH1_PIN DINV
+#define LATCH2_PIN DINV
+#define LATCH3_PIN DINV
+
+GPIO_pin_t gnd_line_pins[] = { DP5, DP6, DP7, DP8, DP12, DP11, DP10, DP9 };
+
+GPIO_pin_t column_pins[] = {  DP0,  DP4, DP19, DP18, DP17, DP16, DP15, DP14,
+                              DINV, DINV, DINV, DINV, DINV, DINV, DINV, DINV,
+                              DINV, DINV, DINV, DINV, DINV, DINV, DINV, DINV, };
+#endif
+// ----------------------------------------------------------------------------
+
+// no shift register in single color test, all latches are set to invalid pin
+GPIO_pin_t sr_pins[] = { DINV, DINV, DINV, DATA_PIN, CLK_PIN };
 
 PWMDirectMatrix *matrix;
 
 void setup() {
-#ifndef __AVR_ATtiny85__
     // Initializing serial breaks one row (shared pin)
-    //Serial.begin(57600);
-    //Serial.println("DirectMatrix Test");
-#endif
-    matrix = new PWMDirectMatrix(8, 8);
-    matrix->begin(_gnd_lines, _columns);
+    if (DEBUG) Serial.begin(57600);
+    if (DEBUG) while (!Serial);
+    if (DEBUG) Serial.println("DirectMatrix Test");
+
+    matrix = new PWMDirectMatrix(8, 8, 1);
+    // The ISR frequency is doubled 3 times to create 4 PWM values
+    // and will run at x, x*2, x*4, x*16 to simulate 16 levels of
+    // intensity without causing 16 interrupts at x, leaving more
+    // time for the main loop and causing less intensity loss.
+    // 200 flickers a bit for me due to the 1600us 4th scan, 150 removes
+    // the flicker for my eyes.
+    matrix->begin(gnd_line_pins, column_pins, sr_pins, 150);
 }
 
 static const uint8_t PROGMEM

        B01000010,
        B00111100 };


void loop() {

    matrix->clear();
    matrix->drawBitmap(0, 0, smile_bmp, 8, 8, LED_RED_HIGH);
    matrix->writeDisplay();
    delay(1000);

    matrix->clear();
    matrix->drawBitmap(0, 0, neutral_bmp, 8, 8, LED_RED_MEDIUM);
    matrix->writeDisplay();
    delay(1000);

    matrix->clear();
    matrix->drawBitmap(0, 0, frown_bmp, 8, 8, LED_RED_VERYLOW);
    matrix->writeDisplay();
    delay(1000);

    matrix->clear();
    matrix->drawLine(0,0, 7,7, LED_RED_MEDIUM);
    matrix->writeDisplay();  // write the changes we just made to the display
    delay(500);

    matrix->clear();
    matrix->drawRect(0,0, 8,8, LED_RED_VERYLOW);
    matrix->fillRect(2,2, 4,4, LED_RED_HIGH);
    matrix->writeDisplay();  // write the changes we just made to the display
    delay(2000);

    matrix->clear();
    matrix->drawCircle(3,3, 3, LED_RED_MEDIUM);
    matrix->writeDisplay();  // write the changes we just made to the display
    delay(500);

    matrix->setTextWrap(false);  // we don't want text to wrap so it scrolls nicely
    matrix->setTextSize(1);
    matrix->setTextColor(LED_RED_MEDIUM);
    matrix->setRotation(1);
    for (int8_t x=7; x>=-36; x--) {
        matrix->clear();
        matrix->setCursor(x,0);

/*************************************************** 
    This is a library to address LED matrices that requires
    constant column/row rescans.

    It uses code from the Adafruit I2C LED backpack library designed for
    ----> http://www.adafruit.com/products/881
    ----> http://www.adafruit.com/products/880
    ----> http://www.adafruit.com/products/879
