Devices & Components
Analog joystick (Generic)
Resistor 221 ohm
Jumper wires (generic)
5 mm LED: Red
Breadboard (generic)
CP2102 USB to UART Module
Arduino Pro Mini 328 - 5V/16MHz
Hardware & Tools
Soldering iron (generic)
Software & Tools
Arduino IDE
Project description
Code
Joystick Example Code From Arduino Learning Board Library
c_cpp
1/* 2 * Arduino Learning Board Project - Dual Axis Joystick Example 3 * 4 * Please visit http://www.ArduinoLearningBoard.com for more information 5 * 6 * Last modified July 2016 by Jeff Shapiro <Jeff@ArduinoLearningBoard.com> 7 */ 8 9#define Vx A0 // Define / Equate "Vx" with A0, the pin where Vx is connected 10#define Vy A1 // Define / Equate "Vy" with A1, the pin where Vy is connected 11#define Button A2 // Define / Equate Button with A2, the pin where the button is connected 12 13void setup() 14{ 15 pinMode(Vx, INPUT); // Configure Vx (A0) as an Input 16 pinMode(Vy, INPUT); // Configure Vy (A1) as an Input 17 pinMode(Button, INPUT_PULLUP); // Configure Button (A2) as an Input, internally "pulled-up" to 5V 18 // Note, we're configuring an Analog input as digital input 19 // which is perfectly fine. I did this to make the wiring easier 20 // and keep all of the wires on the same side of the board 21 22 Serial.begin(9600); // Initialize Serial Port at 9600 baud to display the results 23} 24 25void loop() 26{ 27 int x, y, btn; 28 29 x = analogRead(Vx); // Read the analog value of Vx (Analog Values are from 0-1023 which equate to 0V to 5V) 30 y = analogRead(Vy); // Read the analog value of Vy 31 btn = digitalRead(Button); // Read the button. When the button is open (unpushed), 32 // the input will read High (+5V) 33 // When the button is closed (pressed), the input pin 34 // is connected to ground and will read Low (0V) 35 36 Serial.print(x); // Print the X value to the serial port 37 Serial.print("\ "); // Print a Tab character 38 Serial.print(y); // Print the Y value 39 Serial.print("\ "); // Print a Tab 40 Serial.println(btn); // Print the value of the Btn (0=Pushed, 1 = Not Pushed) 41 42 delay(250); // Delay 250ms so the results don't print too quickly 43}
Joystick Example Code From Arduino Learning Board Library
c_cpp
1/* 2 * Arduino Learning Board Project - Dual Axis Joystick Example 3 * 4 * Please visit http://www.ArduinoLearningBoard.com for more information 5 * 6 * Last modified July 2016 by Jeff Shapiro <Jeff@ArduinoLearningBoard.com> 7 */ 8 9#define Vx A0 // Define / Equate "Vx" with A0, the pin where Vx is connected 10#define Vy A1 // Define / Equate "Vy" with A1, the pin where Vy is connected 11#define Button A2 // Define / Equate Button with A2, the pin where the button is connected 12 13void setup() 14{ 15 pinMode(Vx, INPUT); // Configure Vx (A0) as an Input 16 pinMode(Vy, INPUT); // Configure Vy (A1) as an Input 17 pinMode(Button, INPUT_PULLUP); // Configure Button (A2) as an Input, internally "pulled-up" to 5V 18 // Note, we're configuring an Analog input as digital input 19 // which is perfectly fine. I did this to make the wiring easier 20 // and keep all of the wires on the same side of the board 21 22 Serial.begin(9600); // Initialize Serial Port at 9600 baud to display the results 23} 24 25void loop() 26{ 27 int x, y, btn; 28 29 x = analogRead(Vx); // Read the analog value of Vx (Analog Values are from 0-1023 which equate to 0V to 5V) 30 y = analogRead(Vy); // Read the analog value of Vy 31 btn = digitalRead(Button); // Read the button. When the button is open (unpushed), 32 // the input will read High (+5V) 33 // When the button is closed (pressed), the input pin 34 // is connected to ground and will read Low (0V) 35 36 Serial.print(x); // Print the X value to the serial port 37 Serial.print("\ "); // Print a Tab character 38 Serial.print(y); // Print the Y value 39 Serial.print("\ "); // Print a Tab 40 Serial.println(btn); // Print the value of the Btn (0=Pushed, 1 = Not Pushed) 41 42 delay(250); // Delay 250ms so the results don't print too quickly 43}
Downloadable files
Super Simple
Super Simple

Comments
Only logged in users can leave comments