// This is code for the Atmolight Master controller // Bart Venneker 2013 // www.bartvenneker.nl // // This code recieves data for the Atmolight. It controlls the left and right RGB LED strips // and sends color data for the top RGB LED strip to a second (slave) controller int latchPin = 13; // Go Pin int dataPin = 12; // Data Pin int olr; int og; int ob; #define RedPinLeft 9 //Red pin 9 #define GreenPinLeft 10 //Green pin 10 #define BluePinLeft 11 //Blue pin 11 #define RedPinRight 3 //Red pin 3 #define GreenPinRight 5 //Green pin 5 #define BluePinRight 6 //Blue pin 6 int incomingatmo[255]; int buffer=0; int i=0; int idle=0; void setup() { Serial.begin(38400); pinMode(latchPin, OUTPUT); pinMode(dataPin, OUTPUT); digitalWrite(latchPin, LOW); SendTopColor(0,0,0); // reset the topcolor } void fadeout(){ for(i=1;i<16;i++){ buffer = incomingatmo[i]; if (buffer > 0) { buffer=buffer-1; } incomingatmo[i]=buffer; } idle = 200; WriteLEDArray(); } void WriteLEDArray() { // I only do very basic led controll // I Ignore brightness and gamma settings from the Atmolight protocol // left channel = 4, 5 and 6 // right channel = 7, 8 and 9 // top channel = 10, 11 and 12 analogWrite(RedPinLeft, incomingatmo[4]); // Left Red analogWrite(GreenPinLeft, incomingatmo[5]); // Left Green analogWrite(BluePinLeft, incomingatmo[6]); // Left Blue analogWrite(RedPinRight, incomingatmo[7]); // Right Red analogWrite(GreenPinRight, incomingatmo[8]); // Right Green analogWrite(BluePinRight, incomingatmo[9]); // Right Blue // Now send the top colors to our second AVR SendTopColor(incomingatmo[10],incomingatmo[11],incomingatmo[12]); } void SendSerialByte(int inByte){ // This is a very simple way to transfer bytes // We use a fixed pulse lenght, the other side uses the same timing // Simple synchronisation is done by the latch signal int pulseLenght = 100; for (int pp=0; pp<8; pp++){ digitalWrite(dataPin, bitRead(inByte,pp)); delayMicroseconds(pulseLenght); } } void SendTopColor(int rp,int gp, int bp) { digitalWrite(dataPin, LOW); // might not be needed digitalWrite(latchPin, HIGH); // this latch tells the other AVR to start listening SendSerialByte(rp); // RED value SendSerialByte(gp); // GREEN value SendSerialByte(bp); // BLUE value digitalWrite(latchPin, LOW); } void loop() { // This part of the code is based on code from http://fun3md.blogspot.nl/ if(Serial.available()>0) { buffer = Serial.read(); // wait for the start byte 0xff if(buffer==0xff) // here it is :-) { while(Serial.available()==0) { } // do nothing until the next byte arives buffer=Serial.read(); if(buffer==0x00) // this is the start channel low byte { while(Serial.available()==0) { } // do nothing until the next byte arives buffer=Serial.read(); if(buffer==0x00) // this is the start channel high byte { for(i=0;i<16;i++) // the next 15 bytes are 5 rgb zones { while(Serial.available()==0) { } // do nothing until the next byte arives incomingatmo[i]=Serial.read(); // store the bytes in an array } idle = 0; WriteLEDArray(); } } } } else { WriteLEDArray(); delay(5); idle = idle +1; if (idle > 200) { fadeout(); } } }