 
 ////////////////////////////////////////////////////////////////////////////////////
 
-unsigned char rgb_colors[3];
-
+
+inline void interruptSetup() {
+    const unsigned char buttonPin=3;
+    //cli(); //disable interrupts
+    // initialize the pushbutton pin as an input:
+    pinMode(buttonPin, INPUT);
+
+    MCUCR = 0; //The low level of INT0 generates an interrupt request.
+    //MCUCR = 1; //Any logical change on INT0 generates an interrupt request.
+    //MCUCR = 2; //The falling edge of INT0 generates an interrupt request.
+    //MCUCR = 3; //The rising edge of INT0 generates an interrupt request.
+    
+    //GIMSK |= (1<<6); //Bit 6 INT0: External Interrupt Request 0 Enable
+    GIMSK |= (1<<5); //Bit 5 PCIE: Pin Change Interrupt Enable
+    PCMSK |= (1<<buttonPin); //PCINT[5:0]: Pin Change Enable Mask 5:0
+    //sei(); //enable interrupts
+}
+
+void setup() {
+    interruptSetup();
+    ledsetup();
+}
+
+ISR(PCINT0_vect) {
+    //showColor(0,0,0);
+}
+
+//unsigned char rgb_colors[3];
 unsigned char led_colors[PIXELS][3];
 
-void setup() {
-  ledsetup();
-}
-
 void loop() {
-/*
-  for (unsigned int hue=0; hue < 360; hue++) {
-    //getRGB(hue, rgb_colors);   // converts HSB to RGB
-    
-    hsv2rgb_rainbow(hue, 200, 200, rgb_colors);
-    showColor(rgb_colors[0], rgb_colors[1], rgb_colors[2]);
-    delay(10);
-  }
-  */
-  
-  /* //works great
-  for (unsigned char hue=0; hue < 255; hue++) {
-    hsv2rgb_rainbow(hue, 255, 255, rgb_colors);
-    showColor(rgb_colors[0], rgb_colors[1], rgb_colors[2]);
-    delay(20);
-    }  
-    */
-    
   for (unsigned char hue=0; hue < 255; hue++) {
     for (unsigned char index=0; index < PIXELS; index++) {
         hsv2rgb_rainbow(hue+(index*30), 255, 255, led_colors[index]);

}
*/

/* 
  dim_curve 'lookup table' to compensate for the nonlinearity of human vision.
  Used in the getRGB function on saturation and brightness to make 'dimming' look more natural. 
  Exponential function used to create values below : 
  x from 0 - 255 : y = round(pow( 2.0, x+64/40.0) - 1)   
*/
/*
const unsigned char dim_curve[] = {
    0,   1,   1,   2,   2,   2,   2,   2,   2,   3,   3,   3,   3,   3,   3,   3,
    3,   3,   3,   3,   3,   3,   3,   4,   4,   4,   4,   4,   4,   4,   4,   4,
    4,   4,   4,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   6,   6,   6,
    6,   6,   6,   6,   6,   7,   7,   7,   7,   7,   7,   7,   8,   8,   8,   8,
    8,   8,   9,   9,   9,   9,   9,   9,   10,  10,  10,  10,  10,  11,  11,  11,
    11,  11,  12,  12,  12,  12,  12,  13,  13,  13,  13,  14,  14,  14,  14,  15,
    15,  15,  16,  16,  16,  16,  17,  17,  17,  18,  18,  18,  19,  19,  19,  20,
    20,  20,  21,  21,  22,  22,  22,  23,  23,  24,  24,  25,  25,  25,  26,  26,
    27,  27,  28,  28,  29,  29,  30,  30,  31,  32,  32,  33,  33,  34,  35,  35,
    36,  36,  37,  38,  38,  39,  40,  40,  41,  42,  43,  43,  44,  45,  46,  47,
    48,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,
    63,  64,  65,  66,  68,  69,  70,  71,  73,  74,  75,  76,  78,  79,  81,  82,
    83,  85,  86,  88,  90,  91,  93,  94,  96,  98,  99,  101, 103, 105, 107, 109,
    110, 112, 114, 116, 118, 121, 123, 125, 127, 129, 132, 134, 136, 139, 141, 144,
    146, 149, 151, 154, 157, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 190,
    193, 196, 200, 203, 207, 211, 214, 218, 222, 226, 230, 234, 238, 242, 248, 255,
};
*/

void getRGB(int hue, unsigned char colors[3]) { 
  /* convert hue, saturation and brightness ( HSB/HSV ) to RGB
     The dim_curve is used only on brightness/value and on saturation (inverted).
     This looks the most natural.      
  */

  //val = dim_curve[val];
  //sat = 255-dim_curve[255-sat];
  const unsigned char val = 255;
  const unsigned char sat = 255;

  int r;
  int g;
  int b;
  int base;

  if (sat == 0) { // Acromatic color (gray). Hue doesn't mind.
    colors[0]=val;
    colors[1]=val;
    colors[2]=val;  
  } else  { 

    base = ((255 - sat) * val)>>8;

    switch(hue/60) {
  case 0:
    r = val;
    g = (((val-base)*hue)/60)+base;
    b = base;
  break;

  case 1:
    r = (((val-base)*(60-(hue%60)))/60)+base;
    g = val;
    b = base;
  break;

  case 2:
    r = base;
    g = val;
    b = (((val-base)*(hue%60))/60)+base;
  break;

  case 3:
    r = base;
    g = (((val-base)*(60-(hue%60)))/60)+base;
    b = val;
  break;

  case 4:
    r = (((val-base)*(hue%60))/60)+base;
    g = base;
    b = val;
  break;

  case 5:
    r = val;
    g = base;
    b = (((val-base)*(60-(hue%60)))/60)+base;
  break;
    }
    
    
    //brightness?
    

    colors[0]=r;
    colors[1]=g;
    colors[2]=b; 
  }   
}


////////////////////////////////////////////////////////////////////////////////////

#endif
#else
#error "No implementation for scale8 available."
#endif
}

static inline void nscale8_video_LEAVING_R1_DIRTY( unsigned char & i, unsigned char scale)
{
#if SCALE8_C == 1 || defined(LIB8_ATTINY)
    i = (((int)i * (int)scale) >> 8) + ((i&&scale)?1:0);
#elif SCALE8_AVRASM == 1
    asm volatile(
        "  tst %[i]\n\t"
        "  breq L_%=\n\t"
        "  mul %[i], %[scale]\n\t"
        "  mov %[i], r1\n\t"
        "  breq L_%=\n\t"
        "  subi %[i], 0xFF\n\t"
        "L_%=: \n\t"
        : [i] "+a" (i)
        : [scale] "a" (scale)
        : "r0", "r1");
#else
#error "No implementation for scale8_video_LEAVING_R1_DIRTY available."
#endif
}

static inline void cleanup_R1()
{
#if CLEANUP_R1_AVRASM == 1
    // Restore r1 to "0"; it's expected to always be that
    asm volatile( "clr __zero_reg__  \n\t" : : : "r1" );
#endif
}

