/* Made by Jefferson Sandoval for the Final project of FabAcademy 2021. * * This is the official code for my Fab-RemoteControl of my Fab-OmniBot, a three-wheeled robot. * * Uploaded to my own board that uses an ATtiny1614 microcontroller, a nRF24 radio transceiver * module (as transmitter) and two joysticks. * * Documentation: * http://fabacademy.org/2021/labs/kamplintfort/students/jefferson-sandoval/project/02_RemoteControl/ */ //Libraries for Communication nRF24 #include #include #include RF24 radio(4, 5); //Create radio object with and CE & CSN pins const byte address[6] = "00111"; //Transmitter communication address void setup() { radio.begin(); //Initialize radio object radio.setPALevel(RF24_PA_LOW); //Set radio range radio.openWritingPipe(address); //Set address to receiver radio.stopListening(); //Set module as transmitter } void loop() { int Values[3]; //Declare variable for data to send //int Values[4]; //When using the fourth Joystick reading //Read values from Joysticks and convert them to percentage. //I mapped the values from 270 to 750 cause that is the range of the Joysticks (instead of 0-1023). Values[0] = map(analogRead(0),270,750,-100,100); //Left and Right movement from Joystick_Right Values[1] = map(analogRead(1),270,750,-100,100); //Forward and Backward movement from Joystick_Right Values[2] = map(analogRead(7),270,750,-100,100); //Rotation movement from Joystick_Left //Values[3] = map(analogRead(6),270,750,-100,100); //This adds a fourth Axis, Y movement for Joystick_Left radio.write(&Values, sizeof(Values)); //Send array of Values to Receiver delay(100); //Send values every 0.1 seconds }