   strcpy(outputTopicBuff, outRelayTopic);
   char relaybuffer[5];
   sprintf(relaybuffer, "%d", relayNbr);
+  strcat(outputTopicBuff, relaybuffer);
+  client.publish(outputTopicBuff, state);
+}
+
+void publishPinState(int pinNbr, char* state) {
+  char outputTopicBuff[100];
+  strcpy(outputTopicBuff, outPinTopic);
+  char relaybuffer[5];
+  sprintf(relaybuffer, "%d", pinNbr);
   strcat(outputTopicBuff, relaybuffer);
   client.publish(outputTopicBuff, state);
 }

  22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53
};       // an array of pin numbers to which LEDs are attached
int pinCount = 32;

void setup_ethernet() {


  if (!client.connected()) {
    reconnect();
  }
  debounce1.update();
  if ( debounce1.fell() ) {
    publishPinState(1, "1");
  }
  if ( debounce1.rose() ) {
    publishPinState(1, "0");
  }
  debounce2.update();
  if ( debounce2.fell() ) {
    publishPinState(2, "1");
  }
  if ( debounce2.rose() ) {
    publishPinState(2, "0");
  }
  debounce3.update();
  if ( debounce3.fell() ) {
    publishPinState(3, "1");
  }
  if ( debounce3.rose() ) {
    publishPinState(3, "0");
  }
  debounce4.update();
  if ( debounce4.fell() ) {
    publishPinState(4, "1");
  }
  if ( debounce4.rose() ) {
    publishPinState(4, "0");
  }
  debounce5.update();
  if ( debounce5.fell() ) {
    publishPinState(5, "1");
  }
  if ( debounce5.rose() ) {
    publishPinState(5, "0");
  }
  debounce6.update();
  if ( debounce6.fell() ) {
    publishPinState(6, "1");
  }
  if ( debounce6.rose() ) {
    publishPinState(6, "0");
  }

  client.loop();
}

