#include #include unsigned long int a,b,c; int x[15],ch1[15],ch[7],i; //specifing arrays and variables to store values //Wifi Variables const char* ssid = "WiFi-720P-51667B"; const char* password = ""; WiFiUDP Udp; //unsigned int remoteUdpPort = 50000; byte Packet[8]; void setup() { Serial.begin(9600); //Connect to Wifi Serial.printf("Connecting to %s ", ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(" connected"); //Enable interrupt on pin 2 pinMode(2, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(2), read_me, FALLING); delay(500); } void loop() { read_rc(); //Serial.print(ch[1]);Serial.print("\t"); //Serial.print((ch[2]));Serial.print("\t"); //Serial.print((ch[3]));Serial.print("\t"); //Serial.print((ch[4]));Serial.print("\t"); //Serial.print(ch[5]);Serial.print("\t"); //Serial.print(ch[6]);Serial.print("\n"); if (WiFi.status() == WL_CONNECTED) { //Send UDP packet //Packet = 0x66 0xRoll 0xPitch 0xThrottle 0xYaw 0xCommand 0xChecksum 0x99 all range 0/254 128 being zero Packet[0] = 0x66; Packet[1] = 0.317 * (ch[1] -100); Packet[2] = 0.317 * (ch[2] -100); Packet[3] = 0.317 * (ch[3] -100); Packet[4] = 0.317 * (ch[4] -100); if (ch[5] < 500) Packet[5] = 0x20; else Packet[5] = 0x04; Packet[6] = Packet[5] ^ Packet[4] ^ Packet[3] ^ Packet[2] ^ Packet[1] ; Packet[7] = 0x99; Serial.print(Packet[0],HEX);Serial.print(" "); Serial.print((Packet[1]),HEX);Serial.print(" "); Serial.print((Packet[2]),HEX);Serial.print(" "); Serial.print((Packet[3]),HEX);Serial.print(" "); Serial.print(Packet[4],HEX);Serial.print(" "); Serial.print(Packet[5],HEX);Serial.print(" "); Serial.print(Packet[6],HEX);Serial.print(" "); Serial.print(Packet[7],HEX);Serial.print("\n"); //String outer = String(Packet); Udp.beginPacket("192.168.0.1", 50000); //Udp.write(outer); Udp.write(Packet[0]); Udp.write(Packet[1]); Udp.write(Packet[2]); Udp.write(Packet[3]); Udp.write(Packet[4]); Udp.write(Packet[5]); Udp.write(Packet[6]); Udp.write(Packet[7]); Udp.endPacket(); } else { while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(" connected"); } //generate aprox 50ms delay delay(50); } void read_me() { //this code reads value from RC reciever from PPM pin (Pin 2 or 3) //this code gives channel values from 0-1000 values // -: ABHILASH :- // a=micros(); //store time value a when pin value falling c=a-b; //calculating time inbetween two peaks b=a; // x[i]=c; //storing 15 value in array i=i+1; if(i==15){for(int j=0;j<15;j++) {ch1[j]=x[j];} i=0;}}//copy store all values from temporary array another array after 15 reading void read_rc(){ int i,j,k=0; for(k=14;k>-1;k--){if(ch1[k]>10000){j=k;}} //detecting separation space 10000us in that another array for(i=1;i<=6;i++){ch[i]=(ch1[i+j]-1000);}} //assign 6 channel values after separation space