//defining the pins used for joystick # define VRx 4 // potenetiometer in x direction # define VRy 3 // potenetiometer in y direction # define SW 8 //switch # define rst 1 //reset pin void setup() { Serial.begin(115200); // wake up serial at a specific rate Serial2.begin(115200);// wake up serial1 at the same rate (check that this is the rate your bluetooth module wants) pinMode(VRx, OUTPUT); pinMode(VRy, OUTPUT); pinMode(SW, INPUT_PULLUP); //to enable reseting my bluetooth device (so that I don't need to constantly replug my USB) digitalWrite(rst,LOW); delay(1); digitalWrite(rst, HIGH); delay(100); // setting up the bluetooth device delay(100); Serial2.print("$$$"); //no line ending delay(100); Serial2.print("+\r"); //carriage return delay(100); Serial2.print("SS,C0\r"); //carriage return delay(100); Serial2.print("C,0,44B7D0642065\r"); //carriage return delay(3000); } // for the potentiometer int VRx_read = 0; int VRy_read = 0; void loop() { // reading the potentiometer VRx_read = analogRead(VRx); VRy_read = analogRead(VRy); Serial.print(VRy_read); Serial.print(" "); Serial.println(VRx_read); Serial2.print(VRy_read); // sending the data to the car Serial2.print(" "); Serial2.println(VRx_read); //Serial2.println("12 12"); // button for honking if (digitalRead(SW)==LOW){ //when you press the button and make the voltage grounded, it's equal to LOW Serial.println(2000); Serial2.println(2000); } // allowing Bluetooth communication while (Serial.available()) { // If anything comes in Serial USB, Serial2.write(Serial.read()); // read it and send it out Serial1 (PA14/15) // Serial.write(VRx_read); // Serial.write(" "); // Serial.write(VRy_read); // } while (Serial2.available()) { // If anything comes in Serial1 (PA14/15) Serial.write(Serial2.read()); // read it and send it out Serial USBㅡㅡ } delay(100); }