HOME NOW > ROBOLINK STORE NOW >
Arduino install & Run CoDrone Arduino Example

Windows : Recommended to install directly below the root directory.(Exam : D:RBCodrone)
MACOS : When you first run the package, we recommend 'Finder > Download > Right-click

You can check if a port is installed on the Device Manager > Ports (COM&LPT) tab
(MACOS : Available on the Practice arduino > Tool > Ports tab)

In case of problems with the download
You can download the USB driver directly through the website.

Subject Contents
[Library] CoDrone Library
[Pairing] 1) Pairing with the Nearest Drone (NearbyDrone)
2) Pairing with Recently Connected Drone (ConnectedDrone)
3) Pairing with CoDrone Address (AddressInputDrone)
4) Check CoDrone Address (PrintDroneAddress)
5) AutoConnect (AutoConnect)
[Control] 1) Take-off & Landing (TakeOff-Landing)
2) Ascending & Descending (ThrottleUp)
3) Forward & Backward (PitchUp)
4) Move Left & Right (RollUp)
5) Turn Counterclockwise & Clockwise (YawUp)
6) Turn Turtle (Turn_Over)
7) Flight Control (Controller_Flight)
8) Driving Control (Controller_drive)
9) Battle (Controller_Flight_Battle)
10) Halt Flight Controller (Controller_Flight_joyStop)
11) Move to the height entered (Go To Height)
12) Rotate to the entered angle (Turn Degree)
[LED Control] 1) LED Control 1 (LED_Color_01)
2) LED Control 2 (LED_Color_02)
3) LED Control 3 (LED_Color_03)
4) Set LED’s default value (LedColorDefault)
[Status Check] 1) Check Battery Level (LowBatteryCheck)
2) Check Drone’s Attitude (Serial Print Attitude)
3) RSSI - Received Signal Strength Indication (RSSI_Polling)
4) Indicate Altitude Value (DisplayLEDRangeSensor)
   : Only for CoDrone Pro
5) Indicate Altitude Value (SerialPrintRangeSensor)
   : Only for CoDrone Pro
[Application] 1) Sharp Return (V_Turn)
2) Turn in Circle (Circle_Turn)
3) Hop on the Palm (hand_on)
4) Jump-over the Obstacle (hurdle_jump)
5) Control with Analog Sensors (Analog_Control)
6) Control with Digital Sensor (Button_Control)

For a detailed description of the functions used in the example,
please see the Library landing page below.



#include <CoDrone.h>                     // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                    // Initiate communication of BLE Board (115200bps)

CoDrone.AutoConnect(NearbyDrone);   // Connect to the nearest drone

CoDrone.DroneModeChange(Flight);     // Set the drone into flight mode (Flight type drone)

if (PAIRING == true)                         // Run only when pairing succeeds
{
CoDrone.FlightEvent(TakeOff);             // Take-off
delay(2000);                                    // Waiting time
CoDrone.FlightEvent(Landing);             // Landing slowly
}
}

void loop()
{
}

#include <CoDrone.h>                            // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                           // Initiate communication of BLE Board (115200bps)

CoDrone.AutoConnect(ConnectedDrone);     // Connect to a drone with the same address of the latest drone connected before

CoDrone.DroneModeChange(Flight);           // Set the drone into flight mode (Flight type drone)

if (PAIRING == true)                                // Run only when pairing succeeds
{
CoDrone.FlightEvent(TakeOff);                    // Take-off
delay(2000);                                           // Waiting time
CoDrone.FlightEvent(Landing);                    // Landing slowly
}
}

void loop()
{
}

#include <CoDrone.h>                     // Header file for using CoDrone
void setup()
{
CoDrone.begin(115200);                    // Initiate communication of BLE Board (115200bps)

//CoDrone.PrintDroneAddress();           // Display the address of recently connected drone, on the serial monitor

byte droneAddress[6] = {0xFC, 0xA6, 0x61, 0x78, 0xD5, 0xA4};
// Enter address – check with PrintDroneAddress() command)

CoDrone.AutoConnect(AddressInputDrone, droneAddress); // Connect to a drone having same address entered above

CoDrone.DroneModeChange(Flight);     // Set the drone into flight mode (Flight type drone)

if (PAIRING == true) // Run only when pairing succeeds
{
CoDrone.lightEvent(TakeOff);              // Take-off
delay(2000);                                    // Waiting time
CoDrone.FlightEvent(Landing);             // Landing slowly
}
}

