i made a arduino program that sends joystick info like: "X,Y,SpeedPot,btn1,btn2,btn3,btn" 4 x, y and speedpot are values 1023 to 0 depending on where joystick is, and btn1... are 1 or 0 depending on if the buttons are triggered or not on the joystick. real output like: 563,521,411,1,1,1,1
SEE 2nd reply for C# code and new quesion...
Arduino Code:
//-----Axis-------------------------------------------------------//
#define Xaxis 3 //Joystick X axis Analog pin 3
#define Yaxis 4 //Joystick Y axis Analog pin 4
#define SpeedPot 5 //Pot in base for speed, Analog pin 5
int XaxisVar = 0; //...analog pin 3---X axis
int YaxisVar = 0; //...analog pin 4---Y axis
int SpeedVar = 0; //...analog pin 5---Speed pot
//----------------------------------------------------------------//
//-----Buttons----------------------------------------------------//
#define TrigBtn 2 //trigger button, digital 2
#define MidBtn 6 //Button below trigger on joystick, digital 3
#define LowBtn 4 //Lowest button on the joystick, digital 4
#define BaseBtn 5 //button on base of joystick, digital 5
int TrigBtnState = 0; //Stores the state of TrigBtn
int MidBtnState = 0; //...MidBtnState
int LowBtnState = 0; //...LowBtnState
int BaseBtnState = 0; //...BaseBtnState
//----------------------------------------------------------------//
void setup()
{
Serial.begin(9600);
for (int pin=2; pin<=5; ++pin) //sets all digital pin 2-5 as input and enables internal pullups for buttons
{
pinMode(pin, INPUT); //sets button pins to input
digitalWrite(pin, HIGH); // sets the pull up.
}
}
void loop()
{
XaxisVar = analogRead(Xaxis); //Read X-Axis postion
YaxisVar = analogRead(Yaxis); //Read Y-Axis postion
SpeedVar = analogRead(SpeedPot); //Read Speed Pot postion
TrigBtnState = digitalRead(TrigBtn); //read status of buttons on joystick
MidBtnState = digitalRead(MidBtn); //...
LowBtnState = digitalRead(LowBtn); //...
BaseBtnState = digitalRead(BaseBtn); //...
//Just serial ouput formatting...
String Comma = String(",");
String Data = String(XaxisVar + Comma + YaxisVar + SpeedVar + TrigBtnState + Comma + MidBtnState + Comma + LowBtnState + Comma + BaseBtnState);
Serial.println(Data);
}
also, as you can see here:
String Comma = String(",");
String Data = String(XaxisVar + Comma + YaxisVar + SpeedVar + TrigBtnState + Comma + MidBtnState + Comma + LowBtnState + Comma + BaseBtnState);
Serial.println(Data);
i have to make a "," string and i cant put a real comma in the data string like "," because it gives me an error, something about overflow.
also it maybe a coincidence, but my computer severely lagged for 5 minutes after i ran the compiled C# program, then i forced stopped it in task manger(still ran after closing CMD) and it recovered a few minutes later.
thanks