function doTransmit(order, dimmer) {
  // lock sequence to begin signal emission
  wpi.digitalWrite(pin, wpi.HIGH);
  wpi.delayMicroseconds(275); 
  wpi.digitalWrite(pin, wpi.LOW);
  wpi.delayMicroseconds(9900);
  wpi.digitalWrite(pin, wpi.HIGH);
  wpi.delayMicroseconds(275);
  wpi.digitalWrite(pin, wpi.LOW);
  wpi.delayMicroseconds(2675);
  wpi.digitalWrite(pin, wpi.HIGH);
  // send order data
  for (var i = 0; i < order.length; i++) { 
    if (dimmer && i ==  27) { // send special bit
      sendDimmerBit();
      continue;
    }
//    console.log(i);
    sendPair(toBool(order.charAt(i)));
  }
  wpi.digitalWrite(pin, wpi.HIGH);
  wpi.delayMicroseconds(275);
  wpi.digitalWrite(pin, wpi.LOW);
  //console.log('transmit finished');
}
// Sends the DIMMER special bit
function sendDimmerBit() {
    wpi.digitalWrite(pin, wpi.HIGH);
    wpi.delayMicroseconds(310);
    wpi.digitalWrite(pin, wpi.LOW);
    wpi.delayMicroseconds(310);
    wpi.digitalWrite(pin, wpi.HIGH);
    wpi.delayMicroseconds(310);
    wpi.digitalWrite(pin, wpi.LOW);
    wpi.delayMicroseconds(310);
}
// Send pulse
function sendBit(bool) {
  if (bool) {
    wpi.digitalWrite(pin, wpi.HIGH);
    wpi.delayMicroseconds(310);
    wpi.digitalWrite(pin, wpi.LOW);
    wpi.delayMicroseconds(1340);
  }
  else {
    wpi.digitalWrite(pin, wpi.HIGH);
    wpi.delayMicroseconds(310);
    wpi.digitalWrite(pin, wpi.LOW);
    wpi.delayMicroseconds(310);
  }
}
// Transmit over the air the data
function transmit(order, dimmer) {
    // console.log('order : ' + order);
    for (var i = 0; i < 5; i++) {
      doTransmit(order, dimmer);
      wpi.delayMicroseconds(10);
  }
}