   Serial.println(msg);
 }
 
+bool redFlyTimeout(int ms)
+{
+  int j;
+  for(j=0;!Serial1.available() && j<ms; j++) delay(1);
+  if(j==ms) return false;
+  else      return true;
+}
+
+void redFlyFlush()
+{
+  while (Serial1.available()) 
+  {
+    Serial1.read();
+    if(!Serial1.available()) delay(3);
+  }
+}
+
 bool redFlyInit()
 {
   pinMode(redFlyReset,OUTPUT);
 
   digitalWrite(redFlyReset,LOW);
-  delay(400);
+  delay(50);
   digitalWrite(redFlyReset,HIGH);
-  delay(300);
+  delay(110);
   
   Serial1.begin(9600);
   

  int i=0;
  for (; i<size && Serial1.available(); i++) {
    response[i]=Serial1.read();
    if(!Serial1.available()) delay(3);
  }
  response[i]=0;
  digitalWrite(BLUE_LED,LOW);  
  redFlyFlush();

  if(response[0]=='O') return true;  // OK
  else                 return false;   // ERROR or something
}

bool redFlyCommandRequired(const char* cmd)
{
  char response[64];
  
  if(!redFlyCommand(cmd,response,64))
  {
    Serial.print("RedFly Error at: ");
    Serial.println(cmd);
    Serial.println(response);
    
    return false;
  }
  return true;
}

bool redFlySend(const char* cmd)
{
  char response[2];  
  redFlyCommand(cmd,response,2);
}



// initialize the library with the numbers of the interface pins



  Serial.begin(9600);

  lcd.home();
  lcd.println("INIT");
