Project showcase

Cubik Lamp © GPL3+

Super cool Rubik's cube lamp made to relax students in the middle of tense study at night.

  • 5,038 views
  • 2 comments
  • 14 respects

Components and supplies

About this project

Product Interaction

It has always been my aspiration to look at a daily product around my life and think how could I improve and build a stronger relationship between it and the users. I chose to increment the desk lamp in this project. This object always sits on our table giving light when we need it to study at night. However, we humans need a break between study from time to time, the usual activity during a break for today’s student is to play social media on a mobile phone. This is time consuming, due to the huge load of information being gained. I have designed this product to make sure that a five- minute break will last five and it will also be a break.

I use two Arduino Mega as a microcontroller for this interactive product. The communication between remote control and the object is possible through Xbee wireless module. The product enclosure was designed in Rhino 3D then export to a laser cutting machine to cut an acrylic sheet. Watch the link to see product in action.

MORE AWESOME PROJECTS: https://kimbab.me/portfolio/

Schematics

Cubik Schematic
Inside Cubik brain i manage to connect Aduino Mega with On/Off switch, potentiometer and LED data line. I am using WS2812B RGB light strip because it is much easier to manage the wire instead of traditional LED. I also connect Xbee to this unit to receive the Serial data from the controller in case of interactivity.
Tumblr inline onolgqcrkg1uh4sph 540 zve5ogm5te

Code

Cubik lamp codeArduino
Just upload this code on Arduino mega under Cubik lamp
#include <Adafruit_NeoPixel.h>

#define controller Serial1
#define cubik Serial
#define ledPin 3

int incomingByte = 0;

Adafruit_NeoPixel rubikLight = Adafruit_NeoPixel(54, ledPin);

int white[3]  = { 238, 150, 238 };
int red[3]    = { 255, 0  , 0   };
int blue[3]   = { 0  , 0  , 255 };
int violet[3] = { 255, 80 , 0   };
int green[3]  = { 0  , 55 , 0   };
int yellow[3] = { 255, 200, 0   };

// int white[3]  = { 255, 255, 255 };
// int red[3]    = { 255, 0  , 0   };
// int blue[3]   = { 0  , 0  , 255 };
// int violet[3] = { 238, 150, 238 };
// int green[3]  = { 0  , 55 , 0   };
// int yellow[3] = { 255, 255, 0   };

int colorBufferTH[3]     = { 0, 0, 0}; 
int colorBufferMH[3]     = { 0, 0, 0};
int colorBufferBH[3]     = { 0, 0, 0};

int colorBufferLVL[3]    = { 0, 0, 0}; 
int colorBufferLVM[3]    = { 0, 0, 0};
int colorBufferLVR[3]    = { 0, 0, 0};

int colorBufferRVL[3]    = { 0, 0, 0}; 
int colorBufferRVM[3]    = { 0, 0, 0};
int colorBufferRVR[3]    = { 0, 0, 0};

int topBufferOne[3]      = { 0, 0, 0};
int bottomBufferOne[3]   = { 0, 0, 0};
int topBufferTwo[3]      = { 0, 0, 0};
int bottomBufferTwo[3]   = { 0, 0, 0};
int topBufferThree[3]    = { 0, 0, 0};
int bottomBufferThree[3] = { 0, 0, 0};
int topBufferFour[3]     = { 0, 0, 0};
int bottomBufferFour[3]  = { 0, 0, 0};
int topBufferFive[3]     = { 0, 0, 0};
int bottomBufferFive[3]  = { 0, 0, 0};
int topBufferSix[3]      = { 0, 0, 0};
int bottomBufferSix[3]   = { 0, 0, 0};
int topBufferSeven[3]    = { 0, 0, 0};
int bottomBufferSeven[3] = { 0, 0, 0};
int topBufferEight[3]    = { 0, 0, 0};
int bottomBufferEight[3] = { 0, 0, 0};

int leftBufferOne[3]     = { 0, 0, 0};
int rightBufferOne[3]    = { 0, 0, 0};
int leftBufferTwo[3]     = { 0, 0, 0};
int rightBufferTwo[3]    = { 0, 0, 0};
int leftBufferThree[3]   = { 0, 0, 0};
int rightBufferThree[3]  = { 0, 0, 0};
int leftBufferFour[3]    = { 0, 0, 0};
int rightBufferFour[3]   = { 0, 0, 0};
int leftBufferFive[3]    = { 0, 0, 0};
int rightBufferFive[3]   = { 0, 0, 0};
int leftBufferSix[3]     = { 0, 0, 0};
int rightBufferSix[3]    = { 0, 0, 0};
int leftBufferSeven[3]   = { 0, 0, 0};
int rightBufferSeven[3]  = { 0, 0, 0};
int leftBufferEight[3]   = { 0, 0, 0};
int rightBufferEight[3]  = { 0, 0, 0};

int frontBufferOne[3]    = { 0, 0, 0};
int backBufferOne[3]     = { 0, 0, 0};
int frontBufferTwo[3]    = { 0, 0, 0};
int backBufferTwo[3]     = { 0, 0, 0};
int frontBufferThree[3]  = { 0, 0, 0};
int backBufferThree[3]   = { 0, 0, 0};
int frontBufferFour[3]   = { 0, 0, 0};
int backBufferFour[3]    = { 0, 0, 0};
int frontBufferFive[3]   = { 0, 0, 0};
int backBufferFive[3]    = { 0, 0, 0};
int frontBufferSix[3]    = { 0, 0, 0};
int backBufferSix[3]     = { 0, 0, 0};
int frontBufferSeven[3]  = { 0, 0, 0};
int backBufferSeven[3]   = { 0, 0, 0};
int frontBufferEight[3]  = { 0, 0, 0};
int backBufferEight[3]   = { 0, 0, 0};

int FirstPanel[3][3][4]        = { {{0 , red[0]   , red[1]   , red[2]   } , {1 , red[0]   , red[1]   , red[2]   } , {2 , red[0]   , red[1]   , red[2]   }} , {{3 , red[0]   , red[1]   , red[2]   } , {4 , red[0]   , red[1]   , red[2]   } , {5 , red[0]   , red[1]   , red[2]   }} , {{6 , red[0]   , red[1]   , red[2]   } , {7 , red[0]   , red[1]   , red[2]   } , {8 , red[0]   , red[1]   , red[2]   }} };
int SecondPanel[3][3][4]       = { {{9 , green[0] , green[1] , green[2] } , {10, green[0] , green[1] , green[2] } , {11, green[0] , green[1] , green[2] }} , {{12, green[0] , green[1] , green[2] } , {13, green[0] , green[1] , green[2] } , {14, green[0] , green[1] , green[2] }} , {{15, green[0] , green[1] , green[2] } , {16, green[0] , green[1] , green[2] } , {17, green[0] , green[1] , green[2] }} };
int ThirdPanel[3][3][4]        = { {{18, violet[0], violet[1], violet[2]} , {19, violet[0], violet[1], violet[2]} , {20, violet[0], violet[1], violet[2]}} , {{21, violet[0], violet[1], violet[2]} , {22, violet[0], violet[1], violet[2]} , {23, violet[0], violet[1], violet[2]}} , {{24, violet[0], violet[1], violet[2]} , {25, violet[0], violet[1], violet[2]} , {26, violet[0], violet[1], violet[2]}} };
int FourthPanel[3][3][4]       = { {{27, blue[0]  , blue[1]  , blue[2]  } , {28, blue[0]  , blue[1]  , blue[2]  } , {29, blue[0]  , blue[1]  , blue[2]  }} , {{30, blue[0]  , blue[1]  , blue[2]  } , {31, blue[0]  , blue[1]  , blue[2]  } , {32, blue[0]  , blue[1]  , blue[2]  }} , {{33, blue[0]  , blue[1]  , blue[2]  } , {34, blue[0]  , blue[1]  , blue[2]  } , {35, blue[0]  , blue[1]  , blue[2]  }} };
int FifthPanel[3][3][4]        = { {{36, white[0] , white[1] , white[2] } , {37, white[0] , white[1] , white[2] } , {38, white[0] , white[1] , white[2] }} , {{39, white[0] , white[1] , white[2] } , {40, white[0] , white[1] , white[2] } , {41, white[0] , white[1] , white[2] }} , {{42, white[0] , white[1] , white[2] } , {43, white[0] , white[1] , white[2] } , {44, white[0] , white[1] , white[2] }} };
int SixPanel[3][3][4]          = { {{45, yellow[0], yellow[1], yellow[2]} , {46, yellow[0], yellow[1], yellow[2]} , {47, yellow[0], yellow[1], yellow[2]}} , {{48, yellow[0], yellow[1], yellow[2]} , {49, yellow[0], yellow[1], yellow[2]} , {50, yellow[0], yellow[1], yellow[2]}} , {{51, yellow[0], yellow[1], yellow[2]} , {52, yellow[0], yellow[1], yellow[2]} , {53, yellow[0], yellow[1], yellow[2]}} }; 

