#include #include #include int xData; // Variables for the xData to be recieved to int yData; RF24 radio(3,A3); //Creating instance 'radio' ( CE , CSN ) CE -> 3 | CSN -> A3 const byte Address[6] = "0100"; // Address from which data to be received void RF24setup() { // Serial.begin(9600); Only needed for Debugging radio.begin(); // waking up the Transmitter radio.openReadingPipe(1, Address); radio.startListening(); } void RF24loop() { if (radio.available()) { radio.read(&xData, sizeof(xData)); // Storing the xData recieved as xData radio.read(&yData, sizeof(yData)); // Serial.print("xData "); Only needed for Debugging // Serial.print(xData); // Serial.print(" "); // Serial.print("yData "); // Serial.print(yData); // Serial.println(); } // else{Serial.println("Not Receiving !!!");} Only needed for Debugging } // Example from: https://www.geeksforgeeks.org/enumeration-enum-c enum movement // Creating a variable with different States { Balance, Forward, Back, Turn_Left, Turn_Right, } movement = Balance; // Creating a Function to assign the Variable the motor speeds for each state void selfDriving() { if (movement == Forward){ setting_car_speed = 80; setting_turn_speed = 0; } if (movement == Back){ setting_car_speed = -80; setting_turn_speed = 0; } if (movement == Turn_Left){ setting_car_speed = 0; setting_turn_speed = 80; } if (movement == Turn_Right){ setting_car_speed = 0; setting_turn_speed = -80; } if(movement == Balance){ setting_car_speed = 0; setting_turn_speed = 0; } } // Assigning the Joystick values to individual states void joyStickDriving(){ if (yData < 300){ movement = Forward; selfDriving(); } if (yData > 1000){ movement = Back; selfDriving(); } if (xData < 100){ movement = Turn_Left; selfDriving(); } if (xData > 1000){ movement = Turn_Right; selfDriving(); } else{ movement = Balance; selfDriving(); } }