PaulS:
So, you have some expectations. You have some code that does something. What it does isn't exactly clear. What is clear is that what it does isn't in line with your expectations.So, I'll ask again. Where are your debug statements? Where is your debug output?
Here's the code (written a bit differently) but with the debugging statements. This only prints to console once and doesn't send any UDP packets. After printing once to the console it kinda exits the loop (!):
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <MuxShield.h>
int IO1DigitalVals[16];
int IO2DigitalVals[16];
int IO3DigitalVals[16];
byte valueInBytes[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);
for (int i=0; i<16; i++) {
IO1DigitalVals[i] = 1;
IO2DigitalVals[i] = 1;
IO3DigitalVals[i] = 1;
}
Serial.begin(9600);
}
void loop() {
int evt;
evt = 0;
for (int i=0; i < 16; i++) {
//Digital read on all 16 inputs on IO1, IO2, and IO3
int v1 = muxShield.digitalReadMS(1, i);
int v2 = muxShield.digitalReadMS(2, i);
int v3 = muxShield.digitalReadMS(3, i);
if ((v1 != IO1DigitalVals[i]) || (v2 != IO2DigitalVals[i]) || (v3 != IO3DigitalVals[i])) {
IO1DigitalVals[i] = v1;
IO2DigitalVals[i] = v2;
IO3DigitalVals[i] = v3;
evt = 1;
}
}
if (evt) {
for(int i=0;i<16;i++) {
valueInBytes[i] = (char) IO1DigitalVals[i];
if (IO1DigitalVals[i] == 0) {
Serial.print("port 1 \n");
}
if (IO2DigitalVals[i] == 0) {
Serial.print("port 2 \n");
}
if (IO3DigitalVals[i] == 0) {
Serial.print("port 3 \n");
}
}
Udp.beginPacket(receiverIP, receiverPort); //start udp packet
Udp.write(valueInBytes, 16); //write sensor data to udp packet
Udp.endPacket(); // end packet
}
}