OK, sorry guys I just thought trying to keep it what I thought was simple would help, but clearly not 
- Below are the two sets of code
- The two Atmega328P's are on a PCB I have made so not an Arduino as such.
- The I2C lines are PCB tracks (not wires)
- I did forget the pullup resistors on the PCB but I have soldered some on and it makes no difference.
The problem is as I push the button the lights come on but quite often the light attached to the second chip lights up intermittently.
I will try and get the circuit on here ASAP if needed hope this helps you help me quickly.
P.S. The reason I asked for an alternative library is I had read quite a few posts about the wire library locking up.
Sender Code
#include "RunningAverage.h"
#include <Wire.h>
#define Switch 8
#define RedLed 10
#define GreenLed 9
#define Red 0
#define Yellow 60
#define Green 120
#define Cyan 180
#define Blue 240
#define Magenta 300
int Colours[6] = {Red,Yellow,Green,Cyan,Blue,Magenta};
double hue, saturation, lighting, value;
int R_1 = 3; // LED connected to digital pin 9
int G_1 = 5; // LED connected to digital pin 9
int B_1 = 6; // LED connected to digital pin 9
int i = 0;
int fadedwn=255;
int ThisColour;
unsigned int level[7];
int R=0,G=0,B=0;
byte rgb1[3];
byte rgb2[3];
float h_1,s_1,i_1;
float h_2,s_2,i_2;
void RGB1DWN(int fade_time);
void RGB2DWN(int fade_time);
void ResetMEQU7(void);
void hsi2rgb1(float H, float S, float I);
void hsi2rgb1(float H, float S, float I);
RunningAverage level0(17);
RunningAverage level1(17);
RunningAverage level2(17);
RunningAverage level3(17);
RunningAverage level4(17);
RunningAverage level5(17);
RunningAverage level6(17);
void setup()
{
Serial.begin(115200);
Wire.begin();
Wire.setWireTimeout(3000,true);
analogReference(DEFAULT);
level0.clear();
level1.clear();
level2.clear();
level3.clear();
level4.clear();
level5.clear();
level6.clear();
pinMode(A0,INPUT);
pinMode(A1,OUTPUT);
pinMode(A2,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(R_1,OUTPUT);
pinMode(G_1,OUTPUT);
pinMode(B_1,OUTPUT);
pinMode(Switch,INPUT_PULLUP);
pinMode(13,OUTPUT);
ResetMEQU7();
randomSeed(analogRead(0));
i_1 = 1;
i_2 = 1;
ThisColour = Colours[random(5)];
}
void loop()
{
int R=0,G=0,B=0;
unsigned int Level1;
h_1=180;
s_1=1;
i_1=2;
h_2=180;
s_2=1;
i_2=2;
Serial.println(fadedwn);
if(digitalRead(Switch)==0){
fadedwn=255;
i_1 = 1;
i_2 = 1;
analogWrite(GreenLed,fadedwn);
analogWrite(RedLed,fadedwn);
hsi2rgb1(ThisColour,s_1,i_1);
hsi2rgb2(ThisColour,s_2,i_2);
delay(5);
} else {
ThisColour = Colours[random(5)];
if(fadedwn<20) {
fadedwn=0;
} else {
fadedwn-=20;
}
RGB1DWN(2);
RGB2DWN(2);
analogWrite(GreenLed,fadedwn);
analogWrite(RedLed,fadedwn);
}
}
void RGB1DWN(int fade_time){
i_1=i_1-0.15;
if(i_1>1 || i_1<0){
i_1=0;
}
hsi2rgb1(h_1,s_1,i_1);
delay(fade_time);
}
void RGB2DWN(int fade_time){
i_2=i_2-0.15;
if(i_2>1 || i_2<0){
i_2=0;
}
hsi2rgb2(h_2,s_2,i_2);
//Done via slave
delay(fade_time);
}
void ResetMEQU7(void){
digitalWrite(A1,LOW);
digitalWrite(A2,LOW);
delay(1);
// Reset the MSGEQ7 as per the datasheet timing diagram
digitalWrite(A1,HIGH);
delay(1);
digitalWrite(A1,LOW);
digitalWrite(A2,HIGH);
delay(1);
}
void hsi2rgb1(float H, float S, float I) {
int r,g,b;
H = fmod(H,360); // cycle H around to 0-360 degrees
H = 3.14159*H/(float)180; // Convert to radians.
S = S>0?(S<1?S:1):0; // clamp S and I to interval [0,1]
I = I>0?(I<1?I:1):0;
// Math! Thanks in part to Kyle Miller.
if(H < 2.09439) {
r = 255*I/3*(1+S*cos(H)/cos(1.047196667-H));
g = 255*I/3*(1+S*(1-cos(H)/cos(1.047196667-H)));
b = 255*I/3*(1-S);
} else if(H < 4.188787) {
H = H - 2.09439;
g = 255*I/3*(1+S*cos(H)/cos(1.047196667-H));
b = 255*I/3*(1+S*(1-cos(H)/cos(1.047196667-H)));
r = 255*I/3*(1-S);
} else {
H = H - 4.188787;
b = 255*I/3*(1+S*cos(H)/cos(1.047196667-H));
r = 255*I/3*(1+S*(1-cos(H)/cos(1.047196667-H)));
g = 255*I/3*(1-S);
}
rgb1[0]=r;
rgb1[1]=g;
rgb1[2]=b;
analogWrite(R_1, rgb1[0]);
analogWrite(G_1, rgb1[1]);
analogWrite(B_1, rgb1[2]);
}
void hsi2rgb2(float H, float S, float I) {
int r,g,b;
H = fmod(H,360); // cycle H around to 0-360 degrees
H = 3.14159*H/(float)180; // Convert to radians.
S = S>0?(S<1?S:1):0; // clamp S and I to interval [0,1]
I = I>0?(I<1?I:1):0;
// Math! Thanks in part to Kyle Miller.
if(H < 2.09439) {
r = 255*I/3*(1+S*cos(H)/cos(1.047196667-H));
g = 255*I/3*(1+S*(1-cos(H)/cos(1.047196667-H)));
b = 255*I/3*(1-S);
} else if(H < 4.188787) {
H = H - 2.09439;
g = 255*I/3*(1+S*cos(H)/cos(1.047196667-H));
b = 255*I/3*(1+S*(1-cos(H)/cos(1.047196667-H)));
r = 255*I/3*(1-S);
} else {
H = H - 4.188787;
b = 255*I/3*(1+S*cos(H)/cos(1.047196667-H));
r = 255*I/3*(1+S*(1-cos(H)/cos(1.047196667-H)));
g = 255*I/3*(1-S);
}
rgb2[0]=r;
rgb2[1]=g;
rgb2[2]=b;
Wire.beginTransmission(8);
Wire.write(r);
Wire.write(g);
Wire.write(b);
Wire.endTransmission();
}
Receiver code
#include <Wire.h>
int R = 3; // LED connected to digital pin 9
int G = 5; // LED connected to digital pin 9
int B = 6;
int RR,GG,BB;
void setup() {
Wire.begin(8);
Wire.setWireTimeout(3000,true);
Wire.onReceive(ReceiveEvent);
pinMode(R,OUTPUT);
pinMode(G,OUTPUT);
pinMode(B,OUTPUT);
}
void loop() {
analogWrite(R, RR);
analogWrite(G, GG);
analogWrite(B, BB);
}
void ReceiveEvent() {
RR = Wire.read();
GG = Wire.read(); // receive a byte as character
BB = Wire.read(); // receive a byte as character
}