//Horizontal movement
int horizontalFirst[3][3]      = {{0,1,2}    , {3,4,5}    , {6,7,8}   };
int horizontalSecond[3][3]     = {{9,10,11}  , {12,13,14} , {15,16,17}};
int horizontalThird[3][3]      = {{18,19,20} , {21,22,23} , {24,25,26}};
int horizontalFourth[3][3]     = {{27,28,29} , {30,31,32} , {33,34,35}};

//left vertical movement
int leftVerticalFirst[3][3]    = {{2,5,8}    , {1,4,7}    , {0,3,6}   };
int leftVerticalFifth[3][3]    = {{38,41,44} , {37,40,43} , {36,39,42}};
int leftVerticalThird[3][3]    = {{24,21,18} , {25,22,19} , {26,23,20}};
int leftVerticalSix[3][3]      = {{47,50,53} , {46,49,52} , {45,48,51}};

//right vertical movement
int rightVerticalFourth[3][3]  = {{29,32,35} , {28,31,34} , {27,30,33}};
int rightVerticalFifth[3][3]   = {{44,43,42} , {41,40,39} , {38,37,36}};
int rightVerticalSix[3][3]     = {{45,46,47} , {48,49,50} , {51,52,53}};
int rightVerticalSecond[3][3]  = {{15,12,9}  , {16,13,10} , {17,14,11}};

int incoming;
int tl, currentTL;
int tm, currentTM;
int tr, currentTR;
int ml, currentML;
int mm, currentMM;
int mr, currentMR;
int bl, currentBL;
int bm, currentBM;
int br, currentBR;

int lampSwitch = 2;
int pot = A0;
int colorVal;
int sensVal;

int rotVal;
int curRotVal;

int rotValTwo;
int curRotValTwo;

unsigned long time;

void setup() {

    rubikLight.begin();
    rubikLight.show();
  
    // put your setup code here, to run once:
    controller.begin(9600);
    cubik.begin(9600);

    pinMode(lampSwitch , INPUT);
    pinMode(pot        , INPUT);
    pinMode(ledPin     , OUTPUT);

    curRotVal = analogRead(pot);

    rubikLight.setBrightness(255);

    currentTL = 0;
    currentTM = 0;
    currentTR = 0;
    currentML = 0;
    currentMM = 0;
    currentMR = 0;
    currentBL = 0;
    currentBM = 0;
    currentBR = 0;

}

