de:arduino:joystick

Joystick

Joystick

Das Modul vermittelt das Gefühl der 80er und 90er Jahre und ist eine universelle Steuerung. Zusätzlich zur Richtungsauswahl enthält es auch einen Druckknopf. Die Richtungsmarkierungen (x, y) werden über analoge Signale gelesen, so dass zusätzlich zu den vier Hauptrichtungen die Positionsbestimmung sehr flexibel sein kann.

pinBeschreibung
GNDGrund
+ 5VStromversorgung
VRxAnalog (0..1024) X-Positionskomponente
VRyAnaloge (0..1024) Y-Positionskomponente
SWDigitales Signal (nach Drücken der Taste)

Joystick

Joystick Verdrahtung

// OB121.com Joystick demo - Vámos Sándor 2018
 
#define joystickX A0            // X axe PIN A0.
#define joystickY A1            // Y axe PIN A1.
int button =  5;                // Press key at PIN 5
const int PAUSE = 250;          // wait
long lastAction = -1;           // time stamp
void setup() {
  Serial.begin(9600);           // komm with 9600 baud
 
  // Der Druckknopf wird durch einen Pull-up-Widerstand definiert, 
  // dh die Signale werden auf LOW == HIGH und HIGH == LOW negiert
 
  pinMode(button, INPUT_PULLUP);
}
void loop() {
  // act ms state
  long currentTimestamp = millis(); 
  // wait
  if(lastAction < (currentTimestamp-PAUSE)){
  lastAction = currentTimestamp; 
 
  // positions from joystick
  int x = analogRead(joystickX);
  int y = analogRead(joystickY);
  Serial.print("The current coordinates of the joystick (x,y): ");
  Serial.print(x);
  Serial.print(", ");
  Serial.println(y);
  }
 
  // Push button query
  if(digitalRead(button)==LOW){
  Serial.println("The button has been pressed.");
  }
}
  • de/arduino/joystick.txt
  • 2022/04/21 15:00
  • ()