 
 void sendEnergy() {
   if(SERIAL_DEBUG) Serial.println("send energy");
-  char c = ENERGY;
-  for (int i=0; i<NUM_CONN; i++) bus[i]->write(c);
+  // source sends energy, as 0, meaning 0 distance to source
+  char distance = 0;
+  for (int i=0; i<NUM_CONN; i++) bus[i]->write(distance);
   addTimer(100, sendEnergy);
 }
 


#define SERIAL_DEBUG true

#define ENERGY 0
#define DROPPING_CONNECTOR 254
#define ALERT 255


  // send out message that we're going to drop a connector
  char c = DROPPING_CONNECTOR;
  for (int i=0; i<NUM_CONN; i++) bus[i]->write(c);

  // pick random connected connector to drop
  // count number of ports with a low distance to source
  int n = 0;
  for (int i=0; i<NUM_CONN; i++) if (distanceToSource[i]<99) n++;
  n = random(1,n+1);
  int i=0;
  // go through ports, only count connecteds ports, untill random number is empty
  while(n) {
    if(distanceToSource[i]<99) n--;
    i++;
  }

  // give communication a break and drop connector
  delay(10);
  digitalWrite(coil[i-1], LOW);
  addTimer(1000, resetConnectors);

  // relax alert state
  alertState = false;
}

// ToDo: why not call this on a fixed interval?
void processEnergy() {
  // assess energy supply, find shortest disance to source
  shortestDistanceToSource = 99;
  for (int i =0; i<NUM_CONN; i++) if (distanceToSource[i] < shortestDistanceToSource) shortestDistanceToSource = distanceToSource[i];

  // if we have energy, switch (or keep) lamp on, pass it on and check again in some time
  if (shortestDistanceToSource<99) {
    if (!lampState) switchLampOn();
    // send shortest distance to ports with a higher distance
    for (int i =0; i<NUM_CONN; i++) if (distanceToSource[i] > shortestDistanceToSource) bus[i]->write(shortestDistanceToSource);
    addTimer(100, processEnergy);
  }
