Section 4: Flight-Control-Functions.

........ Scanner i2c Devices Source Code .........

============ File-Name: 3_I2C_Scan.ino ============


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++ Begin I2C Devices Scan ++++++++++++++++++++
//                  Last Update: 9-1-2021  
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

void Scan_4_I2C_Devices()
 {
  byte error, address; 
//  int nDevices = 0;       
//  Serial.println("Scanning for I2C addresses");   

  for(address = 1; address < 127; address++ ) 
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    I2C.beginTransmission(address);
    error = I2C.endTransmission();

    if (error == 0)
    {
 //     Serial.print("I2C device found at address 0x");  
      if (address<16)
        { 
  //      Serial.print("0");       
  //    Serial.print(address,HEX); 
  //    Serial.println("  !");     
        }
        
      nDevices++;
    }
    else if (error==4) 
    {
//      Serial.print("Unknow error at address 0x"); 
      if (address<16) 
        { 
 //       Serial.print("0");                
 //     Serial.println(address,HEX);        
        }
    }  
  }

//       pwm.setPWM(PCApin[0], 0, 4096);  //Switch-off Green LED on pin 0
  
  if (nDevices >= 4)
     {
//       Serial.println("I2C check done, ALL I2C devices found.\n");  mmmmmm
//     Switch-OFF the Green control LED on Pin 0
       pwm.setPWM(PCApin[0],  0, 4096);  //OFF 
       delay(60);
//     Switch-ON the Green control LED on Pin 0
       pwm.setPWM(PCApin[0], 4096, 0);  //ON   
     }
   else
     {  
       Serial.println("I2C check done, NOT ALL I2C devices found\n"); //  mmmmm
//     Switch-OFF the RED control LED on Pin 11
       pwm.setPWM(PCApin[11],  0, 4096); //OFF
       delay(60);
//     Switch-ON the RED control LED on Pin 11
       pwm.setPWM(PCApin[11], 4096, 0);  //ON
       delay(100000);
     } 
 }

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++ End I2C Devices Scan +++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Free-Drones Company 2022