void loop()
{
}

#include <CoDrone.h>              // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);            // Initiate communication of BLE Board (115200bps)

CoDrone.PrintDroneAddress();     // Display the address of recently connected drone, on the serial monitor
}

void loop()
{
}

- Mixed connection mode NearbyDrone and ConnectedDrone
- At power-on, the connection mode is set by the switch Status

#include <CoDrone.h>                     // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                    // Initiate communication of BLE Board (115200bps)

CoDrone.AutoConnect();                    // AutoConnect drones according to Dip switch 3

CoDrone.DroneModeChange(Flight);     // Set the drone into flight mode (Flight type drone)

CoDrone.FlightEvent(TakeOff);             // Take-off
delay(2000);                                    // Waiting time
CoDrone.FlightEvent(Landing);             // Landing slowly
}

void loop()
{
}


#include <CoDrone.h>                      // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                     // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);    // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);      // Set drone into flight mode (Flight type drone)

if (PAIRING == true)                          // Run only when pairing succeeds
{
CoDrone.FlightEvent(TakeOff);              // Take-off

delay(2000);                                     // Waiting time

CoDrone.FlightEvent(Landing);              // Landing slowly
}
}

void loop()
{
}

#include <CoDrone.h>                     // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                    // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);   // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);     // Set drone into flight mode (Flight type drone)

if (PAIRING == true)                         // Run only when pairing succeeds
{
THROTTLE = 100                             // Enter THROTTLE value: 100=Ascend, -100=Descend
CoDrone.Control();                           // Send Control value

delay(2000);                                   // Waiting time

CoDrone.FlightEvent(Stop);                // Stop
}
}

void loop()
{
}

#include <CoDrone.h>                     // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                    // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);   // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);     // Set drone into flight mode (Flight type drone)

if (PAIRING == true)                         // Run only when pairing succeeds
{
CoDrone.FlightEvent(TakeOff);             // Take-off

delay(2000);                                    // Waiting time

PITCH = 100;                                  // Enter PITCH value
CoDrone.Control();                           // Send Control value

delay(500);                                     // Waiting time

CoDrone.FlightEvent(Landing);            // Landing slowly
}
}

void loop()
{
}

#include <CoDrone.h>                      // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                     // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);   // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);     // Set drone into flight mode (Flight type drone)

if (PAIRING == true)                          // Run only when pairing succeeds
{
CoDrone.FlightEvent(TakeOff);              // Take-off

delay(2000);                                     // Waiting time

ROLL = 100;                                    // Enter ROLL value
CoDrone.Control();                            // Send Control value
delay(1000);                                     // Waiting time

CoDrone.FlightEvent(Landing);             // Landing slowly
}
}

void loop()
{
}

#include <CoDrone.h>                     // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                    // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);   // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);     // Set drone into flight mode (Flight type drone)

if (PAIRING == true)                         // Run only when pairing succeeds
{
CoDrone.FlightEvent(TakeOff);             // Take-off

delay(2000);                                    // Waiting time

YAW = 100;                                    // Enter Yaw value
CoDrone.Control();                            // Send Control value

delay(1000);                                    // Waiting time

CoDrone.FlightEvent(Landing);             // Landing slowly
}
}

void loop()
{
}

#include <CoDrone.h>                     // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                    // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);   // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);     // Set drone into flight mode (Flight type drone)

delay(300);                                      // Waiting time

if (PAIRING == true)                         // Run only when pairing succeeds
{
CoDrone.FlightEvent(TurnOver);           // Flip

delay(4000);                                    // Running time

CoDrone.FlightEvent(Stop);                 // Stop
}
}

void loop()
{
}

#include <CoDrone.h> // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                    // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);   // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);     // Set drone into flight mode (Flight type drone)
}

