Any Arduino enthusiasts or C+ coders out there willing to help with a project (Star Citizen related)

Slansickness

Space Marshal
Mar 14, 2015
92
163
2,360
RSI Handle
Slantsickness
I think I might start a TEST Modders Thread, making it easier to find certain stuff. We could have a catalog of mods we use (from physical mods like this joystick mod to what mods we use with our games), put together from all of us. I think it would be a cool way to see what others got going on and a good way to learn. Let me know what you guys think and maybe we can run it by Montoya.
That's a great idea. Since most of us will probably be using arduinos we could write some functions for common uses for the community to use copy/paste style. Makes it easy for newbies to get their devices working with a minimum of frustration. Maybe simple electronics stuff too.
 

Krystal LeChuck

Meme Meister
Staff member
Officer
Jun 10, 2014
594
888
1,420
RSI Handle
Krystal
For some reason the code wouldn't compile
The reason should be given to you by the debugger. That is what you need to focus at. Anyway I took a look at it and fixed the errors. It should compile now IF YOU HAVE THE SPARKFUN DRIVERS PROPERLY INSTALLED, else you will get errors such as error: 'ThumbState_t' does not name a type

The code should be as follows:
Code:
ThumbState_t thumbSt;

const bool DEBUG = false; // set to true to debug the raw values

int xPin = A2;
int yPin = A3;
int xZero, yZero;
int xValue, yValue;
int deadzone = 5; // smaller values will be set to 0


void setup(){
        pinMode(xPin, INPUT);
        pinMode(yPin, INPUT);
        if(DEBUG) {
                Serial.begin(9600);
        }
        // If at the neutral position you are reading a number too large, xZero will be positive, and get subtracted in the void loop, otherwise it will be negative, and get added.
        xZero = analogRead(xPin)-2048;
        yZero = analogRead(yPin)-2048;
        thumbSt.xAxis = 0;
        thumbSt.yAxis = 0;
}

void loop(){
xValue = analogRead(xPin) - xZero;
yValue = analogRead(yPin) - yZero;

//I'm pretty sure you need to keep the values between 0-4096, but I could be wrong
if( yValue < 0 ){
yValue = 0 ;
}
else if( yValue > 4096 ){
yValue = 4096;
}
if( xValue < 0 ){
xValue = 0;
}
else if( xValue > 4096 ){
xValue = 4096;
}

//I changed the deadzone stuff to work with values 0-4096
if(xValue< 2048+deadzone && xValue>2048-deadzone) {
xValue = 2048;
}
if(yValue< 2048+deadzone && yValue>2048-deadzone) {
yValue = 2048;
}

thumbSt.xAxis = map(xValue, 400, -400, -32768, 32768); // here the axis is inverted
thumbSt.yAxis = map(yValue, -400, 400, -32768, 32768);

if(DEBUG) {
Serial.print("X: ");
Serial.println(xValue);
Serial.print("Y: ");
Serial.println(yValue);
}

// Send to USB
Thumbstick.setState(&thumbSt);
}
 
Forgot your password?