 }
 // =======================================================================================
 
-// =======================================================================================
-
 // function that executes whenever data is received from an I2C master
 // this function is registered as an event, see setup()
 void receiveEvent(int eventCode) {
-  int i2cEvent=Wire.read();
-
+  int i2cEvent = Wire.read();
   sei();
-  switch (i2cEvent) {
-    case 1:
-      alarmDisplay();
-      //randomDisplay();
-      break;
-   case 5:
-     leiaDisplay();
-     //randomDisplay();
-     break;
-   case 11:
-     alarm2Display(175000);
-     //randomDisplay();
-     break;
-   default:
-     // if nothing else matches, do the default
-     //randomDisplay();
-     break;
-  }
-}
+  
+  if (i2cEvent != 100){
+    // logic display
+    displayEffect = i2cEvent;
+  }
+}

//   RLD OUT1 -> Rear PSI
//   RLD OUT2 -> FLD -> FLD -> Front PSI
//
// BOARDtype sets which Arduino we're using
// 1 = Arduino Pro Mini or Uno or Duemilanove ( http://arduino.cc/en/Main/ArduinoBoardProMini )
// 2 = Sparkfun Pro Micro ( https://www.sparkfun.com/products/11098 )
// 3 = Arduino Micro ( http://arduino.cc/en/Main/ArduinoBoardMicro )
#define BOARDtype 1

char TFLDtext[] =  "PADAWAN         "; //PUT YOUR TOP FRONT STARTUP TEXT HERE.
char BFLDtext[] =  "         BOOTING"; //PUT YOUR BOTTOM FRONT STARTUP TEXT HERE.
char RLDtext[] = "ARTOO DETOO  "; //PUT YOUR REAR STARTUP TEXT HERE.

// set brightness levels here (a value of 0-15)...
int RLDbright=1;   //rear Logic
int RPSIbright=15; //rear PSI
int FLDbright=1;   //front Logics
int FPSIbright=15; //front PSI

//delay time of logic display blinkyness (lower = blink faster)
int LogicBlinkTime=75;

// PSItype sets the type of our front and rear PSI's
// 1 = Teeces original (6 LEDs of each color, arranged side by side)
// 2 = Teeces original checkerboard (6 LEDs of each color arranged in a checkerboard pattern)
// 3 = Teeces V3.2 PSI by John V (13 LEDs of each color, arranged side by side)
// 4 = Teeces V3.2 PSI checkerboard by John V  (13 LEDs of each color, in a checkerboard pattern)
#define PSItype 4
// Wipe speed of PSI's
int wipe = 70;

//#define TESTLOGICS //turns on all logic LEDs at once, useful for troubleshooting

//#define FLDx4 //for an R7 dome with 4 FLDs (if you have 4 FLDs then delete the first // )

// Most builders shouldn't have to edit anything below here. Enjoy!
// =======================================================================================
///////include libs and declare variables////////////////////////////
int scrollPositions[]={
  9,9,27};
long previousMillis[3];
long scrollSpeed = 48;
long scrollCount[4];
#include <LedControl.h>
#include <Wire.h> //used to support I2C
//#include <Servo.h>
struct RECEIVE_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to receive
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO

  B00000100 };

//Blank Symbol
int cb[] PROGMEM = { 
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000 };  

//upSymbol
int cu[] PROGMEM = { 
  B00000001,
  B00000010,
  B00000100,
  B00001000,
  B00010000 }; 

//down Symbol
int cn[] PROGMEM = { 
  B00010000,
  B00001000,
  B00000100,
  B00000010,
  B00000001 }; 

//Dot Symbol
int cdot[] PROGMEM = { 
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000100 };  

