Skip to content

Commit 75dabd7

Browse files
authored
Merge pull request #1403 from jedgarpark/guitar-hero-midi
first commit
2 parents bd060e6 + 0217c45 commit 75dabd7

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

Guitar_Hero_MIDI/.qtpy.test.only

Whitespace-only changes.

Guitar_Hero_MIDI/GuitarHeroMIDI.ino

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
//Wii Guitar Hero MIDI Controller
2+
// by John Park for Adafruit Industries
3+
#include <WiiChuck.h>
4+
#include <Adafruit_TinyUSB.h>
5+
#include <MIDI.h>
6+
7+
Accessory guitar;
8+
Adafruit_USBD_MIDI usb_midi;
9+
MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
10+
11+
int MIDI_OUT_CH = 1; // pick your midi output channel here
12+
bool DEBUG = 0; // set to 1 to use serial monitor to check out controller values
13+
14+
int whammyBar;
15+
int joyX;
16+
int joyY;
17+
int minusButton; // drop an octave w each press
18+
int plusButton; // up and octave w each press
19+
int strumDown;
20+
int strumUp;
21+
int fretButtons[5];
22+
23+
bool minusButtonOn = 0;
24+
bool plusButtonOn = 0;
25+
bool strumDownOn = 0;
26+
bool strumUpOn = 0;
27+
bool fretButtonOn[] = {0, 0, 0, 0, 0};
28+
29+
int octave = 12; // note offset value, used to change octaves
30+
31+
int strumDownChord[] = {36, 40, 43, 45}; //all note values will be offset by octave value
32+
int strumUpChord[] = {36, 41, 43, 45} ;
33+
int fretNotes[] = {24, 26, 28, 29, 31};
34+
35+
int lastWhammy = 16; // Use the resting state value of your whammy bar
36+
int whammyPitchVal = 8192; // resting position of pitchwheel
37+
38+
int lastJoyX = 223; // resting value of joyX
39+
int joyXCCNum = 71; // VCF or whatever you assign in synth software
40+
int joyXCCVal = 0;
41+
int lastJoyY = 224; // resting value of joyY
42+
int joyYCCNum = 72; // VCA
43+
int joyYCCVal = 0;
44+
45+
void setup() {
46+
Serial.begin(115200);
47+
MIDI.begin(MIDI_CHANNEL_OMNI);
48+
guitar.begin();
49+
guitar.type = GuitarHeroController;
50+
}
51+
52+
void loop() {
53+
guitar.readData(); // Read inputs and update maps
54+
fretButtons[0] = guitar.values[10]; // green
55+
fretButtons[1] = guitar.values[11]; // red
56+
fretButtons[2] = guitar.values[12]; // yellow
57+
fretButtons[3] = guitar.values[13]; //blue
58+
fretButtons[4] = guitar.values[14]; // orange
59+
minusButton = guitar.values[6];
60+
plusButton = guitar.values[16];
61+
strumDown = guitar.values[7];
62+
strumUp = guitar.values[7];
63+
whammyBar = guitar.values[0];
64+
joyX = guitar.values[20];
65+
joyY = guitar.values[21];
66+
67+
for(int i=0;i<5;i++){
68+
if(fretButtons[i]==255 && fretButtonOn[i]==0){
69+
MIDI.sendNoteOn(fretNotes[i]+octave, 127, MIDI_OUT_CH);
70+
fretButtonOn[i] = 1;}
71+
if(fretButtons[i]==0 && fretButtonOn[i]==1){
72+
MIDI.sendNoteOff(fretNotes[i]+octave, 0, MIDI_OUT_CH);
73+
fretButtonOn[i] = 0;}
74+
}
75+
76+
if(whammyBar!=lastWhammy){
77+
whammyPitchVal=map(whammyBar, 15, 26, 8192, 16383); // remap to pitch value range, two semitones here
78+
MIDI.sendPitchBend(whammyPitchVal, MIDI_OUT_CH);
79+
lastWhammy=whammyBar;
80+
}
81+
if(joyX!=lastJoyX){
82+
joyXCCVal=map(joyX, 190, 255, 0, 127); // remap to bigger range
83+
MIDI.sendControlChange(joyXCCNum, joyXCCVal, MIDI_OUT_CH);
84+
lastJoyX=joyX;
85+
}
86+
if(joyY!=lastJoyY){
87+
joyYCCVal=map(joyY, 190, 255, 0, 127); // remap to bigger range
88+
MIDI.sendControlChange(joyYCCNum, joyYCCVal, MIDI_OUT_CH);
89+
lastJoyY=joyY;
90+
}
91+
92+
if(minusButton==0 && minusButtonOn==0){
93+
octave = constrain((octave - 12), 0, 108);
94+
minusButtonOn = 1;}
95+
if(minusButton==128 && minusButtonOn==1){
96+
minusButtonOn = 0;}
97+
98+
if(plusButton==255 && plusButtonOn==0){
99+
octave = constrain((octave + 12), 0, 108);
100+
plusButtonOn = 1;}
101+
if(plusButton==0 && plusButtonOn==1){
102+
plusButtonOn = 0;}
103+
104+
if(strumDown==0 && strumDownOn==0){
105+
for(int c=0; c<4; c++){
106+
MIDI.sendNoteOn(strumDownChord[c]+octave, 127, MIDI_OUT_CH);}
107+
strumDownOn = 1;}
108+
if(strumDown==128 && strumDownOn==1){
109+
for(int c=0; c<4; c++){
110+
MIDI.sendNoteOff(strumDownChord[c]+octave, 0, MIDI_OUT_CH);}
111+
strumDownOn = 0;}
112+
113+
if(strumUp==255 && strumUpOn==0){
114+
for(int c=0; c<4; c++){
115+
MIDI.sendNoteOn(strumUpChord[c]+octave, 127, MIDI_OUT_CH);}
116+
strumUpOn = 1;}
117+
if(strumUp==128 && strumUpOn==1){
118+
for(int c=0; c<4; c++){
119+
MIDI.sendNoteOff(strumUpChord[c]+octave, 0, MIDI_OUT_CH);}
120+
strumUpOn = 0;}
121+
122+
delay(5);
123+
124+
if(DEBUG){
125+
Serial.println("-------------------------------------------");
126+
guitar.printInputs();
127+
for (int i = 0; i < WII_VALUES_ARRAY_SIZE+3; i++) {
128+
Serial.println(
129+
"Controller Val " + String(i) + " = "
130+
+ String((uint8_t) guitar.values[i]));
131+
}
132+
delay(50); // keeps the terminal from flooding
133+
}
134+
}

0 commit comments

Comments
 (0)