diff --git a/README.md b/README.md index 2ceb1e2..670953d 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ This repository houses several Arduino .ino files for use with an Arduino Leonar Allows you to transform it into a a USB game controller for use with [Clone Hero](https://clonehero.net)/[DTXAL](http://senamih.com/dtxal)/Guitar Hero/GuitarFreaks/Gitadora. +For instructions on how to convert an existing guitar into one, [check the wiki here](https://github.com/limyz/573controller/wiki/DIY-Guitar). + * _iidx Allows you to transform it into a IIDX controller with full native support for [beatmania IIDX INFINITAS](https://p.eagate.573.jp/game/eac2dx/infinitas). diff --git a/_gfxg_adxl345.ino b/_gfxg_adxl345/_gfxg_adxl345.ino similarity index 96% rename from _gfxg_adxl345.ino rename to _gfxg_adxl345/_gfxg_adxl345.ino index 5bd596c..255baac 100644 --- a/_gfxg_adxl345.ino +++ b/_gfxg_adxl345/_gfxg_adxl345.ino @@ -1,127 +1,127 @@ -//-------------------------------------------------------------------- -// For use with a 573 or GH Guitar Controller -// -// This sketch maps a ADXL345 accelerometer via I2C and uses 7 digital -// inputs - 5 buttons and a 2 hat switches for the pick. -// -// All digital pins are grounded when they are pressed. -// -// NOTE: This sketch file is for use with Arduino Leonardo and -// Micro only. -// -// by lyzzz -// 2019-07-25 -//-------------------------------------------------------------------- - -#include -#include -#include -#include - -/* Assign a unique ID to this sensor at the same time */ -Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(573); - -Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD, - 5, 1, // Button Count, Hat Switch Count - true, true, true, // X, Y and Z Axis - false, false, false, // No Rx, Ry, or Rz - false, false, // No rudder or throttle - false, false, false); // No accelerator, brake, or steering - -void setup() { - // Initialize Button Pins - // Pins 2 and 3 are reserved for I2C - //pinMode(2, INPUT_PULLUP); - //pinMode(3, INPUT_PULLUP); - - // Pins 5 to 9 -> R, G, B, Y, P - pinMode(4, INPUT_PULLUP); - pinMode(5, INPUT_PULLUP); - pinMode(6, INPUT_PULLUP); - pinMode(7, INPUT_PULLUP); - pinMode(8, INPUT_PULLUP); - - // Pins 9 to 10 -> Guitar Pick - pinMode(9, INPUT_PULLUP); - pinMode(10, INPUT_PULLUP); - - // Initialise ADXL345 - accel.begin(); - - // Set Range for ADXL345 - accel.setRange(ADXL345_RANGE_16_G); - // accel.setRange(ADXL345_RANGE_8_G); - // accel.setRange(ADXL345_RANGE_4_G); - // accel.setRange(ADXL345_RANGE_2_G); - - // Initialize Joystick Library - Joystick.begin(); - Joystick.setXAxisRange(-100, 100); - Joystick.setYAxisRange(-100, 100); - Joystick.setZAxisRange(-100, 100); -} - -// Constant that maps the phyical pin to the joystick button. -const int pinToButtonMap = 4; -const int pinToHatSwitchMap = 9; - -// Last state of the buttons -int lastButtonState[5] = {0,0,0,0,0}; -int lastHatSwitchState[2] = {0,0}; - -void loop() { - /* Get a new sensor event */ - sensors_event_t event; - accel.getEvent(&event); - - bool valueChanged = false; - - Joystick.setXAxis(event.acceleration.x); - Joystick.setYAxis(event.acceleration.y); - Joystick.setZAxis(event.acceleration.z); - - // Read pin values - for (int index = 0; index < 5; index++) { - int currentButtonState = !digitalRead(index + pinToButtonMap); - if (currentButtonState != lastButtonState[index]) { - switch (index) { - case 0: - Joystick.setButton(0, currentButtonState); - break; - case 1: - Joystick.setButton(1, currentButtonState); - break; - case 2: - Joystick.setButton(2, currentButtonState); - break; - case 3: - Joystick.setButton(3, currentButtonState); - break; - case 4: - Joystick.setButton(4, currentButtonState); - break; - } - lastButtonState[index] = currentButtonState; - } - } - - for (int index = 0; index < 2; index++) { - int currentHatSwitchState = digitalRead(index + pinToHatSwitchMap); - if (currentHatSwitchState != lastHatSwitchState[index]) { - valueChanged = true; - lastHatSwitchState[index] = currentHatSwitchState; - } - } - - if (valueChanged) { - if ((lastHatSwitchState[0] == 0) && (lastHatSwitchState[1] == 0)) { - Joystick.setHatSwitch(0, -1); - } - if (lastHatSwitchState[0] == 1) { - Joystick.setHatSwitch(0, 0); - } - if (lastHatSwitchState[1] == 1) { - Joystick.setHatSwitch(0, 180); - } - } // if the value changed -} +//-------------------------------------------------------------------- +// For use with a 573 or GH Guitar Controller +// +// This sketch maps a ADXL345 accelerometer via I2C and uses 7 digital +// inputs - 5 buttons and a 2 hat switches for the pick. +// +// All digital pins are grounded when they are pressed. +// +// NOTE: This sketch file is for use with Arduino Leonardo and +// Micro only. +// +// by lyzzz +// 2019-07-25 +//-------------------------------------------------------------------- + +#include +#include +#include +#include + +/* Assign a unique ID to this sensor at the same time */ +Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(573); + +Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD, + 5, 1, // Button Count, Hat Switch Count + true, true, true, // X, Y and Z Axis + false, false, false, // No Rx, Ry, or Rz + false, false, // No rudder or throttle + false, false, false); // No accelerator, brake, or steering + +void setup() { + // Initialize Button Pins + // Pins 2 and 3 are reserved for I2C + //pinMode(2, INPUT_PULLUP); + //pinMode(3, INPUT_PULLUP); + + // Pins 5 to 9 -> R, G, B, Y, P + pinMode(4, INPUT_PULLUP); + pinMode(5, INPUT_PULLUP); + pinMode(6, INPUT_PULLUP); + pinMode(7, INPUT_PULLUP); + pinMode(8, INPUT_PULLUP); + + // Pins 9 to 10 -> Guitar Pick + pinMode(9, INPUT_PULLUP); + pinMode(10, INPUT_PULLUP); + + // Initialise ADXL345 + accel.begin(); + + // Set Range for ADXL345 + accel.setRange(ADXL345_RANGE_16_G); + // accel.setRange(ADXL345_RANGE_8_G); + // accel.setRange(ADXL345_RANGE_4_G); + // accel.setRange(ADXL345_RANGE_2_G); + + // Initialize Joystick Library + Joystick.begin(); + Joystick.setXAxisRange(-100, 100); + Joystick.setYAxisRange(-100, 100); + Joystick.setZAxisRange(-100, 100); +} + +// Constant that maps the phyical pin to the joystick button. +const int pinToButtonMap = 4; +const int pinToHatSwitchMap = 9; + +// Last state of the buttons +int lastButtonState[5] = {0,0,0,0,0}; +int lastHatSwitchState[2] = {0,0}; + +void loop() { + /* Get a new sensor event */ + sensors_event_t event; + accel.getEvent(&event); + + bool valueChanged = false; + + Joystick.setXAxis(event.acceleration.x); + Joystick.setYAxis(event.acceleration.y); + Joystick.setZAxis(event.acceleration.z); + + // Read pin values + for (int index = 0; index < 5; index++) { + int currentButtonState = !digitalRead(index + pinToButtonMap); + if (currentButtonState != lastButtonState[index]) { + switch (index) { + case 0: + Joystick.setButton(0, currentButtonState); + break; + case 1: + Joystick.setButton(1, currentButtonState); + break; + case 2: + Joystick.setButton(2, currentButtonState); + break; + case 3: + Joystick.setButton(3, currentButtonState); + break; + case 4: + Joystick.setButton(4, currentButtonState); + break; + } + lastButtonState[index] = currentButtonState; + } + } + + for (int index = 0; index < 2; index++) { + int currentHatSwitchState = digitalRead(index + pinToHatSwitchMap); + if (currentHatSwitchState != lastHatSwitchState[index]) { + valueChanged = true; + lastHatSwitchState[index] = currentHatSwitchState; + } + } + + if (valueChanged) { + if ((lastHatSwitchState[0] == 0) && (lastHatSwitchState[1] == 0)) { + Joystick.setHatSwitch(0, -1); + } + if (lastHatSwitchState[0] == 1) { + Joystick.setHatSwitch(0, 0); + } + if (lastHatSwitchState[1] == 1) { + Joystick.setHatSwitch(0, 180); + } + } // if the value changed +}