void loop()
{
byte bt1 = digitalRead(11);       // ■ □ □ □ □ □ □ Use infrared sensors at bottom as input
byte bt4 = digitalRead(14);       // □ □ □ ■ □ □ □ Use infrared sensors at bottom as input
byte bt8 = digitalRead(18);       // □ □ □ □ □ □ ■ Use infrared sensors at bottom as input

if (bt1 && !bt4 && !bt8)          // Run when placing hand on sensor #11 of the board
{
CoDrone.FlightEvent(Stop);        // Stop the drone
}

if (!bt1 && !bt4 && bt8)           // Run when placing hand on sensor #18 of the board
{
CoDrone.FlightEvent(Landing);    // Land the drone
}

if (PAIRING == true)                 // Run only when pairing succeeds
{
YAW = -1 * CoDrone.AnalogScaleChange(analogRead(A3));
// Set value of analog pin #3 as YAW value                                         - Spin Left·Right

THROTTLE = CoDrone.AnalogScaleChange(analogRead(A4));
// Set value of analog pin #4 as THROTTLE value                                 - Ascend·Descend

ROLL = -1 * CoDrone.AnalogScaleChange(analogRead(A5));
// Set value of analog pin #5 as ROLL value                                         - Move Left·Right

PITCH = CoDrone.AnalogScaleChange(analogRead(A6));
// Set value of analog pin #6 as PITCH value                                        - Move Forward·Backward

CoDrone.Control(SEND_INTERVAL);
// Send control signal. For stable communication, sending takes some time.  (At least 50ms)
}
}

#include <CoDrone.h>                    // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                   // Initiate communication of BLE Board (115200bps)


CoDrone.AutoConnect(NearbyDrone);  // Connect to the nearest drone

CoDrone.DroneModeChange(Drive);    // Set drone into drive mode (Wheel type drone)
}

void loop()
{
byte bt1 = digitalRead(11);     // ■ □ □ □ □ □ □ Use infrared sensors at bottom as input
byte bt4 = digitalRead(14);     // □ □ □ ■ □ □ □ Use infrared sensors at bottom as input
byte bt8 = digitalRead(18);     // □ □ □ □ □ □ ■ Use infrared sensors at bottom as input

if (PAIRING == true)              // Run only when pairing succeeds
{
THROTTLE = CoDrone.AnalogScaleChange(analogRead(A4));
// Set value of analog pin #4 as THROTTLE value                                  - Ascend·Descend

ROLL = -1 * CoDrone.AnalogScaleChange(analogRead(A5));
// Set value of analog pin #5 as ROLL value                                         - Move Left/Right

CoDrone.Control(SEND_INTERVAL);
// Send control signal. For stable communication, sending takes some time. (At least 50ms)

}
}

#include <CoDrone.h>                         // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                        // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);       // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);         // Set drone into flight mode (Flight type drone)

CoDrone.BattleBegin(FREE_PLAY);   // Select Team : TEAM_RED/TEAM_BLUE/TEAM_GREEN/TEAM_YELLOW/FREE_PLAY
}

void loop()
{
CoDrone.BattleReceive();               // Receive IR-Data

byte bt1 = digitalRead(11);            // ■ □ □ □ □ □ □ Use infrared sensors at bottom as input
byte bt4 = digitalRead(14);            // □ □ □ ■ □ □ □ Use infrared sensors at bottom as input
byte bt8 = digitalRead(18);            // □ □ □ □ □ □ ■ Use infrared sensors at bottom as input

if (bt1 && !bt4 && !bt8)               // Run when placing hand on sensor #11 of the board
{
CoDrone.FlightEvent(Stop);             // Emergency stop for the drone
}

if (!bt1 && !bt4 && bt8)               // Run when placing hand on sensor #18 of the board
{
CoDrone.BattleShooting();              // Launch weapon
CoDrone.ButtonPreesHoldWait(18);  // Wait until the button is released.(Prevent rapid fire)
}

if (!bt1 && bt4 && !bt8)                // Run when placing the hand on the sensor at the center of the board
{
CoDrone.FlightEvent(Landing);          // Landing slowly
}

YAW = -1 * CoDrone.AnalogScaleChange(analogRead(A3));
// / Set value of analog pin #3 as YAW value                                       - Spin Left·Right

THROTTLE = CoDrone.AnalogScaleChange(analogRead(A4));
// Set value of analog pin #4 as THROTTLE value                                  - Ascend·Descend

ROLL = -1 * CoDrone.AnalogScaleChange(analogRead(A5));
// Set value of analog pin #5 as ROLL value                                         - Move Left·Right

PITCH = CoDrone.AnalogScaleChange(analogRead(A6));
// Set value of analog pin #6 as PITCH value                                        - Move Forward/Backward

CoDrone.Control(SEND_INTERVAL);
// Send control signal. For stable communication, sending takes some time. (At least 50ms)
}

