Skip to content

Latest commit

 

History

History
86 lines (56 loc) · 2.08 KB

joystick_ps2_uno.rst

File metadata and controls

86 lines (56 loc) · 2.08 KB

Lesson 16 Joystick PS2

Introduction

A joystick is an input device consisting of a stick that pivots on a base and reports its angle or direction to the device it is controlling. Joysticks are often used to control video games and robots. A Joystick PS2 is used here.

Components

image

  • SunFounder R3 Board
  • Breadboard
  • Jumper Wires
  • Joystick Module

Schematic Diagram

This module has two analog outputs (corresponding to X,Y biaxial offsets) and one digital output representing whether it is pressed on Z axis. The module integrates power indicator and can display operation condition.

In this experiment, we use the Uno board to detect the moving direction of the Joystick knob and pressing of the button.

image

Experimental Procedures

Step 1: Build the circuit.

image

Step 2: Open the code file.

Step 3: Select the Board and Port.

Step 4: Upload the sketch to the board.

Now, push the rocker and the coordinates of X and Y axes displayed on Serial Monitor will change accordingly; press the button, and the coordinate of Z=0 will also be displayed.

image

Code

Code Analysis

The code is use the serial monitor to print the value of the VRX,VRY and SW pins of the joystick ps2.

void loop()
{
    Serial.print("X: "); 
    Serial.print(analogRead(xPin), DEC);  // print the value of VRX in DEC
    Serial.print("|Y: ");
    Serial.print(analogRead(yPin), DEC);  // print the value of VRX in DEC
    Serial.print("|Z: ");
    Serial.println(digitalRead(swPin));   // print the value of SW
    delay(50);
}