Hello everyone, arduino beginner here!
Could use some guidance form my fs joystick project. Im making joystick and buttonbox but im having some difficulties to set a deadzone for my joystick. I made the joystick my self with 3D printer so it is little wobly and the potentiometers don't turn as much as normal analog tumbstick. There is 3 buttons in joystick that are working. I want also add 12 button for the buttonbox using matrix 4x3. Using arduino micro.
I made it so far that it is working but i wasn't able to include the deadzone, any tips for code? It isnt really working in game, hard to map when there is no deadzone. Calibrated it through w10 gaming controller setup.
Also could take tips for code to make 4x3 matrix base for buttonbox.
#include <Joystick.h>
#define joyX A2
#define joyY A3
#define joyRZ A0
#define joyThrottle A1
#define joyButton1 2
#define joyButton2 3
#define joyButton3 4
//#define numMatxButtons 12
//#define numRows 4
//#define numCols 3
int xAxis_ = 0;
int yAxis_ = 0;
int rzAxis_ = 0;
int throttle_ = 0;
//joystick buttons
int lastButton1State = 0;
int lastButton2State = 0;
int lastButton3State = 0;
Joystick_ Joystick(0x12, JOYSTICK_TYPE_JOYSTICK, 15, 0,true,true,false,false,false,true,false,true,false,false,false);
const bool initAutoSendState = true;
void setup() {
pinMode(joyButton1, INPUT_PULLUP);
pinMode(joyButton2, INPUT_PULLUP);
pinMode(joyButton3, INPUT_PULLUP);
Joystick.begin();
}
void loop() {
xAxis_ = analogRead(joyX);
Joystick.setXAxis(xAxis_);
yAxis_ = analogRead(joyY);
Joystick.setYAxis(yAxis_);
rzAxis_ = analogRead(joyRZ);
rzAxis_ = map(rzAxis_,0,490,0,410);
Joystick.setRzAxis(rzAxis_);
throttle_ = analogRead(joyThrottle);
throttle_ = map(throttle_,0,490,0,410);
Joystick.setThrottle(throttle_);
int currentButton1State = !digitalRead(joyButton1);
if (currentButton1State != lastButton1State){
Joystick.setButton(1, currentButton1State);
lastButton1State = currentButton1State;
}
int currentButton2State = !digitalRead(joyButton2);
if (currentButton2State != lastButton2State){
Joystick.setButton(2, currentButton2State);
lastButton2State = currentButton2State;
}
int currentButton3State = !digitalRead(joyButton3);
if (currentButton3State != lastButton3State){
Joystick.setButton(3, currentButton3State);
lastButton3State = currentButton3State;
}
delay(10);
}