#include <CoDrone.h>                       // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                      // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);    // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);      // Set drone into flight mode (Flight type drone)
}
void loop()
{
byte bt1 = digitalRead(11);                   // ■ □ □ □ □ □ □ Use infrared sensors at bottom as input
byte bt4 = digitalRead(14);                   // □ □ □ ■ □ □ □ Use infrared sensors at bottom as input
byte bt8 = digitalRead(18);                   // □ □ □ □ □ □ ■ Use infrared sensors at bottom as input

if ((analogRead(A4) < 50) && (analogRead(A6) < 50))   // Run when pulling down both side of the joystick
{
CoDrone.FlightEvent(Stop);                                      // Stop the drone (Emergency Stop)
// CoDrone.FlightEvent(Landing); // Stop the drone (Landing Slowly)
}

if (PAIRING == true)                                              // Run only when pairing succeeds
{
YAW = -1 * CoDrone.AnalogScaleChange(analogRead(A3));
// Set value of analog pin #3 as YAW value                                         - Spin Left·Right

THROTTLE = CoDrone.AnalogScaleChange(analogRead(A4));
// Set value of analog pin #4 as THROTTLE value                                  - Ascend·Descend

ROLL = -1 * CoDrone.AnalogScaleChange(analogRead(A5));
// Set value of analog pin #5 as ROLL value                                         - Move Left·Right

PITCH = CoDrone.AnalogScaleChange(analogRead(A6));
// Set value of analog pin #6 as PITCH value                                        - Move Forward·Backward

CoDrone.Control(SEND_INTERVAL);
// Send control signal. For stable communication, sending takes some time. (At least 50ms)
}
}

#include <CoDrone.h>                       // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                      // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);    // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);      // Set drone into flight mode (Flight type drone)
CoDrone.GoToHeight(800);                  // move to the height 800mm(80cm) (Input range : 1 ~ 2000 (Unit : mm))
delay(1000);                                     // Waiting time

CoDrone.FlightEvent(Landing);              // Landing slowly
}

void loop()
{
}

#include <CoDrone.h>                       // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                      // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);    // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);      // Set drone into flight mode (Flight type drone)

CoDrone.FlightEvent(TakeOff);              // Take-off
delay(3000);                                     // Waiting time

CoDrone.TurnDegree(90);                    // Rotate Right 90 degrees
delay(1000);                                     // Waiting time

CoDrone.FlightEvent(Landing);              // Landing slowly
}

void loop()
{
}


#include <CoDrone.h>                       // Header file for using CoDrone

byte modeTime = 7;                          // Variable : Mode time
int delayTime = 1000;                        // Variable : Waiting time

void setup()
{
CoDrone.begin(115200);                     // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);    // Connect to the nearest drone
}

void loop()
{
CoDrone.LedColor(ArmDimming, Yellow, modeTime);
// Set LED light into slowly blinking yellow light during mode time

delay(delayTime);                               // Waiting time

CoDrone.LedColor(ArmDimming, Cyan, modeTime);
// Set LED light into slowly blinking cyan light during mode time

delay(delayTime);                               // Waiting time
}

#include <CoDrone.h>                       // Header file for using CoDrone

byte modeTime = 7;                          // Variable : Mode time
int delayTime = 1000;                        // Variable : Waiting time

void setup()
{
CoDrone.begin(115200);                      // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);     // Connect to the nearest drone
}

