Components and supplies
Resistor 330 ohm
LED (generic)
Resistor 10k ohm
Pushbutton Switch, Pushbutton
Inertial Measurement Unit (IMU) (6 deg of freedom)
Arduino Micro
PCBWay Custom PCB
Tools and machines
Tweezers, SMD Soldering/Desoldering
Apps and platforms
Arduino IDE
Project description
Code
Code snippet #1
text
1/*** PCB Steer Gaming Wheel *** 2 * 3 * Author: Ashraf Minhaj 4 * Mail: ashraf_minhaj@yahoo.com 5 * 6 * Licence: Copyright (C) Ashraf Minhaj 7 * GNU General Public License v3.0 8 */ 9 10 11#include <Keyboard.h> 12#include<Wire.h> 13 14// Threshold value for steering 15int THRESHOLD = 4000; 16 17// Controller buttons 18int brake = 5; 19int nitro = 6; 20int pedal = 4; 21 22// Indicator LEDs 23int left_led = 8; 24int right_led = 9; 25 26int x; 27int y; 28int z; 29 30const int MPU_addr=0x68; // I2C address of the MPU-6050 31 32void indicator_blink() 33{ 34 // blinks the leds - 5 times 35 int i = 0; 36 37 for(i=0; i<5; i++){ 38 digitalWrite(left_led, HIGH); 39 digitalWrite(right_led, HIGH); 40 delay(100); 41 digitalWrite(left_led, LOW); 42 digitalWrite(right_led, LOW); 43 delay(100); 44 } 45} 46 47void setup(){ 48 // set pin mode and initialize things 49 pinMode(brake, INPUT); 50 pinMode(nitro, INPUT); 51 pinMode(pedal, INPUT); 52 53 pinMode(left_led, OUTPUT); 54 pinMode(right_led, OUTPUT); 55 56 Serial.begin(9600); 57 58 Wire.begin(); 59 Wire.beginTransmission(MPU_addr); 60 Wire.write(0x6B); // PWR_MGMT_1 register 61 Wire.write(0); // set to zero (wakes up the MPU-6050) 62 Wire.endTransmission(true); 63 64 indicator_blink(); 65} 66 67void loop() 68{ // Main loop that runs forever 69 70 Wire.beginTransmission(MPU_addr); 71 Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) 72 Wire.endTransmission(false); 73 Wire.requestFrom(MPU_addr, 14, true); // request a total of 14 registers 74 75 x = Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L) 76 y = Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L) 77 z = Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L) 78 79 80 if (digitalRead(brake)){ 81 Keyboard.release(KEY_UP_ARROW); 82 Keyboard.press(KEY_DOWN_ARROW); 83 //Keyboard.press(217); 84 } 85 86 if (digitalRead(nitro)){ 87 delay(10); 88 Keyboard.press('z'); 89 if (digitalRead(nitro)){ 90 Keyboard.press('A'); 91 } 92 } 93 94 else if (digitalRead(pedal)){ 95 Keyboard.release(KEY_DOWN_ARROW); 96 Keyboard.press(KEY_UP_ARROW); 97 //Keyboard.press(218); 98 99 if(y < -THRESHOLD){ 100 Serial.print(" Left "); 101 Keyboard.release(KEY_RIGHT_ARROW); 102 Keyboard.press(KEY_LEFT_ARROW); 103 digitalWrite(left_led, HIGH); 104 } 105 106 else if(y > THRESHOLD){ 107 Serial.print(" Right "); 108 Keyboard.release(KEY_LEFT_ARROW); 109 Keyboard.press(KEY_RIGHT_ARROW); 110 digitalWrite(right_led, HIGH); 111 //Keyboard.press(37); 112 } 113 else{ 114 Keyboard.releaseAll(); 115 } 116 } 117 118 //Serial.println(y); 119 delay(10); 120 digitalWrite(left_led, LOW); 121 digitalWrite(right_led, LOW); 122}
Github
https://github.com/ashraf-minhaj/Gyro-Gaming-Wheel
Code snippet #1
text
1/*** PCB Steer Gaming Wheel *** 2 * 3 * Author: Ashraf Minhaj 4 * Mail: ashraf_minhaj@yahoo.com 5 * 6 * Licence: Copyright (C) Ashraf Minhaj 7 * GNU General Public License v3.0 8 */ 9 10 11#include <Keyboard.h> 12#include<Wire.h> 13 14// Threshold value for steering 15int THRESHOLD = 4000; 16 17// Controller buttons 18int brake = 5; 19int nitro = 6; 20int pedal = 4; 21 22// Indicator LEDs 23int left_led = 8; 24int right_led = 9; 25 26int x; 27int y; 28int z; 29 30const int MPU_addr=0x68; // I2C address of the MPU-6050 31 32void indicator_blink() 33{ 34 // blinks the leds - 5 times 35 int i = 0; 36 37 for(i=0; i<5; i++){ 38 digitalWrite(left_led, HIGH); 39 digitalWrite(right_led, HIGH); 40 delay(100); 41 digitalWrite(left_led, LOW); 42 digitalWrite(right_led, LOW); 43 delay(100); 44 } 45} 46 47void setup(){ 48 // set pin mode and initialize things 49 pinMode(brake, INPUT); 50 pinMode(nitro, INPUT); 51 pinMode(pedal, INPUT); 52 53 pinMode(left_led, OUTPUT); 54 pinMode(right_led, OUTPUT); 55 56 Serial.begin(9600); 57 58 Wire.begin(); 59 Wire.beginTransmission(MPU_addr); 60 Wire.write(0x6B); // PWR_MGMT_1 register 61 Wire.write(0); // set to zero (wakes up the MPU-6050) 62 Wire.endTransmission(true); 63 64 indicator_blink(); 65} 66 67void loop() 68{ // Main loop that runs forever 69 70 Wire.beginTransmission(MPU_addr); 71 Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) 72 Wire.endTransmission(false); 73 Wire.requestFrom(MPU_addr, 14, true); // request a total of 14 registers 74 75 x = Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L) 76 y = Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L) 77 z = Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L) 78 79 80 if (digitalRead(brake)){ 81 Keyboard.release(KEY_UP_ARROW); 82 Keyboard.press(KEY_DOWN_ARROW); 83 //Keyboard.press(217); 84 } 85 86 if (digitalRead(nitro)){ 87 delay(10); 88 Keyboard.press('z'); 89 if (digitalRead(nitro)){ 90 Keyboard.press('A'); 91 } 92 } 93 94 else if (digitalRead(pedal)){ 95 Keyboard.release(KEY_DOWN_ARROW); 96 Keyboard.press(KEY_UP_ARROW); 97 //Keyboard.press(218); 98 99 if(y < -THRESHOLD){ 100 Serial.print(" Left "); 101 Keyboard.release(KEY_RIGHT_ARROW); 102 Keyboard.press(KEY_LEFT_ARROW); 103 digitalWrite(left_led, HIGH); 104 } 105 106 else if(y > THRESHOLD){ 107 Serial.print(" Right "); 108 Keyboard.release(KEY_LEFT_ARROW); 109 Keyboard.press(KEY_RIGHT_ARROW); 110 digitalWrite(right_led, HIGH); 111 //Keyboard.press(37); 112 } 113 else{ 114 Keyboard.releaseAll(); 115 } 116 } 117 118 //Serial.println(y); 119 delay(10); 120 digitalWrite(left_led, LOW); 121 digitalWrite(right_led, LOW); 122}
Github
https://github.com/ashraf-minhaj/Gyro-Gaming-Wheel
Downloadable files
Schematic
Schematic
Comments
Only logged in users can leave comments