Arduino I2C Slave

Hi,
I trying to connect 2 Arduino via I2C. I’m wondering if this code is correct for the slave device. (For the master device, I using Arduino/Labview) :

I would like to dim light pin 9 on the Arduino slave from Labview. Is that code ok? Thank you

Arduio slave code:

#include <Wire.h>

byte IWire1 =0;
int OLight1= 9;

void setup()
{
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  pinMode(OLight1, OUTPUT); 
 
}

void loop()
{
  delay(100);
}

void receiveEvent(int howMany)
{
 IWire1 = Wire.read(); 
 analogWrite(OLight1, IWire1); 
    
   
}

Ok, I change it and it works now. The light brightess change from low to high in a good flow except that from 240 to 255, it increases significantly. I don’t know why?

Arduino code:

#include <Wire.h>
 
 
byte IWire1 =0;
int OLight1= 9;
 
 
void setup()
{
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  pinMode(OLight1, OUTPUT);
 
}
 
 
void loop()
{
  analogWrite(OLight1, IWire1);
}
 
 
 
void receiveEvent(int howMany)
 
{
 
 
IWire1 = Wire.read();
 
}