void loop()
{
CoDrone.LedColor(ArmDimming, 255, 0, 0, modeTime);
// Set LED into slowly blinking light with entered RGB color during mode time delay(delayTime);

delay(delayTime);                               // Waiting time

CoDrone.LedColor(ArmDimming, 0, 255, 0, modeTime);
// Set LED into slowly blinking light with entered RGB color during mode time delay(delayTime);

delay(delayTime);                               // Waiting time

CoDrone.LedColor(ArmDimming, 0, 0, 255, modeTime);
// Set LED into slowly blinking light with entered RGB color during mode time delay(delayTime);

delay(delayTime);                               // Waiting time

CoDrone.LedColor(ArmDimming, 0, 0, 0, modeTime);
// Set LED into slowly blinking light with entered RGB color during mode time delay(delayTime);

delay(delayTime);                               // Waiting time
}

#include <CoDrone.h>                       // Header file for using CoDrone

byte modeTime = 7;                          // Variable : Mode time
int delayTime = 1000;                        // Variable : Waiting time

byte color0[] = {255, 0, 0};                  // color0 color arrangement (R, G, B)
byte color1[] = {0, 255, 0};                  // color1 arrangement (R, G, B)
byte color2[] = {0, 0, 255};                  // color2 arrangement (R, G, B)
byte color3[] = {0, 0, 0};                     // color3 arrangement (R, G, B)

void setup()
{
CoDrone.begin(115200);                      // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NeardbyDrone);   // Connect to the nearest drone
}

void loop()
{
CoDrone.LedColor(ArmDimming, color0, modeTime);
// Set LED into slowly blinking light with color0’s color during mode time delay(delayTime);

delay(delayTime);                               // Waiting time

CoDrone.LedColor(ArmDimming, color1, modeTime);
// Set LED into slowly blinking light with color1’s color during mode time delay(delayTime);

delay(delayTime);                               // Waiting time

CoDrone.LedColor(ArmDimming, color2, modeTime);
// Set LED into slowly blinking light with color2’s color during mode time delay(delayTime);

delay(delayTime);                               // Waiting time

CoDrone.LedColor(ArmDimming, color3, modeTime);
// Set LED into slowly blinking light with color3’s color during mode time delay(delayTime);

delay(delayTime);                               // Waiting time
}

#include <CoDrone.h>                       // Header file for using CoDrone

byte mode1 = ArmHold;
byte color1[] = {0, 0, 255};                   //color1 arrangement (R, G, B)
byte modeTime1 = 255;                      // Variable : Mode time

byte mode2 = EyeHold;
byte color2[] = {255, 255, 0};                //color2 arrangement (R, G, B)
byte modeTime2 = 255;                      // Variable : Mode time

void setup()
{
CoDrone.begin(115200);                       // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);      // Connect to the nearest drone
CoDrone.LedColorDefault(mode1, color1, modeTime2, mode2, color2, modeTime2);
// Operates depending on mode, mode time, and entered color
}

void loop()
{
}


#include <CoDrone.h>                      // Header file for using CoDrone
byte level = 50;                                // Reference value sets here

void setup()
{
CoDrone.begin(115200);                     // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);    // Connect to the nearest drone
CoDrone.LowBatteryCheck(level);          // If battery has lower power than reference value, sound the buzzer to alarm
}

void loop()
{
}

#include <CoDrone.h>

void setup()
{
CoDrone.begin(115200);
CoDrone.AutoConnect(NearbyDrone);
delay(500);
}

void loop()
{
AttitudeToSerialMonitor();
delay(500);
}

void AttitudeToSerialMonitor()
{
//---------------------------------------------------------------------------------------------//
CoDrone.Send_LinkModeBroadcast(LinkBroadcast_Active);           // link module mode change => Active
delay(100);
CoDrone.Request_DroneAttitude();

long oldTime = millis();
boolean attitudeSuccess = false;
CoDrone.receiveAttitudeSuccess = 0; //receiveAttitudeSuccess flag init

while (attitudeSuccess == false)                                            // receiveAttitudeSuccess check
{
CoDrone.Receive();
if (CoDrone.receiveAttitudeSuccess == 1) attitudeSuccess = true;
if (oldTime + 1000 < millis()) break;
}

//---------------------------------------------------------------------------------------------//
if (attitudeSuccess == true)
{
CoDrone.Send_LinkModeBroadcast(LinkModeMute);                  // link module mode change => Mute
delay(300);

Serial.println("");
Serial.println("--------- Now attitude -----------");
Serial.print("ROLLt");
Serial.println(AttitudeROLL);
Serial.print("PITCHt");
Serial.println(AttitudePITCH);
Serial.print("YAWt");
Serial.println(AttitudeYAW);
delay(500);
}
//---------------------------------------------------------------------------------------------//
}

