#include <Adafruit_NeoPixel.h>
#define PIN 0
uint8_t rit = 0;
bool francesco = false;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(48, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show(); 
}

void loop() {
  demo_rotate();
}

void demo_rotate() { 
  static uint8_t massimo = 24;
  
  static uint16_t hue = 0; // 0-359
  static uint8_t saturation = 100; // 0-100
 static uint8_t lightness = 50; // 0-100
  
  uint32_t color;
  uint8_t i, num = 0; 
  
  if(rit < 20 && !francesco) {
    if(rit == 19) francesco = true; 
    rit++; 
  }
  else if(rit > 10 && francesco) {
    if(rit == 9) francesco = false; 
    rit--; 
  }

  for(i=0; i < massimo; i++) {
    color = hsl(hue+=2, saturation, lightness);
    strip.setPixelColor(i, color);
    if(i%3==0) num++;
    strip.setPixelColor(24+i-num, color);
    strip.show();
    delay(20-rit);
  }

  hue %= 360;
}

uint32_t hsl(uint16_t ih, uint8_t is, uint8_t il) {

  float h, s, l, t1, t2, tr, tg, tb;
  uint8_t r, g, b;

  h = (ih % 360) / 360.0;
  s = constrain(is, 0, 100) / 100.0;
  l = constrain(il, 0, 100) / 100.0;

  if ( s == 0 ) { 
    r = g = b = 255 * l;
    return ((uint32_t)r << 16) | ((uint32_t)g <<  8) | b;
  } 
  
  if ( l < 0.5 ) t1 = l * (1.0 + s);
  else t1 = l + s - l * s;
  
  t2 = 2 * l - t1;
  tr = h + 1/3.0;
  tg = h;
  tb = h - 1/3.0;

  r = hsl_convert(tr, t1, t2);
  g = hsl_convert(tg, t1, t2);
  b = hsl_convert(tb, t1, t2);

  return ((uint32_t)r << 16) | ((uint32_t)g <<  8) | b;
}

uint8_t hsl_convert(float c, float t1, float t2) {

  if ( c < 0 ) c+=1; 
  else if ( c > 1 ) c-=1;

  if ( 6 * c < 1 ) c = t2 + ( t1 - t2 ) * 6 * c;
  else if ( 2 * c < 1 ) c = t1;
  else if ( 3 * c < 2 ) c = t2 + ( t1 - t2 ) * ( 2/3.0 - c ) * 6;
  else c = t2;
  
  return (uint8_t)(c*255); 
}
ATTINY8520PU