Problem: UDP Wraped with If Statement

UKHeliBob:
What do you mean by 'stops working' ?
What do you see if you print the value of e just after the test of the value of v1 inside the for loop, and before the if after the for loop ?

Note that e will always be 1 if the 16th reading of v1 is zero no matter what the previous 15 readings were. Is that what you intended ?

The sensors are infrared sensors. It works once and after it goes through the loop it stops working!

Take a look at the following code. It's more readable:

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <MuxShield.h>

int IO1DigitalValues[16];
int IO2DigitalValues[16];
int IO3DigitalValues[16];

byte dataBuff[16];

//Initialize the Mux Shield
MuxShield muxShield;

byte arduinoMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress arduinoIP(192, 168, 1, 192);  // desired IP for Arduino
unsigned int arduinoPort = 8888;        // port of Arduino

IPAddress receiverIP(192, 168, 1, 135); // IP of udp packets receiver
unsigned int receiverPort = 6000;       // port to listen on my PC

EthernetUDP Udp;

void setup() {
  Ethernet.begin(arduinoMac,arduinoIP);
  Udp.begin(arduinoPort);

  muxShield.setMode(1,DIGITAL_IN_PULLUP);  //use DIGITAL_IN in place of DIGITAL_IN_PULLUP if internal pullups are not needed
  muxShield.setMode(2,DIGITAL_IN_PULLUP);
  muxShield.setMode(3,DIGITAL_IN_PULLUP);

  memset(IO1DigitalValues, 0, sizeof(IO1DigitalValues));
  memset(IO2DigitalValues, 0, sizeof(IO2DigitalValues));
  memset(IO3DigitalValues, 0, sizeof(IO3DigitalValues));

  Serial.begin(9600);
}

void loop() {
  int dataChanged = readData();
  if (dataChanged) {
    ProcessData();
  }
}

int readData() {
  int dataChanged = 0;
  for (int i=0; i < 16; i++) {
    int v1 = muxShield.digitalReadMS(1, i);
    int v2 = muxShield.digitalReadMS(2, i);
    int v3 = muxShield.digitalReadMS(3, i);

    if ( (v1 != IO1DigitalValues[i]) || (v2 != IO2DigitalValues[i]) || (v3 != IO3DigitalValues[i]) ) {
     dataChanged = 1;

     IO1DigitalValues[i] = v1;
     IO2DigitalValues[i] = v2;
     IO3DigitalValues[i] = v3;
    }
  }
  return dataChanged;
}

void ProcessData() {
  for(int i=0; i<16; i++) {
    dataBuff[i] = (char) IO1DigitalValues[i];
  }

  Udp.beginPacket(receiverIP, receiverPort);
  Udp.write(dataBuff, sizeof(dataBuff));
  Udp.endPacket();
}