#include <CoDrone.h>                      // Header file for using CoDrone

void setup()
{

CoDrone.begin(115200);                     // Initiate communication of BLE Board (115200bps)

CoDrone.AutoConnect(NearbyDrone);    // Connect to the nearest drone

CoDrone.DisplayRSSI();                       // Represent the drone’s RSSI value by LED
}

#include <CoDrone.h>                      // Header file for using CoDrone

int scale = 200;                                // Criteria altitude of one LED is 200mm
int firstLEDpin = 11;                          // First LED pin number on the Smart Board

void setup()
{
CoDrone.begin(115200);                     // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);    // Connect to the nearest drone

delay(500);

for (int thisPin = 11; thisPin <=1 8; thisPin++) {
pinMode(thisPin, OUTPUT);
}
for (int thisPin = 11; thisPin <=1 8; thisPin++) {
digitalWrite(thisPin, LOW);
}
}

void loop()
{
CoDrone.Request_Range();
long oldTime = millis();

while (CoDrone.receiveRangeSuccess) //receiveRangeSuccess check
{
CoDrone.Receive();
if (oldTime + 1000 < millis()) break;
}

if (CoDrone.receiveRangeSuccess == true)
{
int _sensor = CoDrone.sensorRange[5] / scale;

if (_sensor < 0 )_sensor=0 ;
if (_sensor > 7) _sensor = 7;
for (int thisPin = 11; thisPin <=1 8; thisPin++) {
digitalWrite(thisPin, LOW);
}

digitalWrite(firstLEDpin, HIGH);
for (int i = 1; i < _sensor ; i++)
{
digitalWrite(++firstLEDpin , HIGH);
}
}
}

#include <CoDrone.h>                        // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                       // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);      // Connect to the nearest drone
delay(500);
}
void loop()
{
RangeSensorToSerialMonitor();
}

void RangeSensorToSerialMonitor()
{
//---------------------------------------------------------------------------------------------//
CoDrone.Send_LinkModeBroadcast(LinkBroadcast_Active);          // link module mode change => Active
delay(100);
CoDrone.Request_Range();

long oldTime = millis();
while (CoDrone.receiveRangeSuccess == false)                        // receiveRangeSuccess check
{
CoDrone.Receive();
if (oldTime + 1000 < millis()) break;                                      // time out check
}
//---------------------------------------------------------------------------------------------//
if (CoDrone.receiveRangeSuccess == true)
{
CoDrone.Send_LinkModeBroadcast(LinkModeMute);                 // link module mode change => Mute
delay(300);

Serial.println("");
Serial.println("--------------- Sensor ---------------");
Serial.print("range tt");
Serial.print(CoDrone.sensorRange[5]);
Serial.println(" mm");
Serial.println("-------------------------------------- ");
delay(500);
}
//---------------------------------------------------------------------------------------------//
}


#include <CoDrone.h>                            // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                           // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);         // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);           // Set drone into flight mode (Flight type drone)

delay(300);                                            // Waiting time

if (PAIRING == true)                                // Run only when pairing succeeds
{
CoDrone.FlightEvent(TakeOff);                    // Take-off

delay(1000);                                           // Waiting time

PITCH = 50;                                           // Enter PITCH value
ROLL = 50;                                            // Enter ROLL value
CoDrone.Control();                                  // Operate the drone with entered values

delay(1000);                                           // Waiting time

PITCH = 50;                                           // Enter PITCH value
ROLL = -50;                                           // Enter ROLL value
CoDrone.Control();                                  // Operate the drone with entered values

delay(1000);                                           // Waiting time

PITCH = -50;                                          // Enter PITCH value
ROLL = -50;                                           // Enter ROLL value
CoDrone.Control();                                  // Operate the drone with entered values

delay(1000);                                           // Waiting time

PITCH = -50;                                          // Enter PITCH value
ROLL = 50;                                            // Enter ROLL value
CoDrone.Control();                                  // Operate the drone with entered values

delay(1000);                                           // Waiting time

CoDrone.FlightEvent(Landing);                    // Landing slowly
}
}

