/* Demonstration sketch for combo analog and digital joystick
PM Wiegand October 1 2025
Widely available on Amazon – search analog joystick
Connect VRX and VRY to analog input pins on microcontroller
Connect SW to a digital input (INPUT_PULLUP) pin on microcontroller
Output printed to Serial Monitor, can also visualize with Serial Plotter
*/
constexpr int SWPIN= 2;
constexpr int VRXPIN= A2;
constexpr int VRYPIN= A3;
constexpr unsigned long MSDELAY= 300;
void setup(){
Serial.begin(9600);
pinMode(SWPIN, INPUT_PULLUP);
}
void loop(){
bool swState = !digitalRead(SWPIN); // putting the ! (not) character flips the logic so depressed returns true
int VRXRead = analogRead(VRXPIN);
int VRYRead = analogRead(VRYPIN);
Serial.print("SW VRX VRY ");
Serial.print(swState*1000); //multiply by 1000 to get on same scale as analog for plotting
Serial.print(", ");
Serial.print(VRXRead);
Serial.print(", ");
Serial.println(VRYRead);
delay(MSDELAY);
}