#include #include #include // WiFi credentials const char* ssid = "Atom(Atherion warrior)"; const char* password = "mavihlovesyou:)"; // Pin definitions const int MOTOR_PIN = 13; const int SERVO_X_PIN = 12; const int SERVO_Y_PIN = 14; // Servo objects Servo servoX; Servo servoY; // Control variables int motorSpeed = 0; int servoXPos = 90; int servoYPos = 90; bool armed = false; // PWM settings for motor const int PWM_FREQ = 1000; const int PWM_MAX = 1023; ESP8266WebServer server(80); const char index_html[] PROGMEM = R"rawliteral( Atom Control
ARM

ATOM

MITS Gwalior • Aerospace
Team Atherion
0%
X: 90° | Y: 90°
)rawliteral"; void handleRoot() { server.send(200, "text/html", index_html); } void handleControl() { if (server.hasArg("throttle") && server.hasArg("x") && server.hasArg("y")) { int throttle = server.arg("throttle").toInt(); int x = server.arg("x").toInt(); int y = server.arg("y").toInt(); if (armed) { motorSpeed = constrain(throttle, 0, 100); int pwmValue = map(motorSpeed, 0, 100, 0, PWM_MAX); analogWrite(MOTOR_PIN, pwmValue); } else { analogWrite(MOTOR_PIN, 0); } servoXPos = constrain(x, 0, 180); servoYPos = constrain(y, 0, 180); servoX.write(servoXPos); servoY.write(servoYPos); server.send(200, "text/plain", "OK"); } else { server.send(400, "text/plain", "Bad Request"); } } void handleArm() { if (server.hasArg("state")) { armed = (server.arg("state") == "1"); if (!armed) { analogWrite(MOTOR_PIN, 0); motorSpeed = 0; } server.send(200, "text/plain", armed ? "ARMED" : "DISARMED"); } else { server.send(400, "text/plain", "Bad Request"); } } void setup() { Serial.begin(115200); delay(10); Serial.println("\n\nATOM RC Plane Controller"); pinMode(MOTOR_PIN, OUTPUT); analogWriteFreq(PWM_FREQ); analogWrite(MOTOR_PIN, 0); servoX.attach(SERVO_X_PIN); servoY.attach(SERVO_Y_PIN); servoX.write(90); servoY.write(90); WiFi.mode(WIFI_AP); WiFi.softAP(ssid, password); IPAddress IP = WiFi.softAPIP(); Serial.print("AP IP: "); Serial.println(IP); server.on("/", handleRoot); server.on("/control", handleControl); server.on("/arm", handleArm); server.begin(); Serial.println("Server started"); Serial.println("Connect to: " + String(ssid)); Serial.println("Open: http://" + IP.toString()); } void loop() { server.handleClient(); }