Hi folks!
I made a remote control for my RC copter using xbees and arduinos, and now i want to use just the remote control to acts as a simple game controller using UnoJoy.
The idea is, the remote control sends control data using serial communication to arduino which already flashed with UnoJoy.
When activated, the remote control sends a, b, c, d, e, f , and i only need the e and f values.
e is the X axis, and f is the Y axis data.
Here's the full code for the receiver:
#include "UnoJoy.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 12); // RX, TX
int axisValue[2];
void setup(){
setupUnoJoy();
mySerial.begin(38400);
}
void loop(){
if (mySerial.available() > 0) {
int but1 = mySerial.parseInt();
int but2 = mySerial.parseInt();
int but3 = mySerial.parseInt();
int but4 = mySerial.parseInt();
int xValue = mySerial.parseInt();
int yValue = mySerial.parseInt();
if (mySerial.read() == '\n') {
axisValue[0] = map(xValue,0,1023,0,255);
axisValue[1] = map(yValue,0,1023,0,255);
}
}
dataForController_t controllerData = getControllerData();
setControllerData(controllerData);
}
dataForController_t getControllerData(void){
dataForController_t controllerData = getBlankDataForController();
controllerData.leftStickX = axisValue[0];
controllerData.leftStickY = axisValue[1];
return controllerData;
}
If i hardcode the axisValue[0] and axisValue[1] using values from 0 to 255 in the loop section, there's no problem, the computer can read it correctly.
But when i use
...
axisValue[0] = map (xValue,0,1023,0,255);
axisValue[1] = map (yValue,0,1023,0,255);
...
Nothing happens....
Anyone had a clue what's happening?