#include <SPI.h>

#define BUTTON_PIN 2
#define STORAGE_PIN 8

volatile unsigned long delayTime = 500;
const unsigned long startDelayTime = 500;
const int step = 150;

class Button
{
public:
  Button(int pinB)
  {
    _lastButton = HIGH;
    _curButton = HIGH;
    _pinButton = pinB;
    pinMode(pinB, INPUT_PULLUP);
  }

  ~Button() = default;

  void process()
  {
    _curButton = debounce();
    if (_lastButton == HIGH && _curButton == LOW)
    {
      if(delayTime <= step)
      {
        delayTime = startDelayTime;
      }
      else
      {
        delayTime -= step;       
      }      
    }
    _lastButton = _curButton;
  }

private:
  int _lastButton;
  int _curButton;
  int _pinButton;

  int debounce ()
  {
    int current = digitalRead(_pinButton);
    if(_lastButton != current)
    {
      delay(5);
      current = digitalRead(_pinButton);
    }
    return current;
  }
};

volatile Button button(BUTTON_PIN);

void rotateLeft(uint16_t &bits)
{
uint16_t high_bit = bits & (1 << 15) ? 1 : 0;
bits = (bits << 1) | high_bit;
}

void proxyButton()
{
  button.process();
}

void setup() 
{
  //attachInterrupt(0, proxyButton, CHANGE);
  attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), proxyButton, CHANGE);
  SPI.begin();
  pinMode(STORAGE_PIN, OUTPUT);
  digitalWrite(STORAGE_PIN, LOW);
  SPI.transfer(0);
  SPI.transfer(0);
  digitalWrite(STORAGE_PIN, HIGH);
  digitalWrite(STORAGE_PIN, LOW);
}

void loop() {  
  static uint16_t runningLight = 1;
  SPI.transfer(runningLight>>8);
  SPI.transfer(runningLight);
  digitalWrite(STORAGE_PIN, HIGH);
  digitalWrite(STORAGE_PIN, LOW);
  rotateLeft(runningLight);
  noInterrupts();
  unsigned long tmpTime = delayTime;
  interrupts();
  delay(tmpTime);
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
74HC595
sr1:Q1
sr1:Q2
sr1:Q3
sr1:Q4
sr1:Q5
sr1:Q6
sr1:Q7
sr1:GND
sr1:Q7S
sr1:MR
sr1:SHCP
sr1:STCP
sr1:OE
sr1:DS
sr1:Q0
sr1:VCC
74HC595
sr2:Q1
sr2:Q2
sr2:Q3
sr2:Q4
sr2:Q5
sr2:Q6
sr2:Q7
sr2:GND
sr2:Q7S
sr2:MR
sr2:SHCP
sr2:STCP
sr2:OE
sr2:DS
sr2:Q0
sr2:VCC
led1:A
led1:C
led2:A
led2:C
led3:A
led3:C
led4:A
led4:C
led5:A
led5:C
led6:A
led6:C
led7:A
led7:C
led8:A
led8:C
led9:A
led9:C
led10:A
led10:C
led11:A
led11:C
led12:A
led12:C
led13:A
led13:C
led14:A
led14:C
r1:1
r1:2
r2:1
r2:2
r3:1
r3:2
r4:1
r4:2
r5:1
r5:2
r6:1
r6:2
r7:1
r7:2
r8:1
r8:2
r9:1
r9:2
r10:1
r10:2
r11:1
r11:2
r12:1
r12:2
r13:1
r13:2
r14:1
r14:2
r15:1
r15:2
r16:1
r16:2
led15:A
led15:C
led16:A
led16:C
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r