Arduino/elegoo-kit-lessons/Lesson 12 Analog Joystick Module/Analog_Joystick/Analog_Joystick.ino

27 lines
622 B
Arduino
Raw Permalink Normal View History

2022-02-20 21:05:40 +00:00
//www.elegoo.com
//2016.12.09
// Arduino pin numbers
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output
void setup() {
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(9600);
}
void loop() {
Serial.print("Switch: ");
Serial.print(digitalRead(SW_pin));
Serial.print("\n");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pin));
Serial.print("\n\n");
delay(500);
}