void loop()
{
}

#include <CoDrone.h>                            // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                           // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);         // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);           // Set drone into flight mode (Flight type drone)

delay(300);                                            // Waiting time

if (PAIRING == true)
{
CoDrone.FlightEvent(TakeOff);                    // Take-off
delay(1000);                                           // Waiting time

THROTTLE = 60;                                     // Enter THROTTLE value
                                                          //Rotate 4 times to 90 degrees fan shape
for(int i=0;i<4;i++)
{
THROTTLE = THROTTLE - 10;                    // Enter THROTTLE value
YAW = -80;                                           // Enter YAW value
ROLL = 50;                                            // Enter ROLL value
CoDrone.Control();                                  // Send Control value

delay(1500);                                           // Waiting time
}
CoDrone.FlightEvent(Stop);                        // Stop
}
}

void loop()
{
}

#include <CoDrone.h>                                // Header file for using CoDrone

void setup()
{
CoDrone.begin(115200);                              // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);             // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);               // Set drone into flight mode (Flight type drone)

if (PAIRING == true)                                    // Run only when pairing succeeds
CoDrone.FlightEvent(TakeOff);                        // Take-off
delay(1000);                                               // Waiting time

PITCH = 30;                                               // Enter PITCH value
CoDrone.Control();                                       // Send Control value
delay(300);                                                 // Waiting time

CoDrone.FlightEvent(Stop);                            // Landing slowly
}
}

void loop()
{
}

#include <CoDrone.h>                                // Header file for using CoDrone

void setup() {
CoDrone.begin(115200);                              // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);             // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);               // Set drone into flight mode (Flight type drone)

delay(400);                                                // Waiting time

if (PAIRING == true)                                   // Run only when pairing succeeds
{
CoDrone.FlightEvent(TakeOff);                       // Take-off

delay(1000);                                               // Waiting time
                                                              // Ascend
THROTTLE = 20;                                         // Enter THROTTLE value
CoDrone.Control();                                      // Send Control value

delay(500);                                                // Waiting time
                                                              // Move forward
THROTTLE = 0;                                          // Enter THROTTLE value
PITCH = 100;                                            // Enter PITCH value
ROLL = -10;                                              // Enter ROLL value
CoDrone.Control();                                      // Send Control value

delay(300);                                                // Waiting time
                                                              // Fly in place
THROTTLE = 0;                                          // Enter THROTTLE value
PITCH = 0;                                                // Enter PITCH value
ROLL = 0;                                                 // Enter ROLL value
CoDrone.Control();                                      // Send Control value
delay(500);                                                // Waiting time

CoDrone.FlightEvent(Landing);                       // Landing
}
}

void loop() {
}

#include <CoDrone.h>                         // Header file for using CoDrone
void setup()
{
CoDrone.begin(115200);                        // Initiate communication of BLE Board (115200bps)
CoDrone.AutoConnect(NearbyDrone);      // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);        // Set drone into flight mode (Flight type drone)
}

