I am running a small project to control servo motor by using joystick through RF 315MHz wireless.
In my coding, i am using VirtualWire.h library, but the wireless coding part did not work at all.
I am printing the joystick position at the serial monitor but no data shown whenever the wireless command exist. I have to uncommand the wireless part (the 3 lines shown below), only then the joystick data will be appear at the serial monitor.
Whats wrong with my coding? ><
Previously i try to ON/OFF 5 leds with the joystick, no prob at all. I mean to turn ON or OFF leds to indicate the quadrant or position of the joystick.
- CODE: SELECT_ALL_CODE
// vw_set_ptt_inverted(true);
// vw_set_tx_pin(12);
// vw_setup(2000);
my whole coding is below; the transmitter part only;
- CODE: SELECT_ALL_CODE
// tx joystick for servo COM18
#include <VirtualWire.h>
const int poseX = 1; // L/R
const int poseY = 0; // U/D
const int led1 = 7;
int servoVal1;
int servoVal2;
int servoValx;
int servoValy;
void setup() {
Serial.begin(9600);
Serial.println("Joystick Joystick Joystick Joystick Joystick"); //
pinMode(led1,OUTPUT);
digitalWrite(led1,HIGH);
delay(1000);
digitalWrite(led1,LOW);
delay(1000);
vw_set_ptt_inverted(true);
vw_set_tx_pin(12);
vw_setup(2000);
}
void loop() {
outputJoystick();
servoVal1 = analogRead(poseX);
servoValx = map(servoVal1, 0, 1023, 170, 20);
servoVal2 = analogRead(poseY);
servoValy = map(servoVal2, 0, 1023, 170, 20);
Serial.println (" ");
delay(250);
}
void outputJoystick() {
Serial.print (" Pose X: ");
Serial.println (servoValx, DEC);
Serial.print (" Pose Y: ");
Serial.println (servoValy, DEC);
}
////