 #include <Bounce.h>
 
 // -----------------------------------------------------------------------------
-// Hardware Mapping
+// Hardware Mapping - Arduino Leonardo
 
-static const byte sPins[8] = 
+template<int Pin>
+class ToggleButton : public Bounce
+{
+public:
+    static const int sDebouncingTimeMs = 10;
+
+public:
+    inline ToggleButton()
+        : Bounce(Pin, sDebouncingTimeMs)
+        , mState(false)
+    {
+
+    }
+
+public:
+    static inline void init()
+    {
+        pinMode(Pin, INPUT_PULLUP);
+    }
+
+    inline bool process()
+    {
+        const bool status = update();
+
+        if (fallingEdge())
+        {
+            mState = true; // Pressed
+        }
+        else if (risingEdge())
+        {
+            mState = false; // Released
+        }
+        if (mState != mPreviousState)
+        {
+            mPreviousState = mState;
+            return mState;
+        }
+        return false;
+    }
+private:
+    bool mState;
+    bool mPreviousState;
+};
+
+static const byte sOutputPins[8] =
 {
     0, 1, 2, 3, 4, 5, 6, 7
 };
 
-static const byte sPinMode = 14; // A0
-static const byte sPinIncr = 15; // A1
-static const byte sPinDecr = 16; // A2
+static const byte sModePin = 20; // A2
+static const byte sDecrPin = 21; // A3
+static const byte sIncrPin = 22; // A4
+static const byte sGndPin  = 23; // A5
 
-static const unsigned long sDebouncingTime = 10; // ms
-Bounce sModeButton(sPinMode, sDebouncingTime);
-Bounce sIncrButton(sPinIncr, sDebouncingTime);
-Bounce sDecrButton(sPinDecr, sDebouncingTime);
+ToggleButton<sModePin> sModeButton;
+ToggleButton<sIncrPin> sIncrButton;
+ToggleButton<sDecrPin> sDecrButton;
 
 // -----------------------------------------------------------------------------
 


    for (unsigned i = 0; i < numIterations; ++i)
    {
        sModeButton.update();
        if (sModeButton.fallingEdge())
        {
            sRunningMode = !sRunningMode;
            return true;
        }
        delay(sSleepTime);

{
    while (true)
    {
        const unsigned previous = sCurrentStep;
        sCurrentStep = (sCurrentStep + 1) & 0x7;
        updatePins(previous);
        if (yield(1000))
        {
            reset();
