Skip to content

Instantly share code, notes, and snippets.

@elktros
Created July 5, 2018 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elktros/5705721ac772d50d7ad3757e9959358a to your computer and use it in GitHub Desktop.
Save elktros/5705721ac772d50d7ad3757e9959358a to your computer and use it in GitHub Desktop.
Code for interfacing a Joystick Module with Arduino UNO.
const int xPin = A0;
const int yPin = A1;
const int switchPin = 2;
int xValue;
int yValue;
int switchValue;
void setup()
{
Serial.begin(9600);
pinMode(switchPin, INPUT_PULLUP);
}
void loop()
{
switchValue = digitalRead(switchPin);
xValue = analogRead(xPin);
yValue = analogRead(yPin);
Serial.print("Switch: ");
Serial.print(switchValue);
Serial.print("\n");
Serial.print("X-axis: ");
Serial.print(xValue);
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.print(yValue);
Serial.print("\n\n");
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment