       // Print pin value after assigment
 //            Serial.println("Pin Data: ");
       //      char sPinState[128];
-  //    snprintf(sPinState, sizeof(sPinState), "%s,%i,%i,%f", g_aPins[i].label, g_aPins[i].is_analog, g_aPins[i].is_input, g_aPins[i].value);
-  //    Serial.println(sPinState);
+   //   snprintf(sPinState, sizeof(sPinState), "%s,%i,%i,%f", g_aPins[i].label, g_aPins[i].is_analog, g_aPins[i].is_input, g_aPins[i].value);
+    //  Serial.println(sPinState);
 
     }    
   }

    memset(g_aPins[i].connections, '\0', sizeof(g_aPins[i].connections));
    for(int j=0; j<TOTAL_NUM_OF_PINS; j++)
    {
      g_aPins[i].connections[j] = false;
    }
  }



void updateBoardState()
{
  // Update input pins first
  for(int i=0; i<TOTAL_NUM_OF_PINS; i++)
  {
    if( g_aPins[i].is_input ) // Process input pins
    {
      if( g_aPins[i].is_analog ) // Process analog pins
      {
        g_aPins[i].value = analogRead(i)/float(ANALOG_IN_MAX_VALUE);
      }
      else // Process digital pins
      {
        g_aPins[i].value = digitalRead(i);
      }
    }
  }

  // Update outputs pins
  for(int i=0; i<TOTAL_NUM_OF_PINS; i++)
  {
    if( !g_aPins[i].is_input ) // Process output pins
    {
       //Serial.println("HERE");
//       Serial.print("Is Analog: ");Serial.println(g_aPins[i].is_analog);
      if( g_aPins[i].is_analog ) // Process analog pins
      {
        //analogWrite(i, int(g_aPins[i].value*ANALOG_OUT_MAX_VALUE) );
  //      Serial.print("Analog Pin "); Serial.print(i); Serial.print(": ");Serial.println(getTotalPinAnalogValue(i));
        analogWrite(i, getTotalPinAnalogValue(i)*ANALOG_OUT_MAX_VALUE );
      }
      else // Process digital pins
      {
        //digitalWrite(i, int(g_aPins[i].value) );
  //      Serial.print("Digital Pin "); Serial.print(i); Serial.print(": ");Serial.println(getTotalPinDigitalValue(i));        
        digitalWrite(i, getTotalPinDigitalValue(i) );
      }
    }
  }
}

float getTotalPinAnalogValue(int _iPinNum)
{
  float fPinValSum = 0;
  
  for(int i=0; i<TOTAL_NUM_OF_PINS; i++)
  {
    // Checking what pins are connected to iPinNum
    if(g_aPins[_iPinNum].connections[i])
    {
      fPinValSum += g_aPins[i].value;  
      Serial.print(i); Serial.print(" --> "); Serial.println(_iPinNum);
      Serial.print("Value: "); Serial.println(fPinValSum);
    }    
  }
  
  if(fPinValSum > 1.0)
    fPinValSum = 1.0;
  
  return fPinValSum;
}

int getTotalPinDigitalValue(int _iPinNum)
{ 
  for(int i=0; i<TOTAL_NUM_OF_PINS; i++)
  {
    // Checking what pins are connected to iPinNum
    if(g_aPins[_iPinNum].connections[i])
    {
      if(g_aPins[i].value == 1.0)
        return 1.0;
    }    
  }
  
  return 0.0;
}

// Get the board state and return a JSON object
aJsonObject* getJsonBoardState()
