Alternative controller with a gun and joystick for FPS games
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
Modeles 3D gun.zipFinal 3D models of the gun, as you can see it actually looks like a gun now.x-zip-compressed - 601.10 kB - 12/20/2024 at 21:34 |
|
|
Canon.stlhere is then3d model of the canonStandard Tesselated Geometry - 57.99 kB - 12/17/2024 at 08:35 |
|
|
Fw_ STL.zipFolder containing the 3D models of the gunx-zip-compressed - 67.12 kB - 12/17/2024 at 08:22 |
|
here is the actual final arduino code, we added some LEDs and sounds to mimic the effects of an actua sound, for example a sound when you're aiming and when you shoot a little light will turn on mimicking the muzzle flash of an actual gun.
#include <Mouse.h>
#include "Keyboard.h"
// Joystick Pins
int horzPin = A0; // Analog pin for horizontal joystick
int vertPin = A1; // Analog pin for vertical joystick
int selPin = 8; // Joystick button (select pin)
// Joystick Center Calibration
int vertZero, horzZero; // Joystick center positions
int vertValue, horzValue; // Joystick axis readings
const float sensitivity = 0.3; // Adjust mouse sensitivity (lower = slower movement)
int deadZone = 3; // Minimum offset to ignore small joystick movements
// Button Pin Assignments
const int buttonWheelUp = 2; // Button for Mouse Wheel Up (Zoom)
const int buttonWheelDown = 3;
const int buttonMouseClick = 4; // Button for Left Mouse Click
const int buzzerPin = 6; // Pin connected to the buzzer
const int ledPin = 7; // Pin connected to the LED
void setup() {
Serial.begin(9600); // Start Serial Monitor for debugging
// Joystick Setup
pinMode(horzPin, INPUT);
pinMode(vertPin, INPUT);
pinMode(selPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin+, OUTPUT);
// Button Setup
pinMode(buttonWheelUp, INPUT_PULLUP);
pinMode(buttonWheelDown, INPUT_PULLUP);
pinMode(buttonMouseClick, INPUT_PULLUP);
// Calibrate Joystick Neutral Position
vertZero = analogRead(vertPin);
horzZero = analogRead(horzPin);
Serial.println("Joystick Calibration:");
Serial.print("Center Vertical Value: ");
Serial.println(vertZero);
Serial.print("Center Horizontal Value: ");
Serial.println(horzZero);
Mouse.begin(); // Initialize Mouse Emulation
Keyboard.begin(); // Initialize Keyboard Emulation
}
void loop() {
// --- Joystick Movement ---
vertValue = analogRead(vertPin) - vertZero; // Vertical deviation from center
horzValue = analogRead(horzPin) - horzZero; // Horizontal deviation from center
// Dead Zone Filter to ignore small offsets
if (abs(vertValue) < deadZone) vertValue = 0;
if (abs(horzValue) < deadZone) horzValue = 0;
// Debug output for raw joystick values
Serial.print("Raw Vertical: ");
Serial.print(vertValue);
Serial.print(" | Raw Horizontal: ");
Serial.println(horzValue);
// Scale joystick values for smoother and slower mouse movement
int scaledVertValue = map(vertValue, -512, 512, 5, -5); // Inverted Y-axis
int scaledHorzValue = map(horzValue, -512, 512, 5, -5); // Inverted X-axis
// Debug output for scaled values
Serial.print("Scaled Vertical: ");
Serial.print(scaledVertValue);
Serial.print(" | Scaled Horizontal: ");
Serial.println(scaledHorzValue);
// Apply Mouse Movement (inverted axes)
if (scaledVertValue != 0) { // Move only if outside the dead zone
Mouse.move(0, scaledVertValue); // Vertical movement (Y-axis)
}
if (scaledHorzValue != 0) {
Mouse.move(scaledHorzValue, 0); // Horizontal movement (X-axis)
}
// --- Joystick Button (Space Bar) ---
if (digitalRead(selPin) == LOW) { Keyboard.press(' '); // Press Spacebar
delay(50); // Debounce delay
Keyboard.release(' ');
}
// --- Button 1: Mouse Wheel Up (Zoom) ---
if (digitalRead(buttonWheelUp) == LOW) { Mouse.move(0, 0, 1); // Simulate Mouse Wheel Up
delay(50); // Debounce delay
for (int freq = 200; freq <= 2000; freq++) { // Frequency increases from...
We have made a few modifications to the code, here is the new version:
#include <Mouse.h>
#include "Keyboard.h"
// Joystick Pins
int horzPin = A0; // Analog pin for horizontal joystick
int vertPin = A1; // Analog pin for vertical joystick
int selPin = 8; // Joystick button (select pin)
// Joystick Center Calibration
int vertZero, horzZero; // Joystick center positions
int vertValue, horzValue; // Joystick axis readings
const float sensitivity = 0.5; // Adjust mouse sensitivity (lower = slower movement)
int deadZone = 10; // Minimum offset to ignore small joystick movements
// Button Pin Assignments
const int buttonWheelUp = 2; // Button for Mouse Wheel Up (Zoom)
const int buttonMouseClick = 3; // Button for Left Mouse Click
void setup() {
Serial.begin(9600); // Start Serial Monitor for debugging
// Joystick Setup
pinMode(horzPin, INPUT);
pinMode(vertPin, INPUT);
pinMode(selPin, INPUT_PULLUP);
// Button Setup
pinMode(buttonWheelUp, INPUT_PULLUP);
pinMode(buttonWheelDown, INPUT_PULLUP);
pinMode(buttonMouseClick, INPUT_PULLUP);
// Calibrate Joystick Neutral Position
vertZero = analogRead(vertPin);
horzZero = analogRead(horzPin);
Serial.println("Joystick Calibration:");
Serial.print("Center Vertical Value: ");
Serial.println(vertZero);
Serial.print("Center Horizontal Value: ");
Serial.println(horzZero);
Mouse.begin(); // Initialize Mouse Emulation
Keyboard.begin(); // Initialize Keyboard Emulation
}
void loop() {
// --- Joystick Movement ---
vertValue = analogRead(vertPin) - vertZero; // Vertical deviation from center
horzValue = analogRead(horzPin) - horzZero; // Horizontal deviation from center
// Dead Zone Filter to ignore small offsets
if (abs(vertValue) < deadZone) vertValue = 0;
if (abs(horzValue) < deadZone) horzValue = 0;
// Debug output for raw joystick values
Serial.print("Raw Vertical: ");
Serial.print(vertValue);
Serial.print(" | Raw Horizontal: ");
Serial.println(horzValue);
// Scale joystick values for smoother and slower mouse movement
int scaledVertValue = map(vertValue, -512, 512, 5, -5); // Inverted Y-axis
int scaledHorzValue = map(horzValue, -512, 512, 5, -5); // Inverted X-axis
// Debug output for scaled values
Serial.print("Scaled Vertical: ");
Serial.print(scaledVertValue);
Serial.print(" | Scaled Horizontal: ");
Serial.println(scaledHorzValue);
// Apply Mouse Movement (inverted axes)
if (scaledVertValue != 0) { // Move only if outside the dead zone
Mouse.move(0, scaledVertValue); // Vertical movement (Y-axis)
}
if (scaledHorzValue != 0) {
Mouse.move(scaledHorzValue, 0); // Horizontal movement (X-axis)
}
// --- Joystick Button (Space Bar) ---
if (digitalRead(selPin) == LOW) { Keyboard.press(' '); // Press Spacebar
delay(50); // Debounce delay
Keyboard.release(' ');
}
// --- Button 1: Mouse Wheel Up (Zoom) ---
if (digitalRead(buttonWheelUp) == LOW) { Mouse.move(0, 0, 1); // Simulate Mouse Wheel Up
delay(50); // Debounce delay
}
// --- Button 2: Left Mouse Click ---
if (digitalRead(buttonMouseClick) == LOW) { Mouse.click(MOUSE_LEFT); // Perform Left Mouse Click
delay(50); // Debounce delay
}
}
After trying to solve the code for multiple weeks, we changed the wiring as well, however that did not work but we have finally fixed the code so here it is, and the v2 gun is almost finished as well so here's the code:
#include <Mouse.h>
#include "Keyboard.h"
int horzPin = A0; // Analog pin for horizontal joystick
int vertPin = A1; // Analog pin for vertical joystick
int selPin = 8; // Joystick button (select pin)
int vertZero, horzZero; // Stores joystick center values
int vertValue, horzValue; // Stores joystick axis readings
const float sensitivity = 200.0; // Sensitivity (float for precision)
int mouseClickFlag = 0;
int invertMouse = -1; // Non-inverted movement
// Button pin assignments
const int buttonW = 2; // Button for printing 'W'
const int buttonS = 3; // Button for printing 'S'
const int buttonMouseClick = 4; // Button for mouse left click
void setup() {
// Joystick setup
pinMode(horzPin, INPUT);
pinMode(vertPin, INPUT);
pinMode(selPin, INPUT_PULLUP);
vertZero = analogRead(vertPin); // Calibrate initial neutral position
horzZero = analogRead(horzPin);
Mouse.begin(); // Initialize mouse emulation
Keyboard.begin(); // Initialize keyboard emulation
// Button setup
pinMode(buttonW, INPUT_PULLUP); // Button for 'W'
pinMode(buttonS, INPUT_PULLUP); // Button for 'S'
pinMode(buttonMouseClick, INPUT_PULLUP); // Button for mouse left click
}
void loop() {
// --- Joystick Movement ---
vertValue = analogRead(vertPin) - vertZero; // Vertical movement
horzValue = analogRead(horzPin) - horzZero; // Horizontal movement
if (abs(vertValue) > 5) { // Ignore small offsets
Mouse.move(0, vertValue / sensitivity); // Move mouse vertically
}
if (abs(horzValue) > 5) { // Ignore small offsets
Mouse.move(invertMouse * horzValue / sensitivity, 0); // Move mouse horizontally
}
// --- Joystick Button (Print 'R') ---
if (digitalRead(selPin) == LOW) { Keyboard.print("R"); // Print 'R' when joystick button is pressed
delay(50); // Debounce delay
}
// --- Button 1: Print 'W' Continuously ---
if (digitalRead(buttonW) == LOW) { Keyboard.print("W"); // Print 'W' while button is held
delay(50); // Typing rate
}
// --- Button 2: Print 'S' Continuously ---
if (digitalRead(buttonS) == LOW) { Keyboard.print("S"); // Print 'S' while button is held
delay(50); // Typing rate
}
// --- Button 3: Simulate Left Mouse Click ---
if (digitalRead(buttonMouseClick) == LOW) { Mouse.click(MOUSE_LEFT); // Perform a mouse left click
delay(50); // Avoid multiple rapid clicks
}
}
Our idea is to emulate the keys of a keyboard from buttons that are controlled by arduino. Problem is that it writing wtihout any input and deletes the codes. Here is the code:
#include <Keyboard.h>
#include <Mouse.h>
void setup() {
Keyboard.begin();
pinMode(8, INPUT);
pinMode(7, INPUT);
pinMode(6, INPUT);
Mouse.begin();
}
void loop() {
if (digitalRead(8) == HIGH) {
Keyboard.press('w');
Keyboard.releaseAll();
delay(10);
}
if (digitalRead(7) ==HIGH ) {
Keyboard.press('s');
Keyboard.releaseAll();
delay(10);
}
if (digitalRead(6) == HIGH) {
Mouse.click();
delay(10);
}
}
We have also 3D printed the first prototype of our gun, which will store all of the buttons.
Doesn't look good but we have v2 on the way because the upperpart was too small
We have encoutenred a bit of a problem, the games we had anticipated to modify, such as lehtal company, outlast and escape the backrooms, are not compatible with arduino, so we have scrapped that plan.
So our plan has changed now we're thinking of changing genres and going for a FPS.
Our main goal is to create a controller for a horror game, the idea is to pair a game with a heart sensor, a nosie detector 3 buttons, one for a lamp, one to interact and one for inventory and a joystick. Here is a quick draft of how it will look like.
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