示例#1
0
int robot_begin()
{
  int ret = SUCCESS;
  int ivalue = 0;
  
  ret = motor_begin(); 
  if (ret != SUCCESS) return ret;

  Serial.println("Begin Robot Init");
  Serial.println("****************");
  
  lcd.clear();
  lcd.print("Begin Robot Init");
   
  pinMode(Led_Green, OUTPUT);      // set the pin as output
  blink(Led_Green); 
  pinMode(Led_Red, OUTPUT);      // set the pin as output
  blink(Led_Red);  
  pinMode(Led_Blue, OUTPUT);     // set the pin as output
  blink(Led_Blue);
  Serial.println("Init Leds OK");
    
  // initialize the buzzer
  pinMode(buzzPin, OUTPUT); 
  buzz(3);       
  Serial.println("Init Buzzer OK");
   
  // initialize the Tilt&Pan servos  
  TiltPan_begin(HSERVO_Pin, VSERVO_Pin);
  Serial.println("Init Tilt&Pan servos OK");

  // initialize the camera
  Serial.println(" ");
  Serial.println("Begin Init Camera...");
  ret=JPEGCamera.begin();
  if (ret != SUCCESS)
  {  
        Serial.print("Error Init Camera, error: ");
        Serial.println(ret);
        lcd.setCursor(0,1); 
        lcd.print("Init Camera KO  ");
  }        
  else
  {
        Serial.println("Init Camera OK");
        lcd.setCursor(0,1); 
        lcd.print("Init Camera OK  ");
  } 
  delay(5*1000);lcd.clear();    
  
  // initialize the SD-Card    
  ret = initSDCard();
  if (ret != SUCCESS)
  {  
        Serial.print("Error Init SD-Card, error: ");
        Serial.println(ret);
        lcd.print("Init SD-Card KO ");
  }                                                                    
  else
  {
        Serial.println("Init SD-Card OK");
        lcd.print("Init SD-Card OK ");
  }
    
  // get infos from SD-Card  
  ret=infoSDCard();
  if (ret < 0)
  {  
        Serial.print("Error Infos SD-Card, error: ");
        Serial.println(ret);
        lcd.setCursor(0,1); 
        lcd.print("Err Infos SDCard");
  }
  else
  {
        no_picture = ret+1;
        Serial.print("no_picture starts at: ");
        Serial.println(no_picture);
        lcd.setCursor(0,1); 
        lcd.print("Num picture:");lcd.print(no_picture);
  }   
  delay(5*1000);lcd.clear();  
    
    
  // initialize the brightness sensor   
  TEMT6000.TEMT6000_init(TEMT6000_Pin); // initialize the pin connected to the sensor
  Serial.println("Init Brightness sensor OK");
  
  ivalue = TEMT6000.TEMT6000_getLight();
  Serial.print("Value between 0 (dark) and 1023 (bright): ");
  Serial.println(ivalue); 
  lcd.print("Lux:");lcd.print(ivalue);lcd.printByte(lcd_pipe);
  
  // initialize the temperature sensor   
  TMP102.TMP102_init();
  Serial.println("Init Temperature sensor OK");
  
  double temperature = TMP102.TMP102_read();
  ivalue = (int)(100.0 * temperature);
  Serial.print("Temperature: ");
  Serial.println(ivalue); 
  lcd.print("T:");lcd.print(ivalue);lcd.printByte(lcd_celcius);lcd.printByte(lcd_pipe);   
  
  // initialize the electret micro   
  //Micro.Micro_init(MICRO_Pin); // initialize the pin connected to the micro
  //Serial.println("Init Micro OK");

  // initialize the motion sensor
  pinMode(MOTION_PIN, INPUT);
  Serial.println("Init Motion sensor OK");

  // initialize the IOT Serial 1 
  IOTSerial.IOTSbegin(1); // initialize the IOT Serial 1 to communicate with IOT WIFClient ESP8266
  Serial.println ("Init IOT Serial 1 to communicate with IOT WIFClient ESP8266 OK");
  
  // initialize the IOT Serial 2, interrupt setting
  IOTSerial.IOTSbegin(2); // initialize the IOT Serial 2 to communicate with IOT WIFServer ESP8266
  Serial.println ("Init IOT Serial 2 to communicate with IOT WIFServer ESP8266 OK");
  pinMode(IOT_PIN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(IOT_PIN), IntrIOT, RISING);         // set IOT interrupt
 
  interrupts(); // enable all interrupts
  Serial.print("Init Interrupts OK, IntIOT: "); Serial.println(IntIOT);
  
  lcd.setCursor(0,1); 
  lcd.print("End   Robot Init");
  delay(5*1000);lcd.clear();  
 
  Serial.println("End Robot Init");
  Serial.println("**************");
  Serial.println("");
 
  return SUCCESS;
  
}