My Thingiverse page for this project: https://www.thingiverse.com/thing:5155241
A tiny Arduino-powered USB joystick mouse with 3D printed enclosure and right and left click functionality
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
My Thingiverse page for this project: https://www.thingiverse.com/thing:5155241
Arduino_Joystick_Mouse_Enclosure.stlEnclosure for a joystick mouse made from an Arduino Pro Micro, joystick module, and tac switch. Margins are tight, so recommend lightly filing the inner tracks of the enclosure, and/or the rough sides of the boards themselves to slide them in easier. The solder points on the Arduino also need to be low profile and facing inward, and the excess solder under the joystick board needs to be clipped off.Standard Tesselated Geometry - 13.37 kB - 05/24/2023 at 16:20 |
|
/* HID Joystick Mouse Example by: Jim Lindblom date: 1/12/2012 license: MIT License - Feel free to use this code for any purpose. No restrictions. Just keep this license if you go on to use this code in your future endeavors! Reuse and share. This is very simplistic code that allows you to turn the SparkFun Thumb Joystick (http://www.sparkfun.com/products/9032) into an HID Mouse. The select button on the joystick is set up as the mouse left click. */ #include <mouse.h> int horzPin = A0; // Analog output of horizontal joystick pin int vertPin = A1; // Analog output of vertical joystick pin int selPin = 3; // select button pin of joystick int rclPin = 2; // select button pin of joystick int vertZero, horzZero; // Stores the initial value of each axis, usually around 512 int vertValue, horzValue; // Stores current analog output of each axis const int sensitivity = 100; // Higher sensitivity value = slower mouse, should be <= about 500 int mouseClickFlag = 0; int rightClickFlag = 0; //int invertMouse = -1; //Invert joystick based on orientation int invertMouse = -1; //Noninverted joystick based on orientation void setup() { pinMode(horzPin, INPUT); // Set both analog pins as inputs pinMode(vertPin, INPUT); pinMode(selPin, INPUT); // set button select pin as input digitalWrite(selPin, HIGH); // Pull button select pin high pinMode(rclPin, INPUT); // set button select pin as input digitalWrite(rclPin, HIGH); // Pull button select pin high delay(1000); // short delay to let outputs settle vertZero = analogRead(vertPin); // get the initial values horzZero = analogRead(horzPin); // Joystick should be in neutral position when reading these Mouse.begin(); //Init mouse emulation } void loop() { vertValue = analogRead(vertPin) - vertZero; // read vertical offset horzValue = analogRead(horzPin) - horzZero; // read horizontal offset if (vertValue != 0) Mouse.move(0, (invertMouse * (vertValue / sensitivity)), 0); // move mouse on y axis if (horzValue != 0) Mouse.move(((horzValue / sensitivity)), 0, 0); // move mouse on x axis if ((digitalRead(selPin) == 0) && (!mouseClickFlag)) // if the joystick button is pressed { mouseClickFlag = 1; Mouse.press(MOUSE_LEFT); // click the left button down } else if ((digitalRead(selPin)) && (mouseClickFlag)) // if the joystick button is not pressed { mouseClickFlag = 0; Mouse.release(MOUSE_LEFT); // release the left button } if ((digitalRead(rclPin) == 0) && (!rightClickFlag)) // if the joystick button is pressed { rightClickFlag = 1; Mouse.press(MOUSE_RIGHT); // click the left button down } else if ((digitalRead(rclPin)) && (rightClickFlag)) // if the joystick button is not pressed { rightClickFlag = 0; Mouse.release(MOUSE_RIGHT); // release the left button } }</mouse.h>
Print enclosure and file down inner tracks so that the joystick PCB slides in easily
De-solder pins from joystick breakout board
Use wires to make the following solder connections:
Solder GND on Joystick to GND on Arduino
Solder 5V on Joystick to VCC on Arduino
Solder VRX on Joystick to A0 on Arduino
Solder VRY on Joystick to A1 on Arduino
Solder SW on Joystick to Pin 9 on Arduino
Solder tac button to Arduino using GND and Pin 2, insulate with heat shrink tubing
Connect Adruino to PC and upload code using Arduino IDE
Disconnect and reconnect Arduino and it should be detected as a mouse input
Create an account to leave a comment. Already have an account? Log In.
Become a member to follow this project and never miss any updates
By using our website and services, you expressly agree to the placement of our performance, functionality, and advertising cookies. Learn More