Joystick Shield V1.A for Arduino
FunduinoPublished on
Sechs Taster und einen Joystick auf einem Shield auslesen
You need this
Joystick Shield V1.A - 2 axes, 2 buttons, for Arduino UNO
3,44 € *Item no. F23107178About the product — Joystick Shield V1.A - 2 axes, 2 buttons, for Arduino UNO
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
All 2 parts together 14,56 € *
* All prices include statutory VAT, plus shipping costs.
The Joystick Shield V1.A
Operating voltage and value range
The pinout
The program
Display the button and joystick position in the Serial Monitor
const byte KnopfA = 2; // The variables are declared
const byte KnopfB = 3; // We use the "const byte" declaration because each button is connected to its respective pin constantly ("const")
const byte KnopfC = 4;
const byte KnopfD = 5;
const byte KnopfE = 6;
const byte KnopfF = 7;
const byte KnopfK = 8;
const byte PinJoystickX = 0;
const byte PinJoystickY = 1;
int JoystickX;
int JoystickY;
boolean Agedruckt = false; // Set the variables to the default state "false" – the corresponding button is not pressed in the default state
boolean Bgedruckt = false;
boolean Cgedruckt = false;
boolean Dgedruckt = false;
boolean Egedruckt = false;
boolean Fgedruckt = false;
boolean Kgedruckt = false;
void setup() // Setup begins here
{
Serial.begin(9600);
pinMode(KnopfA, INPUT); // Button A now serves as an input and …
digitalWrite(KnopfA, HIGH); // … is set to the "HIGH" state
pinMode(KnopfB, INPUT);
digitalWrite(KnopfB, HIGH);
pinMode(KnopfC, INPUT);
digitalWrite(KnopfC, HIGH);
pinMode(KnopfD, INPUT);
digitalWrite(KnopfD, HIGH);
pinMode(KnopfE, INPUT);
digitalWrite(KnopfE, HIGH);
pinMode(KnopfF, INPUT);
digitalWrite(KnopfF, HIGH);
}
void loop() // The loop begins here
{
if(Agedruckt == digitalRead(KnopfA)) // When the button is pressed… (read using the "digitalRead()" command)
{
Serial.print("Button A pressed"); // …"Button A pressed" should be output
Serial.println();
}
if(Bgedruckt == digitalRead(KnopfB))
{
Serial.print("Button B pressed");
Serial.println();
}
if(Cgedruckt == digitalRead(KnopfC))
{
Serial.print("Button C pressed");
Serial.println();
}
if(Dgedruckt == digitalRead(KnopfD))
{
Serial.print("Button D pressed");
Serial.println();
}
if(Egedruckt == digitalRead(KnopfE))
{
Serial.print("Button E pressed");
Serial.println();
}
if(Fgedruckt == digitalRead(KnopfF))
{
Serial.print("Button F pressed");
Serial.println();
}
if(Kgedruckt == digitalRead(KnopfK))
{
Serial.print("Joystick button K pressed");
Serial.println();
}
// Next, the joystick position is read
JoystickX = analogRead(PinJoystickX); // The JoystickX variable stores the value of the X-axis
Serial.print("Joystick X-axis value is ");
Serial.println(JoystickX);
JoystickY = analogRead(PinJoystickY); // The JoystickY variable stores the value of the Y-axis
Serial.print("Joystick Y-axis value is ");
Serial.println(JoystickY);
Serial.println(); // Add blank lines so the output values are easy to read
Serial.println();
delay(1000); // The values (or button presses) should be output with a delay of 1000 ms (1 second)
}Rate the instructions