#define ledStartPin 2 #define totalPins 7 int pinState[totalPins]; void setup(){ initPins(); initSerial(); } void loop(){ sendSerialComm(); //send serial commands to reflect arduino states readSerialComm(); //recieve serial command from processing setPins(); //set the pin state base on the pinState array } //=================== void initSerial(){ Serial.begin(14400); } void initPins(){ //define pin states and array for pin state storage for (int i=ledStartPin; i 0) { // read the incoming byte: incomingByte = Serial.read(); // say what you got: // Serial.print("I received: "); // Serial.println(incomingByte); if ((incomingByte>47)&&(incomingByte<58)){//check if the incoming byte is (0-9, ASCII= 48-57) int switchPin=incomingByte-48; //parse ASCII to integer if ((switchPin>=ledStartPin)&&(switchPin<=ledStartPin+totalPins)){ pinState[switchPin-ledStartPin]*=-1; //toggle pin state } } Serial.flush(); } } void sendSerialComm(){ Serial.print("===================:"); for (int i=0; i