Download this file
#include   
#include 
#include "TwoColorLED.h"
#include "RotaryEncoder.h"
#include "PushButton.h"
#include "Random.h"
#include 

volatile uint8_t counter = 0;
volatile uint8_t compare = 8;
#define MAX_COMPARE 0xFF
#define MAX_ILLUMINATION 500
#define MAX_LEDS 3
#define MAX_BUTTONS 4

RotaryEncoder re(12,13);
TwoColorLED leds[MAX_LEDS] = { TwoColorLED(6,7), TwoColorLED(3,4), TwoColorLED(9,11) };
PushButton buttons[MAX_BUTTONS] = { PushButton(8), PushButton(2), PushButton(10), PushButton(5) };

#define LEDS(op) leds[0].op ; leds[1].op; leds[2].op

//Timer2 overflow interrupt vector handler, called (16,000,000/256)/8 times per second
ISR(TIMER2_OVF_vect) {
  counter = (counter + 1) & MAX_COMPARE;
  if (counter == 0 && compare > 0) {
    LEDS(pulse(1));
  }
  else if (counter == compare && compare < MAX_COMPARE) {
    LEDS(pulse(0));
  }
}; 

uint8_t dim_steps[] = {0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F};
uint8_t step = 0;

void setup() {
  //Serial.begin(57600);
  
  //Timer2 Settings: Timer Prescaler /8, WGM mode 0
  TCCR2A = 0;
  TCCR2B = 1<= MAX_LEDS) {
        //Serial.read(); // Remove the next char too
        Serial.println("Ei");
        return ;
      }
      else 
        wait_next = 1;
    }
    else {
      switch (c) {
        case 'R':
          leds[id].red();
          break;
        case 'G':
          leds[id].green();
          break;
        case 'Y':
          leds[id].yellow();
          break;
        case 'B':
          leds[id].deactivate();
          break;
        default:
          Serial.println("Ec");
          break;
      }
      wait_next = 0;
    }
  }
}

void loop () {

  handleInput();

  int8_t r = re.read();
  if (r == 1)
    Serial.println("R+");
  else if (r == -1)
    Serial.println("R-");
    
  for (uint8_t i = 0; i MAX_ILLUMINATION) I = MAX_ILLUMINATION;
    compare = I * MAX_COMPARE / MAX_ILLUMINATION;
    if (compare == 0) compare = 1;
  }
}