// #include <BleKeyboard.h>
// const int JoyStick_pin = 8; //plug Joystick 'Button' into pin 8
const int X_pin = 2; //plug joystick X direction into pin A0
const int Y_pin = 17; //plug joystick Y direction into pin A1
int xc=1;
int yc=1;
int JSButton;
void setup() {
pinMode(X_pin, INPUT_PULLUP);
pinMode(Y_pin, INPUT_PULLUP);
Serial.begin(115200);
}
void loop() {
int x = analogRead(X_pin) - 347; //read x direction value and -517 to bring back to around 0
int y = analogRead(Y_pin) - 340; //read y direction value and -512 to bring back to around 0
if (x <-40) { //joystick has off set of +/-8 so this negates that
xc = 0; //turn analogue value into integer. 0, 1 or 2 depending on state
// bleKeyboard.press(KEY_LEFT_CTRL);
} else if (x >40) {
xc = 2;
} else {
xc = 1;
}
if (y <-40) {
yc = 0;
}
else if (y >40) {
yc = 2;
} else {
yc = 1;
}
int buttonStates = 0; //set starting value of Joystick button
// buttonStates |= ((digitalRead(JoyStick_pin) == LOW) ? 1 : 0) << 0;
//start printing the data, format is Sxc,yc,buttonStates > S1,1,0
Serial.print("S");
Serial.print(xc);
Serial.print(",");
Serial.print(yc);
Serial.print(",");
Serial.println((buttonStates));
delay(40);
}