// Libraries #include #include #include #include byte SEND_PIN = 4; IRsend irsend(SEND_PIN); // WiFi network const char* ssid = "xxxxxxx"; const char* password = "xxxxxxx"; AsyncWebServer server(80); const char* input_heading = "heading"; const char* input_memory = "memory"; char headingmap[360]; const uint16_t IRCodes[] = { 0x44, // A 0x7, // B 0x9, // C 0x40, // D 0x19, // E 0x16, // F 0xC, // G 0x18, // H 0x5E, // I 0x8, // J 0x1C, // K -> U 0x5A // L }; // other possible codes: // rotate CCW: 0x43 // rotate CW: 0x45 // initial: 0x42 // memory: 0x4A const char index_html[] PROGMEM = R"rawliteral( Hy-Gain AR-500X

HyGain AR-500X

N
WE
S

)rawliteral"; void notFound(AsyncWebServerRequest *request) { request->send(404, "text/plain", "Not found"); } // Function to get value by key const uint16_t getValueByKey(char key) { key = toupper(key); int index = key - 'A'; return IRCodes[index]; } char lookupLetter(int angle) { // Adjust angle to be within 0 and 360 angle %= 360; if (angle < 0) { angle += 360; } // Define the lookup table const int angles[] = {0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300, 315, 330, 345, 360}; const char letters[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'A'}; // Find the closest angle in the table int closestAngleIndex = 0; for (int i = 1; i < 26; ++i) { if (abs(angles[i] - angle) < abs(angles[closestAngleIndex] - angle)) { closestAngleIndex = i; } } // Return the corresponding letter return letters[closestAngleIndex]; } void setup() { // Start serial Serial.begin(9600); delay(10); Serial.print("ESP Board MAC Address: "); Serial.println(WiFi.macAddress()); // Connecting to a WiFi network Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); // Fill the array char currentChar = 'A'; for (int i = 0; i < 360; i++) { headingmap[i] = currentChar; if ((i + 1) % 15 == 0) { currentChar++; if (currentChar > 'L') currentChar = 'A'; } } Serial.println("OK"); server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/html", index_html); }); server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) { String input_message; char mem; if (request->hasParam(input_memory)) { input_message = request->getParam(input_memory)->value(); mem = input_message[0]; } if (request->hasParam(input_heading)) { int angle = request->getParam(input_heading)->value().toInt(); char letter = lookupLetter(angle); mem = letter; } else { input_message = "No message sent"; } Serial.println(String(mem)); uint16_t val = getValueByKey(mem); Serial.println("IR Code: " + String(val)); irsend.sendNEC(0x0, val, 2); delay(500); request->send_P(200, "text/html", index_html); }); server.onNotFound(notFound); server.begin(); } void loop() { }