A simple RGB led fader

I've used Atmel AVR's for many years, here's my first simple test of Arduino Uno, with some hardware intructions:

/*
  RainbowLED
 This example shows how to fade an RGB LED on pin 6, 9 and 11 with 
 three different phases through 1530 colors (bitShift=8) down to
 6 colors (bitShift=1). Speed is changed by varying the voltage on 
 analog input 0
 
 created 9 Nov 2013
 by Tino Johannesson
 
 This example code is in the public domain.
 */
const int bitShift = 8;  // range 1-8
const int maxCount = ((1 << bitShift)-1);
const int top = maxCount*2;
const int bottom = -maxCount;
const int mpy = 255 / maxCount;

int ledRed = 6;        // the pin the red LED is attached to
int ledGreen = 9;      // the pin the green LED is attached to
int ledBlue = 11;      // the pin the blue LED is attached to

int counterRed = maxCount;    // initial counter red
int counterGreen = maxCount;  // initial counter green
int counterBlue = -maxCount;  // initial counter blue

int countRed = -1;    // initial count down for red
int countGreen = 1;   // initial count up for green
int countBlue = 1;    // initial count up for blue

int levelRed, levelGreen, levelBlue;

void setup()  {
  // the setup routine runs once when you press reset:

  // declare pin 6, 9, 11 to be outputs:
  pinMode(ledRed, OUTPUT);
  pinMode(ledGreen, OUTPUT);
  pinMode(ledBlue, OUTPUT);
} 

// the loop routine runs over and over again forever:
void loop()  { 
  // set the brightness of pins 6, 9, 11 in the counter span 0-1, 0-3, 0-7, 0-15, 0-31, 0-63, 0-127, 0-255:
  if (counterRed>=0 && counterRed<=maxCount) {
    levelRed = counterRed*mpy;
  }  
  if (counterGreen>=0 && counterGreen<=maxCount) {
    levelGreen = counterGreen*mpy;
  }   
  if (counterBlue>=0 && counterBlue<=maxCount) {
    levelBlue = counterBlue*mpy;
  } 

  {
    analogWrite(ledRed, levelRed);
  }
  {
    analogWrite(ledGreen, (levelGreen & 255)/2);
  }    // adjustment for, as in my test setup, to bright green LED, use
  // analogWrite(ledGreen, levelGreen); 
  // if the brightness is more even.
  // brightness differences between colors could also be adjusted with 
  // different values for the anode resistors
  {
    analogWrite(ledBlue, levelBlue);
  } 

  // change the brightness for next time through the loop:
  counterRed = counterRed + countRed;
  counterGreen = counterGreen + countGreen;
  counterBlue = counterBlue + countBlue;

  // reverse the direction of the counters when hitting top or bottom: 
  if ((counterRed <= bottom) || (counterRed >= top)) {
    countRed = -countRed ; 
  }     
  if (counterGreen <= bottom || counterGreen >= top) {
    countGreen = -countGreen ; 
  }     
  if (counterBlue <= bottom || counterBlue >= top) {
    countBlue = -countBlue ; 
  }   
  // wait for appr. 1-57 milliseconds to next loop, adjusted for number of colors in each cycle    
  delay(mpy*((pow((1023-analogRead(0))/64, 2)/4)+1));   // read analog input 0 and exponentiate to
  // get a more useable range with 15 speed steps, reverse by removing '1023-'                         
}

/* Use a common cathode RGB LED, connect cathode to GND, red, green and blue
 anodes to digital pins 6, 9 and 11 through suitable resistors, usually 
 100-220 Ohms. Connect the outer connectors of an 1k to 100k potentiometer 
 to +5V and ground and the middle connector to analog input 0, or connect 
 analog input 0 to other 0-5V source.
 */

Code tags, please.

How to use this forum