void loop()
{
byte bt1 = digitalRead(11);                    // ■ □ □ □ □ □ □ Use infrared sensors at bottom as input
byte bt4 = digitalRead(14);                    // □ □ □ ■ □ □ □ Use infrared sensors at bottom as input
byte bt8 = digitalRead(18);                    // □ □ □ □ □ □ ■ Use infrared sensors at bottom as input

int analogValue0 = analogRead(A0);        // Connect Analog sensor to the control value (Throttle, Pitch, or Roll) that you want
int analogValue1 = analogRead(A1);        // Connect Analog sensor to the control value (Throttle, Pitch, or Roll) that you want
int analogValue2 = analogRead(A2);        // Connect Analog sensor to the control value (Throttle, Pitch, or Roll) that you want

if (bt1 && !bt4 && !bt8)                       // Run when placing hand on sensor #11 of the board
{
CoDrone.FlightEvent(Stop);                     // Stop the drone
}

if (bt4)                                               // Run when placing a hand on sensor #14 which is at the bottom center of the board

{
THROTTLE = map(analogValue1, 0, 1023, -50, 200);                // Ascend·Descend
ROLL = map(analogValue0, 0, 1023, 100, 0) + map(analogValue2, 0, 1023, -100, 0); // Move Left·Right
CoDrone.Control(SEND_INTERVAL); // Send control signal. Sending takes some time (At least 50ms)
}

if (bt8)                                               // Run when placing hand on sensor #18 of the board
{
THROTTLE = map(analogValue1, 0, 1023, -50, 200);                // Ascend·Descend
PITCH = map(analogValue0, 0, 1023, -100, 0) + map(analogValue2, 0, 1023, 100, 0); // Move Forward·Backward
CoDrone.Control(SEND_INTERVAL); // Send control signal. Sending takes some time (At least 50ms)
}
}

#include <CoDrone.h>                             // Header file for using CoDrone

int slowUp = 80;                                     // Value of slow hovering ascent
int slowDown = -100;                              // Value of slow hovering descent
int slowTime = 10;                                  // Control the slow moving speed: moves slower when the value gets bigger

void setup()
{
CoDrone.begin(115200);

CoDrone.AutoConnect(NearbyDrone);          // Connect to the nearest drone
CoDrone.DroneModeChange(Flight);            // Set drone into flight mode (Flight type drone)

delay(300);

                                                           // Use all bottom sensors as inputs
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(13, INPUT);
pinMode(14, INPUT);
pinMode(15, INPUT);
pinMode(16, INPUT);
pinMode(17, INPUT);
pinMode(18, INPUT);

delay(100);
}

void loop()
{
byte bt1 = digitalRead(11);
byte bt2 = digitalRead(12);
byte bt3 = digitalRead(13);
byte bt4 = digitalRead(14);                         //14 & 15
byte bt6 = digitalRead(16);
byte bt7 = digitalRead(17);
byte bt8 = digitalRead(18);

//*************************** Slow Up ***************************//
// ■ □ □ □ □ □ □ Ascends slowly when placing hand on sensor #1
if (bt8 && !bt7 && !bt6 && !bt4 && !bt3 && !bt2 && !bt1)
{
THROTTLE = slowUp;
CoDrone.Control();
delay(slowTime);
THROTTLE = 0;
CoDrone.Control();
}

//*************************** Slow Down ***************************//
// □ □ □ □ □ □ ■ Descends slowly when placing hand on sensor #7
else if (!bt8 && !bt7 && !bt6 && !bt4 && !bt3 && !bt2 && bt1)
{
THROTTLE = slowDown;
CoDrone.Control();
delay(slowTime);
THROTTLE = 0;
CoDrone.Control();
}

//**************************** STOP ******************************//
// □ □ □ ■ □ □ □ Stops when placing hand on sensor #4
else if (bt4)
{
CoDrone.FlightEvent(Stop);

}
//**************************** Control ******************************//
// □ ■ □ □ □ □ □ Moves forward when placing hand on sensor #2
// Forward
else if (!bt8 && bt7 && !bt6 && !bt4 && !bt3 && !bt2 && !bt1)
{
PITCH = 40;
CoDrone.Control();
}
// □ □ □ □ □ ■ □ Moves backward when placing hand on sensor #6
// Back
else if (!bt8 && !bt7 && !bt6 && !bt4 && !bt3 && bt2 && !bt1)
{
PITCH = -40;
CoDrone.Control();
}
// □ □ ■ □ □ □ □ Moves left when placing hand on sensor #3
// Left
else if (!bt8 && !bt7 && bt6 && !bt4 && !bt3 && !bt2 && !bt1)
{
ROLL = -40;
CoDrone.Control();
}
// □ □ □ □ ■ □ □ Moves right when placing hand on sensor #5
// Right
else if (!bt8 && !bt7 && !bt6 && !bt4 && bt3 && !bt2 && !bt1)
{
ROLL = 40;
CoDrone.Control();
}
delay(10);
}