> For the complete documentation index, see [llms.txt](https://ptandur14.gitbook.io/everything-about-drone/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ptandur14.gitbook.io/everything-about-drone/table-tennis-game.md).

# Table Tennis Game

If we execute this program/code then we can play the game with the help of drone

```

// Do not remove the include below
#include "PlutoPilot.h"
#include "XRanging.h"
#include "Utils.h"
#include "User.h"

int16_t Rangel = 0;
int16_t Ranger = 0;
//The setup function is called once at Pluto's hardware startup
void plutoInit()
{
	XRanging.init(LEFT);
	XRanging.init(RIGHT);

// Add your hardware initialization code here
}



//The function is called once before plutoLoop when you activate Developer Mode
void onLoopStart()
{
	LED.flightStatus(DEACTIVATE);
  // do your one time stuff here

}



// The loop function is called in an endless loop
void plutoLoop()
{
Rangel=XRanging.getRange(LEFT);
Ranger=XRanging.getRange(RIGHT);

if (Ranger<300)
{
	RcCommand.set(RC_ROLL,1450);
LED.set(RED, ON);
LED.set(GREEN,OFF);
}
else if (Rangel<300)
{
 RcCommand.set(RC_ROLL,1550);
 LED.set(GREEN,ON);
 LED.set(RED,OFF);
}
else{
	RcCommand.set(RC_ROLL, 1500);
	LED.set(GREEN,OFF);
	LED.set(RED,OFF);
}
//Add your repeated code here

}



//The function is called once after plutoLoop when you deactivate Developer Mode
void onLoopFinish()
{
LED.flightStatus(ACTIVATE);
// do your cleanup stuffs here

}





```

For this game we had first tried to get the values from the distance sensor so on the monitor we get these values

![When the object is at distance (Distance is in mm)](https://2337796245-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LiHGnU31k3UMwGKWEZa%2F-LjUO6M9TM0Kqax_Cjkm%2F-LjUf643ACMKai9-p2xY%2FScreenshot%20\(5\)_LI.jpg?alt=media\&token=fd9f7a64-ef0c-4bca-98b7-cc8c033b2644)

![When the object is too close (Distance is in mm)](https://2337796245-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LiHGnU31k3UMwGKWEZa%2F-LjUO6M9TM0Kqax_Cjkm%2F-LjUfFTNA4zDSiMZGidZ%2FScreenshot%20\(6\)_LI.jpg?alt=media\&token=7adaa4a4-df76-47ef-99cb-fd1ab944751a)

![Playing Hover Tennis with Drone](https://2337796245-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LiHGnU31k3UMwGKWEZa%2F-LjUO6M9TM0Kqax_Cjkm%2F-LjUfg7jknOWkVvj9vhA%2F20190711_113724.gif?alt=media\&token=d7f9bc79-3e1a-481b-ad9c-b1df26ad7637)