void loop() {
 
	// put your main code here, to run repeatedly:
	
	if (digitalRead(lampSwitch) == HIGH) {
	  
	    colorVal = map(analogRead(pot),0,1024,0,255);
	  
	    for(int i = 0 ; i < rubikLight.numPixels() ; i++) {
		    rubikLight.setPixelColor(i,0,0,colorVal);
	    }
	  
	    rubikLight.show();

	} else if (digitalRead(lampSwitch) == LOW) {

        for (int row = 0; row < 3; row++)
	    {
	    	for (int col = 0; col < 3; col++)
	    	{
	 
	    		rubikLight.setPixelColor(FirstPanel[row][col][0], FirstPanel[row][col][1], FirstPanel[row][col][2], FirstPanel[row][col][3]);
	    		rubikLight.setPixelColor(SecondPanel[row][col][0], SecondPanel[row][col][1], SecondPanel[row][col][2], SecondPanel[row][col][3]);
	    		rubikLight.setPixelColor(ThirdPanel[row][col][0], ThirdPanel[row][col][1], ThirdPanel[row][col][2], ThirdPanel[row][col][3]);
	    		rubikLight.setPixelColor(FourthPanel[row][col][0], FourthPanel[row][col][1], FourthPanel[row][col][2], FourthPanel[row][col][3]);
	    		rubikLight.setPixelColor(FifthPanel[row][col][0], FifthPanel[row][col][1], FifthPanel[row][col][2], FifthPanel[row][col][3]);
	    		rubikLight.setPixelColor(SixPanel[row][col][0], SixPanel[row][col][1], SixPanel[row][col][2], SixPanel[row][col][3]);	    		
	         
	    	}
	    }

	    rubikLight.show();

		if(controller.available() > 0) {

		    incoming = controller.read();
		    //cubik.write(incoming);

		    if(incoming == 'A') {
		    	tl = controller.parseInt();
		    	cubik.print("TL ");
		    	cubik.println(tl);
		    }

		    if(incoming == 'B') {
		    	tm = controller.parseInt();
		    	cubik.print("TM ");
		    	cubik.println(tm);
		    }

		    if(incoming == 'C') {
		    	tr = controller.parseInt();
		    	cubik.print("TR ");
		    	cubik.println(tr);
		    }

		    if(incoming == 'D') {
		    	ml = controller.parseInt();
		    	cubik.print("ML ");
		    	cubik.println(ml);
		    }

		    if(incoming == 'E') {
		    	mm = controller.parseInt();
		    	cubik.print("MM ");
		    	cubik.println(mm);
		    }

		    if(incoming == 'F') {
		    	mr = controller.parseInt();
		    	cubik.print("MR ");
		    	cubik.println(mr);
		    }

		    if(incoming == 'G') {
		    	bl = controller.parseInt();
		    	cubik.print("BL ");
		    	cubik.println(bl);
		    }

		    if(incoming == 'H') {
		    	bm = controller.parseInt();
		    	cubik.print("BM ");
		    	cubik.println(bm);
		    }

		    if(incoming == 'T') {
		    	br = controller.parseInt();
		    	cubik.print("BR ");
		    	cubik.println(br);		    	
		    }

//---------------------------------------------------------------------------------------------------------------------------------------------
// Horizontal sides move
//---------------------------------------------------------------------------------------------------------------------------------------------

		    //rotate leds top horizontal line

		    if( currentTL - tl >= 2) {

	            for (int k = 0; k < 3; k++)
	            {
	            	for (int i = 0; i < 3; i++)
	            	{
	            		for (int j = 0; j < 3; j++)
	            		{

			            	if ( horizontalFirst[0][k] == FirstPanel[i][j][0] ) {

			            		colorBufferTH[0] = FourthPanel[i][j][1];
			            		colorBufferTH[1] = FourthPanel[i][j][2];
			            		colorBufferTH[2] = FourthPanel[i][j][3];

			                    FourthPanel[i][j][1] = FirstPanel[i][j][1];
			                    FourthPanel[i][j][2] = FirstPanel[i][j][2];
			                    FourthPanel[i][j][3] = FirstPanel[i][j][3];

		                        FirstPanel[i][j][1]  = SecondPanel[i][j][1];
		                        FirstPanel[i][j][2]  = SecondPanel[i][j][2];
		                        FirstPanel[i][j][3]  = SecondPanel[i][j][3];

		                        SecondPanel[i][j][1] = ThirdPanel[i][j][1];
		                        SecondPanel[i][j][2] = ThirdPanel[i][j][2];
		                        SecondPanel[i][j][3] = ThirdPanel[i][j][3];

		                        ThirdPanel[i][j][1]  = colorBufferTH[0];
		                        ThirdPanel[i][j][2]  = colorBufferTH[1];
		                        ThirdPanel[i][j][3]  = colorBufferTH[2];

		                    }
	                    }
	            	}   
	            }
 
	            //move right

	            for (int i = 0; i < 3; ++i)
	            {
	            	//36
                    topBufferOne[i] = FifthPanel[0][0][i + 1];
                    //37
	                topBufferTwo[i] = FifthPanel[0][1][i + 1];
	                //38
	                topBufferThree[i] = FifthPanel[0][2][i + 1];
	                //39
	                topBufferFour[i] = FifthPanel[1][0][i + 1];
	                //41
	                topBufferFive[i] = FifthPanel[1][2][i + 1];
	                //42
	                topBufferSix[i] = FifthPanel[2][0][i + 1];
	                //43
	                topBufferSeven[i] = FifthPanel[2][1][i + 1];
	                //44
	                topBufferEight[i] = FifthPanel[2][2][i + 1];

	                //first row 36 to 42
		            FifthPanel[0][0][i + 1] = topBufferSix[i];
	                // 37 to 39
		            FifthPanel[0][1][i + 1] = topBufferFour[i];
                    // 38 to 36
		            FifthPanel[0][2][i + 1] = topBufferOne[i];

	                //second row 39 to 43
		            FifthPanel[1][0][i + 1] = topBufferSeven[i];
	                // 41 to 37
		            FifthPanel[1][2][i + 1] = topBufferTwo[i];

	                //third row 42 to 44
		            FifthPanel[2][0][i + 1] = topBufferEight[i];
                    // 43 to 41
		            FifthPanel[2][1][i + 1] = topBufferFive[i];
	                // 44 to 38
		            FifthPanel[2][2][i + 1] = topBufferThree[i];

	            }

	            currentTL = tl;

                cubik.print("CurrentTL ");
			    cubik.println(currentTL);  

 		    } else if (tl - currentTL >= 2) {
                 
	            for (int k = 0; k < 3; k++)
	            {
	            	for (int i = 0; i < 3; i++)
	            	{
	            		for (int j = 0; j < 3; j++)
	            		{

			            	if ( horizontalFirst[0][k] == FirstPanel[i][j][0] ) {

			            		colorBufferTH[0] = FourthPanel[i][j][1];
			            		colorBufferTH[1] = FourthPanel[i][j][2];
			            		colorBufferTH[2] = FourthPanel[i][j][3];

			                    FourthPanel[i][j][1] = ThirdPanel[i][j][1];
			                    FourthPanel[i][j][2] = ThirdPanel[i][j][2];
			                    FourthPanel[i][j][3] = ThirdPanel[i][j][3];

		                        ThirdPanel[i][j][1]  = SecondPanel[i][j][1];
		                        ThirdPanel[i][j][2]  = SecondPanel[i][j][2];
		                        ThirdPanel[i][j][3]  = SecondPanel[i][j][3];

		                        SecondPanel[i][j][1] = FirstPanel[i][j][1];
		                        SecondPanel[i][j][2] = FirstPanel[i][j][2];
		                        SecondPanel[i][j][3] = FirstPanel[i][j][3];

		                        FirstPanel[i][j][1]  = colorBufferTH[0];
		                        FirstPanel[i][j][2]  = colorBufferTH[1];
		                        FirstPanel[i][j][3]  = colorBufferTH[2];
		                        
	                        }
	                    }
	            	}   
	            }

	            //move left

	            for (int i = 0; i < 3; ++i)
	            {
	            	//36
                    topBufferOne[i] = FifthPanel[0][0][i + 1];
                    //37
	                topBufferTwo[i] = FifthPanel[0][1][i + 1];
	                //38
	                topBufferThree[i] = FifthPanel[0][2][i + 1];
	                //39
	                topBufferFour[i] = FifthPanel[1][0][i + 1];
	                //41
	                topBufferFive[i] = FifthPanel[1][2][i + 1];
	                //42
	                topBufferSix[i] = FifthPanel[2][0][i + 1];
	                //43
	                topBufferSeven[i] = FifthPanel[2][1][i + 1];
	                //44
	                topBufferEight[i] = FifthPanel[2][2][i + 1];

	                //first row 36 to 38
		            FifthPanel[0][0][i + 1] = topBufferThree[i];
	                // 37 to 41
		            FifthPanel[0][1][i + 1] = topBufferFive[i];
                    // 38 to 44
		            FifthPanel[0][2][i + 1] = topBufferEight[i];

	                //second row 39 to 37
		            FifthPanel[1][0][i + 1] = topBufferTwo[i];
	                // 41 to 43
		            FifthPanel[1][2][i + 1] = topBufferSeven[i];

	                //third row 42 to 36
		            FifthPanel[2][0][i + 1] = topBufferOne[i];
                    // 43 to 39
		            FifthPanel[2][1][i + 1] = topBufferFour[i];
	                // 44 to 42
		            FifthPanel[2][2][i + 1] = topBufferSix[i];

	            }

	            currentTL = tl;

                cubik.print("CurrentTL ");
			    cubik.println(currentTL);  

 		    }





//---------------------------------------------------------------------------------------------------------------------------------------------

	        //rotate leds middle horizontal line

		    if( currentTM - tm >= 2) {

	            for (int k = 0; k < 3; k++)
	            {
	            	for (int i = 0; i < 3; i++)
	            	{
	            		for (int j = 0; j < 3; j++)
	            		{

			            	if ( horizontalFirst[1][k] == FirstPanel[i][j][0] ) {

			            		colorBufferMH[0] = FourthPanel[i][j][1];
			            		colorBufferMH[1] = FourthPanel[i][j][2];
			            		colorBufferMH[2] = FourthPanel[i][j][3];

			                    FourthPanel[i][j][1] = FirstPanel[i][j][1];
			                    FourthPanel[i][j][2] = FirstPanel[i][j][2];
			                    FourthPanel[i][j][3] = FirstPanel[i][j][3];

		                        FirstPanel[i][j][1]  = SecondPanel[i][j][1];
		                        FirstPanel[i][j][2]  = SecondPanel[i][j][2];
		                        FirstPanel[i][j][3]  = SecondPanel[i][j][3];

		                        SecondPanel[i][j][1] = ThirdPanel[i][j][1];
		                        SecondPanel[i][j][2] = ThirdPanel[i][j][2];
		                        SecondPanel[i][j][3] = ThirdPanel[i][j][3];

		                        ThirdPanel[i][j][1]  = colorBufferMH[0];
		                        ThirdPanel[i][j][2]  = colorBufferMH[1];
		                        ThirdPanel[i][j][3]  = colorBufferMH[2];

		                    }
	                    }
	            	}   
	            }

	            currentTM = tm;

                cubik.print("CurrentTM ");
			    cubik.println(currentTM);  

 		    } else if (tm - currentTM >= 2) {
                 
	            for (int k = 0; k < 3; k++)
	            {
	            	for (int i = 0; i < 3; i++)
	            	{
	            		for (int j = 0; j < 3; j++)
	            		{

			            	if ( horizontalFirst[1][k] == FirstPanel[i][j][0] ) {

			            		colorBufferMH[0] = FourthPanel[i][j][1];
			            		colorBufferMH[1] = FourthPanel[i][j][2];
			            		colorBufferMH[2] = FourthPanel[i][j][3];

			                    FourthPanel[i][j][1] = ThirdPanel[i][j][1];
			                    FourthPanel[i][j][2] = ThirdPanel[i][j][2];
			                    FourthPanel[i][j][3] = ThirdPanel[i][j][3];

		                        ThirdPanel[i][j][1]  = SecondPanel[i][j][1];
		                        ThirdPanel[i][j][2]  = SecondPanel[i][j][2];
		                        ThirdPanel[i][j][3]  = SecondPanel[i][j][3];

		                        SecondPanel[i][j][1] = FirstPanel[i][j][1];
		                        SecondPanel[i][j][2] = FirstPanel[i][j][2];
		                        SecondPanel[i][j][3] = FirstPanel[i][j][3];

		                        FirstPanel[i][j][1]  = colorBufferMH[0];
		                        FirstPanel[i][j][2]  = colorBufferMH[1];
		                        FirstPanel[i][j][3]  = colorBufferMH[2];
           
	                        }
	                    }
	            	}   
	            }

	            currentTM = tm;

                cubik.print("CurrentTM ");
			    cubik.println(currentTM); 

 		    }





//---------------------------------------------------------------------------------------------------------------------------------------------

			//rotate leds bottom horizontal line

		    if( currentTR - tr >= 2) {

	            for (int k = 0; k < 3; k++)
	            {
	            	for (int i = 0; i < 3; i++)
	            	{
	            		for (int j = 0; j < 3; j++)
	            		{

			            	if ( horizontalFirst[2][k] == FirstPanel[i][j][0] ) {

			            		colorBufferBH[0] = FourthPanel[i][j][1];
			            		colorBufferBH[1] = FourthPanel[i][j][2];
			            		colorBufferBH[2] = FourthPanel[i][j][3];

			                    FourthPanel[i][j][1] = FirstPanel[i][j][1];
			                    FourthPanel[i][j][2] = FirstPanel[i][j][2];
			                    FourthPanel[i][j][3] = FirstPanel[i][j][3];

		                        FirstPanel[i][j][1]  = SecondPanel[i][j][1];
		                        FirstPanel[i][j][2]  = SecondPanel[i][j][2];
		                        FirstPanel[i][j][3]  = SecondPanel[i][j][3];

		                        SecondPanel[i][j][1] = ThirdPanel[i][j][1];
		                        SecondPanel[i][j][2] = ThirdPanel[i][j][2];
		                        SecondPanel[i][j][3] = ThirdPanel[i][j][3];

		                        ThirdPanel[i][j][1]  = colorBufferBH[0];
		                        ThirdPanel[i][j][2]  = colorBufferBH[1];
		                        ThirdPanel[i][j][3]  = colorBufferBH[2];

		                    }
	                    }
	            	}   
	            }

	            //move right

	            for (int i = 0; i < 3; ++i)
	            {
	            	//45
                    bottomBufferOne[i] = SixPanel[0][0][i + 1];
                    //46
	                bottomBufferTwo[i] = SixPanel[0][1][i + 1];
	                //47
	                bottomBufferThree[i] = SixPanel[0][2][i + 1];
	                //48
	                bottomBufferFour[i] = SixPanel[1][0][i + 1];
	                //50
	                bottomBufferFive[i] = SixPanel[1][2][i + 1];
	                //51
	                bottomBufferSix[i] = SixPanel[2][0][i + 1];
	                //52
	                bottomBufferSeven[i] = SixPanel[2][1][i + 1];
	                //53
	                bottomBufferEight[i] = SixPanel[2][2][i + 1];

	                //first row 45 to 47
		            SixPanel[0][0][i + 1] = bottomBufferThree[i];
	                // 46 to 50
		            SixPanel[0][1][i + 1] = bottomBufferFive[i];
                    // 47 to 53
		            SixPanel[0][2][i + 1] = bottomBufferEight[i];

	                //second row 48 to 46
		            SixPanel[1][0][i + 1] = bottomBufferTwo[i];
	                // 50 to 52
		            SixPanel[1][2][i + 1] = bottomBufferSeven[i];

	                //third row 51 to 45
		            SixPanel[2][0][i + 1] = bottomBufferOne[i];
                    // 52 to 48
		            SixPanel[2][1][i + 1] = bottomBufferFour[i];
	                // 53 to 51
		            SixPanel[2][2][i + 1] = bottomBufferSix[i];

	            }

	            currentTR = tr;

                cubik.print("CurrentTR ");
			    cubik.println(currentTR); 

 		    } else if (tr - currentTR >= 2) {
                 
	            for (int k = 0; k < 3; k++)
	            {
	            	for (int i = 0; i < 3; i++)
	            	{
	            		for (int j = 0; j < 3; j++)
	            		{

			            	if ( horizontalFirst[2][k] == FirstPanel[i][j][0] ) {

			            		colorBufferBH[0] = FourthPanel[i][j][1];
			            		colorBufferBH[1] = FourthPanel[i][j][2];
			            		colorBufferBH[2] = FourthPanel[i][j][3];

			                    FourthPanel[i][j][1] = ThirdPanel[i][j][1];
			                    FourthPanel[i][j][2] = ThirdPanel[i][j][2];
			                    FourthPanel[i][j][3] = ThirdPanel[i][j][3];

		                        ThirdPanel[i][j][1]  = SecondPanel[i][j][1];
		                        ThirdPanel[i][j][2]  = SecondPanel[i][j][2];
		                        ThirdPanel[i][j][3]  = SecondPanel[i][j][3];

		                        SecondPanel[i][j][1] = FirstPanel[i][j][1];
		                        SecondPanel[i][j][2] = FirstPanel[i][j][2];
		                        SecondPanel[i][j][3] = FirstPanel[i][j][3];

		                        FirstPanel[i][j][1]  = colorBufferBH[0];
		                        FirstPanel[i][j][2]  = colorBufferBH[1];
		                        FirstPanel[i][j][3]  = colorBufferBH[2];
                   
	                        }
	                    }
	            	}   
	            }

	            //move left

	            for (int i = 0; i < 3; ++i)
	            {
	            	//45
                    bottomBufferOne[i] = SixPanel[0][0][i + 1];
                    //46
	                bottomBufferTwo[i] = SixPanel[0][1][i + 1];
	                //47
	                bottomBufferThree[i] = SixPanel[0][2][i + 1];
	                //48
	                bottomBufferFour[i] = SixPanel[1][0][i + 1];
	                //50
	                bottomBufferFive[i] = SixPanel[1][2][i + 1];
	                //51
	                bottomBufferSix[i] = SixPanel[2][0][i + 1];
	                //52
	                bottomBufferSeven[i] = SixPanel[2][1][i + 1];
	                //53
	                bottomBufferEight[i] = SixPanel[2][2][i + 1];

	                //first row 45 to 51
		            SixPanel[0][0][i + 1] = bottomBufferSix[i];
	                // 46 to 48
		            SixPanel[0][1][i + 1] = bottomBufferFour[i];
                    // 47 to 45
		            SixPanel[0][2][i + 1] = bottomBufferOne[i];

	                //second row 48 to 50
		            SixPanel[1][0][i + 1] = bottomBufferFive[i];
	                // 50 to 46
		            SixPanel[1][2][i + 1] = bottomBufferTwo[i];

	                //third row 51 to 53
		            SixPanel[2][0][i + 1] = bottomBufferEight[i];
                    // 52 to 46
		            SixPanel[2][1][i + 1] = bottomBufferTwo[i];
	                // 53 to 47
		            SixPanel[2][2][i + 1] = bottomBufferThree[i];

	            }

	            currentTR = tr;

                cubik.print("CurrentTR ");
			    cubik.println(currentTR); 

 		    }





//---------------------------------------------------------------------------------------------------------------------------------------------
// Left Vertical
//---------------------------------------------------------------------------------------------------------------------------------------------

			//rotate lEDs left vertical left line

		    if( currentMR - mr >= 2) {

	            for (int k = 0; k < 3; k++)
	            {
	            	for (int i = 0; i < 3; i++)
	            	{
	            		for (int j = 0; j < 3; j++)
	            		{
	            			for (int l = 0; l < 3; l++)
	            			{
                            
                            for (int m = 0; m < 3; m++)
                            {

			            	if ( leftVerticalFirst[0][k] == FirstPanel[i][j][0] && leftVerticalThird[0][k] == ThirdPanel[l][m][0]) {

			            		colorBufferLVL[0]      = FirstPanel[i][j][1];
			            		colorBufferLVL[1]      = FirstPanel[i][j][2];
			            		colorBufferLVL[2]      = FirstPanel[i][j][3];

			                    FirstPanel[i][j][1] = SixPanel[i][j][1];
			                    FirstPanel[i][j][2] = SixPanel[i][j][2];
			                    FirstPanel[i][j][3] = SixPanel[i][j][3];

		                        SixPanel[i][j][1]   = ThirdPanel[l][m][1];
		                        SixPanel[i][j][2]   = ThirdPanel[l][m][2];
		                        SixPanel[i][j][3]   = ThirdPanel[l][m][3];

		                        ThirdPanel[l][m][1] = FifthPanel[i][j][1];
		                        ThirdPanel[l][m][2] = FifthPanel[i][j][2];
		                        ThirdPanel[l][m][3] = FifthPanel[i][j][3];
        
		                        FifthPanel[i][j][1] = colorBufferLVL[0];
		                        FifthPanel[i][j][2] = colorBufferLVL[1];
		                        FifthPanel[i][j][3] = colorBufferLVL[2];

	                        }

		                    }
		                    }
	                    }
	            	}   
	            }

	            //move right

	            for (int i = 0; i < 3; ++i)
	            {
	            	//9
                    leftBufferOne[i] = SecondPanel[0][0][i + 1];
                    //10
	                leftBufferTwo[i] = SecondPanel[0][1][i + 1];
	                //11
	                leftBufferThree[i] = SecondPanel[0][2][i + 1];
	                //12
	                leftBufferFour[i] = SecondPanel[1][0][i + 1];
	                //14
	                leftBufferFive[i] = SecondPanel[1][2][i + 1];
	                //15
	                leftBufferSix[i] = SecondPanel[2][0][i + 1];
	                //16
	                leftBufferSeven[i] = SecondPanel[2][1][i + 1];
	                //17
	                leftBufferEight[i] = SecondPanel[2][2][i + 1];

	                //first row 9 to 15
		            SecondPanel[0][0][i + 1] = leftBufferSix[i];
	                // 10 to 12
		            SecondPanel[0][1][i + 1] = leftBufferFour[i];
                    // 11 to 9
		            SecondPanel[0][2][i + 1] = leftBufferOne[i];

	                //second row 12 to 16
		            SecondPanel[1][0][i + 1] = leftBufferSeven[i];
	                // 14 to 10
		            SecondPanel[1][2][i + 1] = leftBufferTwo[i];

	                //third row 15 to 17
		            SecondPanel[2][0][i + 1] = leftBufferEight[i];
                    // 16 to 14
		            SecondPanel[2][1][i + 1] = leftBufferFive[i];
	                // 17 to 11
		            SecondPanel[2][2][i + 1] = leftBufferThree[i];

	            }

	            currentMR = mr;

                cubik.print("CurrentMR ");
			    cubik.println(currentMR); 

 		    } else if ( mr - currentMR >= 2) {
                 
	            for (int k = 0; k < 3; k++)
	            {
	            	for (int i = 0; i < 3; i++)
	            	{
	            		for (int j = 0; j < 3; j++)
	            		{
	            			for (int l = 0; l < 3; l++)
	            			{
                            
                            for (int m = 0; m < 3; m++)
                            {

			            	if ( leftVerticalFirst[0][k] == FirstPanel[i][j][0] && leftVerticalThird[0][k] == ThirdPanel[l][m][0]) {

			            		colorBufferLVL[0]      = FirstPanel[i][j][1];
			            		colorBufferLVL[1]      = FirstPanel[i][j][2];
			            		colorBufferLVL[2]      = FirstPanel[i][j][3];

			                    FirstPanel[i][j][1] = FifthPanel[i][j][1];
			                    FirstPanel[i][j][2] = FifthPanel[i][j][2];
			                    FirstPanel[i][j][3] = FifthPanel[i][j][3];

		                        FifthPanel[i][j][1] = ThirdPanel[l][m][1];
		                        FifthPanel[i][j][2] = ThirdPanel[l][m][2];
		                        FifthPanel[i][j][3] = ThirdPanel[l][m][3];

		                        ThirdPanel[l][m][1] = SixPanel[i][j][1];
		                        ThirdPanel[l][m][2] = SixPanel[i][j][2];
		                        ThirdPanel[l][m][3] = SixPanel[i][j][3];

		                        SixPanel[i][j][1]   = colorBufferLVL[0];
		                        SixPanel[i][j][2]   = colorBufferLVL[1];
		                        SixPanel[i][j][3]   = colorBufferLVL[2];
     
                            }

                            }
	                        }
	                    }
	            	}   
	            }

	            //move left

	            for (int i = 0; i < 3; ++i)
	            {
	            	//9
                    leftBufferOne[i] = SecondPanel[0][0][i + 1];
                    //10
	                leftBufferTwo[i] = SecondPanel[0][1][i + 1];
	                //11
	                leftBufferThree[i] = SecondPanel[0][2][i + 1];
	                //12
	                leftBufferFour[i] = SecondPanel[1][0][i + 1];
	                //14
	                leftBufferFive[i] = SecondPanel[1][2][i + 1];
	                //15
	                leftBufferSix[i] = SecondPanel[2][0][i + 1];
	                //16
	                leftBufferSeven[i] = SecondPanel[2][1][i + 1];
	                //17
	                leftBufferEight[i] = SecondPanel[2][2][i + 1];

	                //first row 9 to 11
		            SecondPanel[0][0][i + 1] = leftBufferThree[i];
	                // 10 to 14
		            SecondPanel[0][1][i + 1] = leftBufferFive[i];
                    // 11 to 17
		            SecondPanel[0][2][i + 1] = leftBufferEight[i];

	                //second row 12 to 10
		            SecondPanel[1][0][i + 1] = leftBufferTwo[i];
	                // 14 to 16
		            SecondPanel[1][2][i + 1] = leftBufferSeven[i];

	                //third row 15 to 9
		            SecondPanel[2][0][i + 1] = leftBufferOne[i];
                    // 16 to 12
		            SecondPanel[2][1][i + 1] = leftBufferFour[i];
	                // 17 to 15
		            SecondPanel[2][2][i + 1] = leftBufferSix[i];

	            }

	            currentMR = mr;

                cubik.print("CurrentMR ");
			    cubik.println(currentMR); 

 		    }





//---------------------------------------------------------------------------------------------------------------------------------------------

			//rotate lEDs left vertical middle line

		    if( currentMM - mm >= 2) {

	            for (int k = 0; k < 3; k++)
	            {
	            	for (int i = 0; i < 3; i++)
	            	{
	            		for (int j = 0; j < 3; j++)
	            		{
	            			for (int l = 0; l < 3; l++)
	            			{
                            
                            for (int m = 0; m < 3; m++)
                            {

			            	if ( leftVerticalFirst[1][k] == FirstPanel[i][j][0] && leftVerticalThird[1][k] == ThirdPanel[l][m][0]) {

			            		colorBufferLVM[0]      = FirstPanel[i][j][1];
			            		colorBufferLVM[1]      = FirstPanel[i][j][2];
			            		colorBufferLVM[2]      = FirstPanel[i][j][3];

			                    FirstPanel[i][j][1] = SixPanel[i][j][1];
			                    FirstPanel[i][j][2] = SixPanel[i][j][2];
			                    FirstPanel[i][j][3] = SixPanel[i][j][3];

		                        SixPanel[i][j][1]   = ThirdPanel[l][m][1];
		                        SixPanel[i][j][2]   = ThirdPanel[l][m][2];
		                        SixPanel[i][j][3]   = ThirdPanel[l][m][3];

		                        ThirdPanel[l][m][1] = FifthPanel[i][j][1];
		                        ThirdPanel[l][m][2] = FifthPanel[i][j][2];
		                        ThirdPanel[l][m][3] = FifthPanel[i][j][3];

		                        FifthPanel[i][j][1] = colorBufferLVM[0];
		                        FifthPanel[i][j][2] = colorBufferLVM[1];
		                        FifthPanel[i][j][3] = colorBufferLVM[2];

	                        }

		                    }
		                    }
	                    }
	            	}   
	            }

	            currentMM = mm;

                cubik.print("CurrentMM ");
			    cubik.println(currentMM); 

 		    } else if ( mm - currentMM >= 2) {
                 
	            for (int k = 0; k < 3; k++)
	            {
	            	for (int i = 0; i < 3; i++)
	            	{
	            		for (int j = 0; j < 3; j++)
	            		{
	            			for (int l = 0; l < 3; l++)
	            			{
                            
                            for (int m = 0; m < 3; m++)
                            {

			            	if ( leftVerticalFirst[1][k] == FirstPanel[i][j][0] && leftVerticalThird[1][k] == ThirdPanel[l][m][0]) {

			            		colorBufferLVM[0]      = FirstPanel[i][j][1];
			            		colorBufferLVM[1]      = FirstPanel[i][j][2];
			            		colorBufferLVM[2]      = FirstPanel[i][j][3];

			                    FirstPanel[i][j][1] = FifthPanel[i][j][1];
			                    FirstPanel[i][j][2] = FifthPanel[i][j][2];
			                    FirstPanel[i][j][3] = FifthPanel[i][j][3];

		                        FifthPanel[i][j][1] = ThirdPanel[l][m][1];
		                        FifthPanel[i][j][2] = ThirdPanel[l][m][2];
		                        FifthPanel[i][j][3] = ThirdPanel[l][m][3];

		                        ThirdPanel[l][m][1] = SixPanel[i][j][1];
		                        ThirdPanel[l][m][2] = SixPanel[i][j][2];
		                        ThirdPanel[l][m][3] = SixPanel[i][j][3];

		                        SixPanel[i][j][1]   = colorBufferLVM[0];
		                        SixPanel[i][j][2]   = colorBufferLVM[1];
		                        SixPanel[i][j][3]   = colorBufferLVM[2];

                            }

                            }
	                        }
	                    }
	            	}   
	            }

	            currentMM = mm;

                cubik.print("CurrentMM ");
			    cubik.println(currentMM); 

 		    }




//---------------------------------------------------------------------------------------------------------------------------------------------

			//rotate lEDs left vertical Right line

		    if( currentML - ml >= 2) {

	            for (int k = 0; k < 3; k++)
	            {
	            	for (int i = 0; i < 3; i++)
	            	{
	            		for (int j = 0; j < 3; j++)
	            		{
	            			for (int l = 0; l < 3; l++)
	            			{
                            
                            for (int m = 0; m < 3; m++)
                            {

			            	if ( leftVerticalFirst[2][k] == FirstPanel[i][j][0] && leftVerticalThird[2][k] == ThirdPanel[l][m][0]) {

			            		colorBufferLVR[0]      = FirstPanel[i][j][1];
			            		colorBufferLVR[1]      = FirstPanel[i][j][2];
			            		colorBufferLVR[2]      = FirstPanel[i][j][3];

			                    FirstPanel[i][j][1] = SixPanel[i][j][1];
			                    FirstPanel[i][j][2] = SixPanel[i][j][2];
			                    FirstPanel[i][j][3] = SixPanel[i][j][3];

		                        SixPanel[i][j][1]   = ThirdPanel[l][m][1];
		                        SixPanel[i][j][2]   = ThirdPanel[l][m][2];
		                        SixPanel[i][j][3]   = ThirdPanel[l][m][3];

		                        ThirdPanel[l][m][1] = FifthPanel[i][j][1];
		                        ThirdPanel[l][m][2] = FifthPanel[i][j][2];
		                        ThirdPanel[l][m][3] = FifthPanel[i][j][3];

		                        FifthPanel[i][j][1] = colorBufferLVR[0];
		                        FifthPanel[i][j][2] = colorBufferLVR[1];
		                        FifthPanel[i][j][3] = colorBufferLVR[2];

	                        }

		                    }
		                    }
	                    }
	            	}   
	            }

	            //move right

	            for (int i = 0; i < 3; ++i)
	            {
	            	//27
                    rightBufferOne[i] = FourthPanel[0][0][i + 1];
                    //28
	                rightBufferTwo[i] = FourthPanel[0][1][i + 1];
	                //29
	                rightBufferThree[i] = FourthPanel[0][2][i + 1];
	                //30
	                rightBufferFour[i] = FourthPanel[1][0][i + 1];
	                //32
	                rightBufferFive[i] = FourthPanel[1][2][i + 1];
	                //33
	                rightBufferSix[i] = FourthPanel[2][0][i + 1];
	                //34
	                rightBufferSeven[i] = FourthPanel[2][1][i + 1];
	                //35
	                rightBufferEight[i] = FourthPanel[2][2][i + 1];

	                //first row 27 to 29
		            FourthPanel[0][0][i + 1] = rightBufferThree[i];
	                // 28 to 32
		            FourthPanel[0][1][i + 1] = rightBufferFive[i];
                    // 29 to 35
		            FourthPanel[0][2][i + 1] = rightBufferEight[i];

	                //second row 30 to 28
		            FourthPanel[1][0][i + 1] = rightBufferTwo[i];
	                // 32 to 34
		            FourthPanel[1][2][i + 1] = rightBufferSeven[i];

	                //third row 33 to 27
		            FourthPanel[2][0][i + 1] = rightBufferOne[i];
                    // 34 to 30
		            FourthPanel[2][1][i + 1] = rightBufferFour[i];
	                // 35 to 33
		            FourthPanel[2][2][i + 1] = rightBufferSix[i];

	            }

	            currentML = ml;

                cubik.print("CurrentML ");
			    cubik.println(currentML);

 		    } else if ( ml - currentML >= 2) {
                 
	            for (int k = 0; k < 3; k++)
	            {
	            	for (int i = 0; i < 3; i++)
	            	{
	            		for (int j = 0; j < 3; j++)
	            		{
	            			for (int l = 0; l < 3; l++)
	            			{
                            
                            for (int m = 0; m < 3; m++)
                            {

			            	if ( leftVerticalFirst[2][k] == FirstPanel[i][j][0] && leftVerticalThird[2][k] == ThirdPanel[l][m][0]) {

			            		colorBufferLVR[0]      = FirstPanel[i][j][1];
			            		colorBufferLVR[1]      = FirstPanel[i][j][2];
			            		colorBufferLVR[2]      = FirstPanel[i][j][3];

			                    FirstPanel[i][j][1] = FifthPanel[i][j][1];
			                    FirstPanel[i][j][2] = FifthPanel[i][j][2];
			                    FirstPanel[i][j][3] = FifthPanel[i][j][3];

		                        FifthPanel[i][j][1] = ThirdPanel[l][m][1];
		                        FifthPanel[i][j][2] = ThirdPanel[l][m][2];
		                        FifthPanel[i][j][3] = ThirdPanel[l][m][3];

		                        ThirdPanel[l][m][1] = SixPanel[i][j][1];
		                        ThirdPanel[l][m][2] = SixPanel[i][j][2];
		                        ThirdPanel[l][m][3] = SixPanel[i][j][3];

		                        SixPanel[i][j][1]   = colorBufferLVR[0];
		                        SixPanel[i][j][2]   = colorBufferLVR[1];
		                        SixPanel[i][j][3]   = colorBufferLVR[2];

                            }

                            }
	                        }
	                    }
	            	}   
	            }

	            //move left

	            for (int i = 0; i < 3; ++i)
	            {
	            	//27
                    rightBufferOne[i] = FourthPanel[0][0][i + 1];
                    //28
	                rightBufferTwo[i] = FourthPanel[0][1][i + 1];
	                //29
	                rightBufferThree[i] = FourthPanel[0][2][i + 1];
	                //30
	                rightBufferFour[i] = FourthPanel[1][0][i + 1];
	                //32
	                rightBufferFive[i] = FourthPanel[1][2][i + 1];
	                //33
	                rightBufferSix[i] = FourthPanel[2][0][i + 1];
	                //34
	                rightBufferSeven[i] = FourthPanel[2][1][i + 1];
	                //35
	                rightBufferEight[i] = FourthPanel[2][2][i + 1];

	                //first row 27 to 33
		            FourthPanel[0][0][i + 1] = rightBufferSix[i];
	                // 28 to 30
		            FourthPanel[0][1][i + 1] = rightBufferFour[i];
                    // 29 to 27
		            FourthPanel[0][2][i + 1] = rightBufferOne[i];

	                //second row 30 to 34
		            FourthPanel[1][0][i + 1] = rightBufferSeven[i];
	                // 32 to 28
		            FourthPanel[1][2][i + 1] = rightBufferTwo[i];

	                //third row 33 to 35
		            FourthPanel[2][0][i + 1] = rightBufferEight[i];
                    // 34 to 32
		            FourthPanel[2][1][i + 1] = rightBufferFive[i];
	                // 35 to 29
		            FourthPanel[2][2][i + 1] = rightBufferThree[i];

	            }

	            currentML = ml;

                cubik.print("CurrentML ");
			    cubik.println(currentML);

 		    }





//---------------------------------------------------------------------------------------------------------------------------------------------
// Right Vertical
//---------------------------------------------------------------------------------------------------------------------------------------------

			//rotate lEDs right vertical left line

		    if( currentBR - br >= 2) {

	            for (int k = 0; k < 3; k++)
	            {

	            	for (int i = 0; i < 3; i++){for (int j = 0; j < 3; j++){for (int l = 0; l < 3; l++){for (int m = 0; m < 3; m++){for (int n = 0; n < 3; n++){for (int o = 0; o < 3; o++){for (int p = 0; p < 3; p++){for (int q = 0; q < 3; q++){

		            	if ( rightVerticalFourth[0][k] == FourthPanel[i][j][0] && rightVerticalFifth[0][k] == FifthPanel[l][m][0] && rightVerticalSix[0][k] == SixPanel[n][o][0] && rightVerticalSecond[0][k] == SecondPanel[p][q][0]) {

		            		colorBufferRVL[0]       = FourthPanel[i][j][1];
		            		colorBufferRVL[1]       = FourthPanel[i][j][2];
		            		colorBufferRVL[2]       = FourthPanel[i][j][3];

		                    FourthPanel[i][j][1] = SixPanel[n][o][1];
		                    FourthPanel[i][j][2] = SixPanel[n][o][2];
		                    FourthPanel[i][j][3] = SixPanel[n][o][3];

	                        SixPanel[n][o][1]    = SecondPanel[p][q][1];
	                        SixPanel[n][o][2]    = SecondPanel[p][q][2];
	                        SixPanel[n][o][3]    = SecondPanel[p][q][3];

	                        SecondPanel[p][q][1] = FifthPanel[l][m][1];
	                        SecondPanel[p][q][2] = FifthPanel[l][m][2];
	                        SecondPanel[p][q][3] = FifthPanel[l][m][3];

	                        FifthPanel[l][m][1]  = colorBufferRVL[0];
	                        FifthPanel[l][m][2]  = colorBufferRVL[1];
	                        FifthPanel[l][m][3]  = colorBufferRVL[2];

                        }

                    }}}}}}}}   

	            }

	            //move right

	            for (int i = 0; i < 3; ++i)
	            {
	            	//0
                    frontBufferOne[i] = FirstPanel[0][0][i + 1];
                    //1
	                frontBufferTwo[i] = FirstPanel[0][1][i + 1];
	                //2
	                frontBufferThree[i] = FirstPanel[0][2][i + 1];
	                //3
	                frontBufferFour[i] = FirstPanel[1][0][i + 1];
	                //5
	                frontBufferFive[i] = FirstPanel[1][2][i + 1];
	                //6
	                frontBufferSix[i] = FirstPanel[2][0][i + 1];
	                //7
	                frontBufferSeven[i] = FirstPanel[2][1][i + 1];
	                //8
	                frontBufferEight[i] = FirstPanel[2][2][i + 1];

	                //first row 0 to 6
		            FirstPanel[0][0][i + 1] = frontBufferSix[i];
	                // 1 to 3
		            FirstPanel[0][1][i + 1] = frontBufferFour[i];
                    // 2 to 0
		            FirstPanel[0][2][i + 1] = frontBufferOne[i];

	                //second row 3 to 7
		            FirstPanel[1][0][i + 1] = frontBufferSeven[i];
	                // 5 to 1
		            FirstPanel[1][2][i + 1] = frontBufferTwo[i];

	                //third row 6 to 8
		            FirstPanel[2][0][i + 1] = frontBufferEight[i];
                    // 7 to 5
		            FirstPanel[2][1][i + 1] = frontBufferFive[i];
	                // 8 to 2
		            FirstPanel[2][2][i + 1] = frontBufferThree[i];

	            }

	            currentBR = br;

                cubik.print("CurrentBR ");
			    cubik.println(currentBR);

 		    } else if ( br - currentBR >= 2 ) {
                 
	            for (int k = 0; k < 3; k++)
	            {

	            	for (int i = 0; i < 3; i++){for (int j = 0; j < 3; j++){for (int l = 0; l < 3; l++){for (int m = 0; m < 3; m++){for (int n = 0; n < 3; n++){for (int o = 0; o < 3; o++){for (int p = 0; p < 3; p++){for (int q = 0; q < 3; q++){

		            	if ( rightVerticalFourth[0][k] == FourthPanel[i][j][0] && rightVerticalFifth[0][k] == FifthPanel[l][m][0] && rightVerticalSix[0][k] == SixPanel[n][o][0] && rightVerticalSecond[0][k] == SecondPanel[p][q][0]) {

		            		colorBufferRVL[0]      = FourthPanel[i][j][1];
		            		colorBufferRVL[1]      = FourthPanel[i][j][2];
		            		colorBufferRVL[2]      = FourthPanel[i][j][3];

		                    FourthPanel[i][j][1] = FifthPanel[l][m][1];
		                    FourthPanel[i][j][2] = FifthPanel[l][m][2];
		                    FourthPanel[i][j][3] = FifthPanel[l][m][3];

	                        FifthPanel[l][m][1] = SecondPanel[p][q][1];
	                        FifthPanel[l][m][2] = SecondPanel[p][q][2];
	                        FifthPanel[l][m][3] = SecondPanel[p][q][3];

	                        SecondPanel[p][q][1] = SixPanel[n][o][1];
	                        SecondPanel[p][q][2] = SixPanel[n][o][2];
	                        SecondPanel[p][q][3] = SixPanel[n][o][3];

	                        SixPanel[n][o][1]   = colorBufferRVL[0];
	                        SixPanel[n][o][2]   = colorBufferRVL[1];
	                        SixPanel[n][o][3]   = colorBufferRVL[2];

                        }

                    }}}}}}}}   

	            }

	            //move left

	            for (int i = 0; i < 3; ++i)
	            {
	            	//0
                    frontBufferOne[i] = FirstPanel[0][0][i + 1];
                    //1
	                frontBufferTwo[i] = FirstPanel[0][1][i + 1];
	                //2
	                frontBufferThree[i] = FirstPanel[0][2][i + 1];
	                //3
	                frontBufferFour[i] = FirstPanel[1][0][i + 1];
	                //5
	                frontBufferFive[i] = FirstPanel[1][2][i + 1];
	                //6
	                frontBufferSix[i] = FirstPanel[2][0][i + 1];
	                //7
	                frontBufferSeven[i] = FirstPanel[2][1][i + 1];
	                //8
	                frontBufferEight[i] = FirstPanel[2][2][i + 1];

	                //first row 0 to 2
		            FirstPanel[0][0][i + 1] = frontBufferThree[i];
	                // 1 to 5
		            FirstPanel[0][1][i + 1] = frontBufferFive[i];
                    // 2 to 8
		            FirstPanel[0][2][i + 1] = frontBufferEight[i];

	                //second row 3 to 1
		            FirstPanel[1][0][i + 1] = frontBufferTwo[i];
	                // 5 to 7
		            FirstPanel[1][2][i + 1] = frontBufferSeven[i];

	                //third row 6 to 0
		            FirstPanel[2][0][i + 1] = frontBufferOne[i];
                    // 7 to 3
		            FirstPanel[2][1][i + 1] = frontBufferFour[i];
	                // 8 to 6
		            FirstPanel[2][2][i + 1] = frontBufferSix[i];

	            }

	            currentBR = br;

                cubik.print("CurrentBR ");
			    cubik.println(currentBR);

 		    }





//---------------------------------------------------------------------------------------------------------------------------------------------
			
			//rotate lEDs right vertical Middle line

		    if( currentBM - bm >= 2) {

	            for (int k = 0; k < 3; k++)
	            {

	            	for (int i = 0; i < 3; i++){for (int j = 0; j < 3; j++){for (int l = 0; l < 3; l++){for (int m = 0; m < 3; m++){for (int n = 0; n < 3; n++){for (int o = 0; o < 3; o++){for (int p = 0; p < 3; p++){for (int q = 0; q < 3; q++){

		            	if ( rightVerticalFourth[1][k] == FourthPanel[i][j][0] && rightVerticalFifth[1][k] == FifthPanel[l][m][0] && rightVerticalSix[1][k] == SixPanel[n][o][0] && rightVerticalSecond[1][k] == SecondPanel[p][q][0]) {

		            		colorBufferRVM[0]       = FourthPanel[i][j][1];
		            		colorBufferRVM[1]       = FourthPanel[i][j][2];
		            		colorBufferRVM[2]       = FourthPanel[i][j][3];

		                    FourthPanel[i][j][1] = SixPanel[n][o][1];
		                    FourthPanel[i][j][2] = SixPanel[n][o][2];
		                    FourthPanel[i][j][3] = SixPanel[n][o][3];

	                        SixPanel[n][o][1]    = SecondPanel[p][q][1];
	                        SixPanel[n][o][2]    = SecondPanel[p][q][2];
	                        SixPanel[n][o][3]    = SecondPanel[p][q][3];

	                        SecondPanel[p][q][1] = FifthPanel[l][m][1];
	                        SecondPanel[p][q][2] = FifthPanel[l][m][2];
	                        SecondPanel[p][q][3] = FifthPanel[l][m][3];

	                        FifthPanel[l][m][1]  = colorBufferRVM[0];
	                        FifthPanel[l][m][2]  = colorBufferRVM[1];
	                        FifthPanel[l][m][3]  = colorBufferRVM[2];

                        }

                    }}}}}}}}   

	            }

	            currentBM = bm;

                cubik.print("CurrentBM ");
			    cubik.println(currentBM);

 		    } else if ( bm - currentBM >= 2 ) {
                 
	            for (int k = 0; k < 3; k++)
	            {

	            	for (int i = 0; i < 3; i++){for (int j = 0; j < 3; j++){for (int l = 0; l < 3; l++){for (int m = 0; m < 3; m++){for (int n = 0; n < 3; n++){for (int o = 0; o < 3; o++){for (int p = 0; p < 3; p++){for (int q = 0; q < 3; q++){

		            	if ( rightVerticalFourth[1][k] == FourthPanel[i][j][0] && rightVerticalFifth[1][k] == FifthPanel[l][m][0] && rightVerticalSix[1][k] == SixPanel[n][o][0] && rightVerticalSecond[1][k] == SecondPanel[p][q][0]) {

		            		colorBufferRVM[0]      = FourthPanel[i][j][1];
		            		colorBufferRVM[1]      = FourthPanel[i][j][2];
		            		colorBufferRVM[2]      = FourthPanel[i][j][3];

		                    FourthPanel[i][j][1] = FifthPanel[l][m][1];
		                    FourthPanel[i][j][2] = FifthPanel[l][m][2];
		                    FourthPanel[i][j][3] = FifthPanel[l][m][3];

	                        FifthPanel[l][m][1] = SecondPanel[p][q][1];
	                        FifthPanel[l][m][2] = SecondPanel[p][q][2];
	                        FifthPanel[l][m][3] = SecondPanel[p][q][3];

	                        SecondPanel[p][q][1] = SixPanel[n][o][1];
	                        SecondPanel[p][q][2] = SixPanel[n][o][2];
	                        SecondPanel[p][q][3] = SixPanel[n][o][3];

	                        SixPanel[n][o][1]   = colorBufferRVM[0];
	                        SixPanel[n][o][2]   = colorBufferRVM[1];
	                        SixPanel[n][o][3]   = colorBufferRVM[2];

                        }

                    }}}}}}}}   

	            }

	            currentBM = bm;

                cubik.print("CurrentBM ");
			    cubik.println(currentBM);

 		    }





//---------------------------------------------------------------------------------------------------------------------------------------------
			
			//rotate lEDs right vertical Right line

		    if( currentBL - bl >= 2 ) {

	            for (int k = 0; k < 3; k++)
	            {

	            	for (int i = 0; i < 3; i++){for (int j = 0; j < 3; j++){for (int l = 0; l < 3; l++){for (int m = 0; m < 3; m++){for (int n = 0; n < 3; n++){for (int o = 0; o < 3; o++){for (int p = 0; p < 3; p++){for (int q = 0; q < 3; q++){

		            	if ( rightVerticalFourth[2][k] == FourthPanel[i][j][0] && rightVerticalFifth[2][k] == FifthPanel[l][m][0] && rightVerticalSix[2][k] == SixPanel[n][o][0] && rightVerticalSecond[2][k] == SecondPanel[p][q][0]) {

		            		colorBufferRVR[0]       = FourthPanel[i][j][1];
		            		colorBufferRVR[1]       = FourthPanel[i][j][2];
		            		colorBufferRVR[2]       = FourthPanel[i][j][3];

		                    FourthPanel[i][j][1] = SixPanel[n][o][1];
		                    FourthPanel[i][j][2] = SixPanel[n][o][2];
		                    FourthPanel[i][j][3] = SixPanel[n][o][3];

	                        SixPanel[n][o][1]    = SecondPanel[p][q][1];
	                        SixPanel[n][o][2]    = SecondPanel[p][q][2];
	                        SixPanel[n][o][3]    = SecondPanel[p][q][3];

	                        SecondPanel[p][q][1] = FifthPanel[l][m][1];
	                        SecondPanel[p][q][2] = FifthPanel[l][m][2];
	                        SecondPanel[p][q][3] = FifthPanel[l][m][3];

	                        FifthPanel[l][m][1]  = colorBufferRVR[0];
	                        FifthPanel[l][m][2]  = colorBufferRVR[1];
	                        FifthPanel[l][m][3]  = colorBufferRVR[2];

                        }

                    }}}}}}}}   

	            }

	            //move right

	            for (int i = 0; i < 3; i++)
	            {
	            	//18
                    backBufferOne[i]   = ThirdPanel[0][0][i + 1];
                    //19
	                backBufferTwo[i]   = ThirdPanel[0][1][i + 1];
	                //20
	                backBufferThree[i] = ThirdPanel[0][2][i + 1];
	                //21
	                backBufferFour[i]  = ThirdPanel[1][0][i + 1];
	                //23
	                backBufferFive[i]  = ThirdPanel[1][2][i + 1];
	                //24
	                backBufferSix[i]   = ThirdPanel[2][0][i + 1];
	                //25
	                backBufferSeven[i] = ThirdPanel[2][1][i + 1];
	                //26
	                backBufferEight[i] = ThirdPanel[2][2][i + 1];

	                //first row 18 to 20
		            ThirdPanel[0][0][i + 1] = backBufferThree[i];
	                // 19 to 23
		            ThirdPanel[0][1][i + 1] = backBufferFive[i];
                    // 20 to 26
		            ThirdPanel[0][2][i + 1] = backBufferEight[i];

	                //second row 21 to 19
		            ThirdPanel[1][0][i + 1] = backBufferTwo[i];
	                // 23 to 25
		            ThirdPanel[1][2][i + 1] = backBufferSeven[i];

	                //third row 24 to 18
		            ThirdPanel[2][0][i + 1] = backBufferOne[i];
                    // 25 to 21
		            ThirdPanel[2][1][i + 1] = backBufferFour[i];
	                // 26 to 24
		            ThirdPanel[2][2][i + 1] = backBufferSix[i];

	            }

	            currentBL = bl;

                cubik.print("CurrentBL ");
			    cubik.println(currentBL);

 		    } else if ( bl - currentBL >= 2 ) {
                 
	            for (int k = 0; k < 3; k++)
	            {

	            	for (int i = 0; i < 3; i++){for (int j = 0; j < 3; j++){for (int l = 0; l < 3; l++){for (int m = 0; m < 3; m++){for (int n = 0; n < 3; n++){for (int o = 0; o < 3; o++){for (int p = 0; p < 3; p++){for (int q = 0; q < 3; q++){

		            	if ( rightVerticalFourth[2][k] == FourthPanel[i][j][0] && rightVerticalFifth[2][k] == FifthPanel[l][m][0] && rightVerticalSix[2][k] == SixPanel[n][o][0] && rightVerticalSecond[2][k] == SecondPanel[p][q][0]) {

		            		colorBufferRVR[0]      = FourthPanel[i][j][1];
		            		colorBufferRVR[1]      = FourthPanel[i][j][2];
		            		colorBufferRVR[2]      = FourthPanel[i][j][3];

		                    FourthPanel[i][j][1] = FifthPanel[l][m][1];
		                    FourthPanel[i][j][2] = FifthPanel[l][m][2];
		                    FourthPanel[i][j][3] = FifthPanel[l][m][3];

	                        FifthPanel[l][m][1] = SecondPanel[p][q][1];
	                        FifthPanel[l][m][2] = SecondPanel[p][q][2];
	                        FifthPanel[l][m][3] = SecondPanel[p][q][3];

	                        SecondPanel[p][q][1] = SixPanel[n][o][1];
	                        SecondPanel[p][q][2] = SixPanel[n][o][2];
	                        SecondPanel[p][q][3] = SixPanel[n][o][3];

	                        SixPanel[n][o][1]   = colorBufferRVR[0];
	                        SixPanel[n][o][2]   = colorBufferRVR[1];
	                        SixPanel[n][o][3]   = colorBufferRVR[2];

                        }

                    }}}}}}}}   

	            }

	            //move left

	            for (int i = 0; i < 3; i++)
	            {
	            	//18
                    backBufferOne[i]   = ThirdPanel[0][0][i + 1];
                    //19
	                backBufferTwo[i]   = ThirdPanel[0][1][i + 1];
	                //20
	                backBufferThree[i] = ThirdPanel[0][2][i + 1];
	                //21
	                backBufferFour[i]  = ThirdPanel[1][0][i + 1];
	                //23
	                backBufferFive[i]  = ThirdPanel[1][2][i + 1];
	                //24
	                backBufferSix[i]   = ThirdPanel[2][0][i + 1];
	                //25
	                backBufferSeven[i] = ThirdPanel[2][1][i + 1];
	                //26
	                backBufferEight[i] = ThirdPanel[2][2][i + 1];

	                //first row 18 to 24
		            ThirdPanel[0][0][i + 1] = backBufferSix[i];
	                // 19 to 21
		            ThirdPanel[0][1][i + 1] = backBufferFour[i];
                    // 20 to 18
		            ThirdPanel[0][2][i + 1] = backBufferOne[i];

	                //second row 21 to 25
		            ThirdPanel[1][0][i + 1] = backBufferSeven[i];
	                // 23 to 19
		            ThirdPanel[1][2][i + 1] = backBufferTwo[i];

	                //third row 24 to 26
		            ThirdPanel[2][0][i + 1] = backBufferEight[i];
                    // 25 to 23
		            ThirdPanel[2][1][i + 1] = backBufferFive[i];
	                // 26 to 20
		            ThirdPanel[2][2][i + 1] = backBufferThree[i];

	            }

	            currentBL = bl;

                cubik.print("CurrentBL ");
			    cubik.println(currentBL);

 		    }





//---------------------------------------------------------------------------------------------------------------------------------------------

		    // currentTL = tl;
		    // currentTM = tm;
		    // currentTR = tr;
		    // currentML = ml;
		    // currentMM = mm;
		    // currentMR = mr;
		    // currentBL = bl;
		    // currentBM = bm;
		    // currentBR = br;    
		 

//---------------------------------------------------------------------------------------------------------------------------------------------





	    }
    
	}
  
	if(controller.available()) {
	   //cubik.write(controller.read());
	}
	 
	// if(cubik.available()) {
	//    controller.write(cubik.read());
	// }


}

Comments

Similar projects you might like

Plant Communicator

Project tutorial by Arduino

  • 103 views
  • 0 comments
  • 0 respects

The Nerd

Project tutorial by Arduino

  • 104 views
  • 1 comment
  • 0 respects

LED Matrix Display Badge

Project tutorial by FabLabAQ

  • 593 views
  • 0 comments
  • 2 respects

PICASO 4.0 The Infinite X- Axis CNC Wall Engraver

Project tutorial by Arnab Kumar Das

  • 118 views
  • 1 comment
  • 1 respect

Object Tracker and Updater

by Rupin Chheda

  • 139 views
  • 0 comments
  • 0 respects

Temperature Control

Project tutorial by reteprelleum

  • 1,158 views
  • 1 comment
  • 7 respects
Add projectSign up / Login