//////////////////////////////////////////////////////////////////
// retrieve latin alphabet letter from progam memory
void getLatinLetter(int* letterbitmap, char let)
{
  // pLetter will be a pointer to program memory
  int* pLetter;

  // get pointer to program memory from character
  switch (let)
  {
  case 'A': 
    pLetter=cA; 
    break;
  case 'B': 
    pLetter=cB; 
    break;
  case 'C': 
    pLetter=cC; 
    break;
  case 'D': 
    pLetter=cD; 
    break;
  case 'E': 
    pLetter=cE; 
    break;
  case 'F': 
    pLetter=cF; 
    break;
  case 'G': 
    pLetter=cG; 
    break;
  case 'H': 
    pLetter=cH; 
    break;
  case 'I': 
    pLetter=cI; 
    break;
  case 'J': 
    pLetter=cJ; 
    break;
  case 'K': 
    pLetter=cK; 
    break;
  case 'L': 
    pLetter=cL; 
    break;
  case 'M': 
    pLetter=cM; 
    break;
  case 'N': 
    pLetter=cN; 
    break;
  case 'O': 
    pLetter=cO; 
    break;
  case 'P': 
    pLetter=cP; 
    break;
  case 'Q': 
    pLetter=cQ; 
    break;
  case 'R': 
    pLetter=cR; 
    break;
  case 'S': 
    pLetter=cS; 
    break;
  case 'T': 
    pLetter=cT; 
    break;
  case 'U': 
    pLetter=cU; 
    break;
  case 'V': 
    pLetter=cV; 
    break;
  case 'W': 
    pLetter=cW; 
    break;
  case 'X': 
    pLetter=cX; 
    break;
  case 'Y': 
    pLetter=cY; 
    break;
  case 'Z': 
    pLetter=cZ; 
    break;
    //non-letters
    //numbers
  case '0': 
    pLetter=c0; 
    break;
  case '1': 
    pLetter=c1; 
    break;
  case '2': 
    pLetter=c2; 
    break;
  case '3': 
    pLetter=c3; 
    break;
  case '4': 
    pLetter=c4; 
    break;
  case '5': 
    pLetter=c5; 
    break;
  case '6': 
    pLetter=c6; 
    break;
  case '7': 
    pLetter=c7; 
    break;
  case '8': 
    pLetter=c8; 
    break;
  case '9': 
    pLetter=c9; 
    break;
    //special characters
  case '*': 
    pLetter=ch; 
    break;
  case '#': 
    pLetter=ct; 
    break;
  case '@': 
    pLetter=cr; 
    break;
  case '-': 
    pLetter=cd; 
    break;
  case '|': 
    pLetter=cf; 
    break;
  case '.': 
    pLetter=cdot; 
    break;
    //whitespace
  case ' ': 
    pLetter=cb; 
    break;
  case '<': 
    pLetter=cu; 
    break;
  case '>': 
    pLetter=cn; 
    break;
  default : 
    pLetter=cb; 
    break;
    break;
  }

  // move data back from program memory to RAM
  for(byte i=0; i<5; i++)
  {
    letterbitmap[i]=(int)pgm_read_word(&(pLetter[i]));
  }
}

//////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////
// Draws in a letter on the LED grid     
// shift=0 draws starting from the left edge (column 0)
// shift>0 slide letter further towards the right
// shift<0 slide letter further towards the left (becomes only partly visible)
void drawLetter(byte display, char let, int shift)
{

  // return immediately if the letter won't show
  if(shift < -LETTERWIDTH ||  shift>27) return;

  // allocate RAM space for the bitmap
  int letterBitmap[5];
  getLatinLetter(letterBitmap, let);
  
  //loop thru rows of the letter
  // shift=0 draws starting from the left edge (column 0)
  // shift>0 slide letter further towards the right
  // shift<0 slide letter further towards the left (becomes only partly visible)
  for (byte i=0; i<5; i++) 
  {
    if (shift>0) //positive shift means letter is slid to the right on the display
      LEDgrid[display][i] |= ((long)letterBitmap[i]) << shift;
    else //negative shift means letter is slid to the left so that only part of it is visible
    LEDgrid[display][i] |= ((long)letterBitmap[i]) >> -shift;
  }
}

//////////////////////////////////////////////////////////////////////////////////////
// Scrolls the given text string on the given display
// Call repeatedly to keep the text scrolling.
// A scrolling count global tells you how many times the string has scrolled entirely
// There is no reset of the original position, should be accomplished elsewhere
// (9, 9 and 27 respectively)
void scrollText(byte display, char text[])
{
  static long previousTextScroll[3];

  // wait until next update cycle
  unsigned long currentMillis = millis();
  if((currentMillis - previousTextScroll[display]) < SCROLLspeed) return;
  previousTextScroll[display] = currentMillis;

  // LED grid to all off
  clearGrid(display);

  // draw all letters in the grid, scrolled according to the global scrollPosition[display]
  // each letter is moved 5 pixels from the next letter.
  // Positive scroll means moves towards the right
  // So scrollPosition should start at the last column and be decremented
  for (int i=0; i<strlen(text); i++)
  {
    int shift=i*LETTERWIDTH + scrollPositions[display];
    //if(shift > -(LETTERWIDTH+1) &&  shift<28)
    {
      drawLetter(display, text[i], shift);
    }
  }

  // this moves the text one step to the left, it will eventually become negative
  // and some text will start to disappear
  scrollPositions[display]--;

  // if the whole text is off screen to the left
  if (scrollPositions[display] < -LETTERWIDTH*(int)strlen(text))
  {
    // resets the scroll to just off screen to the right
    if (display==2) scrollPositions[display]=27;
    else scrollPositions[display]=9;

    // increment global scroll count
    // Right now this is used once at startup to stop calling this in the loop 
    // once the startup text has scrolled once
    // warning there is no reset to this
    textScrollCount[display]++;
  }

  // show text on logics
  showGrid(display);
}
//////////////////////////////////////////////////
///HP flicker
void hpFlicker()
{
  static unsigned long swtchMillis = millis();
  unsigned long currentMillis = millis();
  static long flick = 100;
  if(currentMillis - swtchMillis > flick) {
    // save the last time you blinked the LED 
    swtchMillis = currentMillis;   

    analogWrite(hpPin, random(255));
    flick = random(100);
  }
}
///////////////////////////////////////////////////////////////////
void autoHP()
{
  if (hpY!=150&&hpY!=30&&hpX!=150&&hpX!=30&&displayEffect!=5)
  {  
    unsigned long currentMillis = millis();
    if (currentMillis - HpMillis > twitch){
      hpY=random(31,150);
      hpX=random(31,150);
      HpMillis = currentMillis;
