// RHYME AND REASON SLAVE3 RECEIVES COMMANDS THRU I2C FROM RECEIVER
// BASED ON COMMAND RECEIVED FROM CONTROLLER
// THIS CONTROLS THE RGB LED's ON BOTTOM CIRCLE OF R&R

// INCLUDE LIBRARIES
#include "SPI.h"
#include "Adafruit_WS2801.h"
#include <Wire.h>

// DECLARE VARIABLES
int dataPin = 2;
int clockPin = 3;
byte dataByte = 0;

Adafruit_WS2801 strip = Adafruit_WS2801(64, dataPin, clockPin);

//VOIDSETUPVOIDSETUPVOIDSETUPVOIDSETUPVOIDSETUPVOIDSETUPVOIDSETUPVOIDSETUPVOIDSETUPVOIDSETUPVOIDSETUPVOIDSETUPVOIDSETUPVOIDSETUPVOIDSETUPVOIDSETUP
void setup()
{
  // SET UP RGB LED STRIP
  strip.begin();
  // MAKE SURE ALL LED's ARE OFF AT POWER UP
  strip.show();
  // SET UP SERIAL TRANSMISSION
  Serial.begin(9600);
  Wire.begin(6);
}
//VOIDLOOPVOIDLOOPVOIDLOODVOIDLOOPVOIDLOOPVOIDLOOPVOIDLOOPVOIDLOOPVOIDLOOPVOIDLOOPVOIDLOOPVOIDLOODVOIDLOOPVOIDLOOPVOIDLOOPVOIDLOOPVOIDLOOPVOIDLOOP
void loop()
{
  Wire.onReceive(receiveEvent);
  delay(100);
  Wire.endTransmission();
  //////////SWITCH STATEMENTS//////////
  /////////////////////////////////////
  switch(dataByte){
    //////////R&R RED ON (BOTTOM HALF OF CIRCLE)//////////
    ///////////////////////////////////////////////////
    case 'J':
    
    setcolor(Color(250,0,0),50);
    delay(100);
    break;
    //////////R&R RED OFF (BOTTOM HALF OF CIRCLE)//////////
    ////////////////////////////////////////////////////
    case 'j':
    
    setcolor(Color(0,0,0),50);
    delay(100);
    break;
    //////////R&R GREEN ON (BOTTOM HALF OF CIRCLE)//////////
    /////////////////////////////////////////////////////
    case 'K':
    
    setcolor(Color(0,250,0),50);
    delay(100);
    break;
    //////////R&R GREEN OFF (TOP HALF OF CIRCLE)//////////
    //////////////////////////////////////////////////////
    case 'k':
    
    setcolor(Color(0,0,0),50);
    delay(100);
    break;
    //////////R&R BLUE ON (BOTTOM HALF OF CIRCLE)////////////
    //////////////////////////////////////////////////////
    case 'L':
    
    setcolor(Color(0,0,250),50);
    delay(100);
    break;
    //////////R&R BLUE OFF (BOTTOM HALF OF CIRCLE)////////////
    ///////////////////////////////////////////////////////
    case 'l':
    
    setcolor(Color(0,0,0),50);
    delay(100);
    break;
  }
}//END LOOP*************************************************
////////////////////////////////////////////////////////////
//**************************************************************************************
//FUNCTIONSFUNCTIONSFUNCTIONSFUNCTIONSFUNCTIONSFUNCTIONSFUNCTIONSFUNCTIONSFUNCTIONSFUNCTIONSFUNCTIONSFUNCTIONSFUNCTIONSFUNCTIONSFUNCTIONSFUNCTIONS

// FUNCTION THAT EXECUTES WHENEVER DATA IS RECEIVED FROM MASTER
// THIS FUNCTION IS REGISTERED AS AN EVENT SEE setup()
void receiveEvent(int howMany)
{
  if(Wire.available())
  {
    dataByte = Wire.read();
  }
}
// SENDS COLOR COMMAND TO RGB LED STRIP
void setcolor(uint32_t c, uint8_t wait) {
  int i;
  
  for (i=0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
  }
  strip.show();
}
// CREATE A 24 BIT COLOR VALUE FROM R,G,B
uint32_t Color(byte r, byte g, byte b)
{
  uint32_t c;
  c = r;
  c <<= 8;
  c |= g;
  c <<= 8;
  c |= b;
  return c;
}