#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
#include <Servo.h>
#include “Arduino.h”
YunServer server;
Servo ail; // Create a servo object
Servo ele; // Create a servo object
Servo thr; // Create a servo object
Servo rud; // Create a servo object
Servo aux; // Create a servo object
int value, aileron, elevator, throttle, rudder, auxiliary;
void setup()
{
Serial.begin (115200);
Bridge.begin();
server.begin();
ail.attach(5); // Attaches the servo on Pin 4
ele.attach(6); // Attaches the servo on Pin 5
thr.attach(9); // Attaches the servo on Pin 6
rud.attach(10); // Attaches the servo on Pin 7
aux.attach(11); // Attaches the servo on Pin 7
}
void loop()
{
YunClient client = server.accept();
if (client)
{
process(client);
client.stop();
}
delay(15);
}
void process(YunClient client)
{
String command = client.readStringUntil(’/’);
// Check if the url contains the word “quad”
if (command == “quad”)
{
servoCommand(client);
}
}
void servoCommand(YunClient client)
{
aileron = client.parseInt();
if(client.read() == ‘/’)
{
elevator = client.parseInt();
if(client.read() == ‘/’)
{
throttle = client.parseInt();
if(client.read() == ‘/’)
{
rudder = client.parseInt();
if(client.read() == ‘/’)
{
auxiliary = client.parseInt();
ail.writeMicroseconds(aileron); // servo ail
ele.writeMicroseconds(elevator); // servo ele
thr.writeMicroseconds(throttle); // servo thr
rud.writeMicroseconds(rudder); // servo rud
aux.writeMicroseconds(auxiliary); // servo aux
}
}
}
}
}