//simple Tx on pin D12 // for this code to work it is important to download virtualWire Library //.................................. #include // first we name the inputs and outputs. char *controller; int joystickPr1=0; int joystickPr2=1; int joystickPr3=2; void setup() { Serial.begin(9600); // Debugging only Serial.println("setup"); vw_set_ptt_inverted(true); // vw_set_tx_pin(12); vw_setup(4000);// speed of data transfer Kbps } void loop(){ joystickPr1=analogRead(A0); float signal1=joystickPr1*(5.0/1023.0); //here i define the signal from joystick1 from 0-5. This is for left or right joystickPr2=analogRead(A1); float signal2=joystickPr2*(5.0/1023.0);//here i define the signal from joystick2 from 0-5. This is for forward or backward joystickPr3=analogRead(A2); float signal3=joystickPr3*(5.0/1023.0);//here i define the signal from joystick2 from 0-5. This is for the sirens if (signal2>3.5)// if the joystick goes over 3.5v it will go backward {controller="1"; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); ; Serial.println("REVERSE"); } else{ // if joystick1 is between 1-3.5v it will send a signal to turn motor1 off. controller="a"; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); // Wait until the whole message is gone ; } if (signal2<1.0) // if the signal goes under 1v it will send signal to go forward {controller="2"; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); // Wait until the whole message is gone Serial.println("FORWARD");} else{ controller="b"; // this will stop the motor. vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); // Wait until the whole message is gone } // this is the ultimate stop, if the joysticks fails, this code should turn of the motors. if (digitalRead(4)==HIGH) {controller="5"; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); } if (digitalRead(4)==LOW){ controller="0"; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); // Wait until the whole message is gone } if (signal1>3.5) //if the signal goes over 3.5 it will send a signal to motor2 {controller="3"; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); Serial.println("RIGHT"); } else{ // this will turn motor2 off controller="c"; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); // Wait until the whole message is gone } if (signal1<1.0) // if the signal from joystick2 goes under 1 it will reverse motor2 {controller="4"; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); Serial.println("LEFT"); } else{ controller="d"; // this will turn motor 2 off vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); // Wait until the whole message is gone } if (signal3>3.5) {controller="8"; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); Serial.println("SIRENS"); } if(signal3<1.0){ controller="f"; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); // Wait until the whole message is gone} } }