If-Else Conditioning

Hi! I am working on top of the masterWriter() code, tweaking things a bit. The code below shows the results I wanted whenever the sound sensor is triggered. This is from the slave board:

#include <Wire.h>

void setup()
{
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output

}

int threshold = 100;

void loop()
{
  delay(500);
}


void receiveEvent(int howMany)
{
  while(1 < Wire.available()) // loop through all but the last
  {
    char a = Wire.read();
    Serial.print(a);
      }
  
  int x = Wire.read();   
  Serial.println(x);       

}

However, when I incorporate the changes such as sound sensitive lights with if-else statements, the data being received becomes a constant (-1).

#include <Wire.h>

void setup()
{
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);

}

int threshold = 100;

void loop()
{
  delay(500);
}


void receiveEvent(int howMany)
{
  while(1 < Wire.available()) // loop through all but the last
  {
     int c = Wire.read(); 
      if (c >= threshold) {
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(9, HIGH);
 
  }
  else {
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
  }
      }
  
  //int x = Wire.read();   
  //Serial.println(x);       

}

Hope someone can help. Thanks!

You commented out the Wire.read()

Also why delay(500); in the loop? It serving no purpose

Also why delay(500); in the loop? It serving no purpose

aarg:
You commented out the Wire.read()

There are two Wire.read(). I have placed in the comments the last one as it is the same with the first.

The first example receives pairs of data, a and x. The second only receives individual data. Why? If the data stream contains pairs you have to read pairs.