//Code is based on: http://www.technoblogy.com/show?1ONY //Rewritten by Klaas-jan Winkel #define DEBUGLEDPIN 13 #define DEBUGSPEED 15624 #define CHARLIESPEED 24 void setup() { pinMode(DEBUGLEDPIN, OUTPUT); configureInterupt(); } void loop() { recalculateColorBrightnessLED(); delay(200); } //*****************Interrupt code********************************** //this will compile for Arduino UNO, Pro and older boards #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) void configureInterupt() { //TODO: The Arduino UNO version maybe is not running at the right frequency with these settings? //cli(); noInterrupts(); TCCR1A = 0; //set entire TCCR1A register to 0 TCCR1B = 0; //same //set compare match register to desired timer count: OCR1A = CHARLIESPEED; //int timer1_counter = 34286; //TCNT1 = 34286; //turn on CTC Mode TCCR1B |= (1 << WGM12); //TCCR1B = 1< 5kHz TIMSK = TIMSK | 1< 15) y = 31 - y; return max(y, 0); } int green (int x) { return red(x + 32); } int blue (int x) { return red(x + 64); } int getFirstNibble(int x) { return x & KEEPONLY_FIRST_NIBBLE_ANDMASK; } int getSecondNibble(int x) { //shift the second nibble into the first position return x>>4 & KEEPONLY_FIRST_NIBBLE_ANDMASK;; } int getThirdNibble(int x) { //shift the third nibble into the first position return x>>8 & KEEPONLY_FIRST_NIBBLE_ANDMASK; } int getCurrentbrightnessFromState(int astate) { //shift the third nibble into the first position return astate>>2; } int getLEDNrFromState(int astate) { return astate & KEEPONLY_FIRST_TWO_BITS_ANDMASK; }