hey folks, im having an issue. my project is midi drums to play rock band 3. i used todbot's code as a starting point, and had it working great. was messing with threshold values to tune it in, and all of a sudden no worky. i went back an changed the threshold values to were it was last working. and now it seems as if its not sending a midi signl. im thinking it my have to do with this part of the code.
while(analogRead(piezoBPin) >= PIEZOTHRESHOLD2/2)
^^ not fully sure what this is for. is it dividing my threshold in half?
but anyways heres the code, and if someone could tell me what the poop is up or happed that would be greatly appreciated.
/*
* MIDI Drum Kit
* -------------
* Convert Arduino to a MIDI controller using various inputs and
* the serial port as a MIDI output.
*
* This sketch is set up to send General MIDI (GM) drum notes
* on MIDI channel 1, but it can be easily reconfigured for other
* notes and channels
*
* It uses switch inputs to send MIDI notes of a fixed velocity with
* note on time determined by duration of keypress and it uses
* piezo buzzer elements as inputs to send MIDI notes of a varying velocity
* & duration, depending on forced of impulse imparted to piezo sensor.
*
* To send MIDI, attach a MIDI out jack (female DIN-5) to Arduino.
* DIN-5 pinout is: _____
* pin 2 - Gnd / \
* pin 4 - 220 ohm resistor to +5V | 3 1 | MIDI jack
* pin 5 - Arduino D1 (TX) | 5 4 |
* all other pins - unconnected \__2__/
* On my midi jack, the color of the wires for the pins are:
* 3 = n/c
* 5 = black (blue)
* 2 = red (red)
* 4 = orange (yellow)
* 1 = brown
*
* Based off of Tom Igoe's work at:
* http://itp.nyu.edu/physcomp/Labs/MIDIOutput
*
* Created 25 October 2006
* copyleft 2006 Tod E. Kurt <tod@todbot.com
* http://todbot.com/
*
* Updates:
* - 2 May 2009 - fixed noteOn() and noteOff()
*
*/
// what midi channel is being sent
// ranges from 0-15
#define drumchan 2
// general midi drum notes
#define note_bassdrum 33
#define note_snaredrum 37 // RED PAD
#define note_hihatclosed 44 // FOOT SWITCH FOR CLOSED HI HAT
#define note_hihatopen 22 // YELLOW CYMBAL, PIN 0
#define note_crash 49 // GREEN CYMBAL.A5
#define note_hitom 48 //
#define note_lowtom 45 //
#define note_floortom 41 //
#define note_ridecym 51 // BLUE CYMBOL A6
// define the pins we use
#define switchAPin 7 //bass pedal, DIGITAL PIN 7
#define switchCPin 5 // hihatclosed pedal, DIGITAL PIN 5
#define piezoAPin 0 //hi hat open pedal, YELLOW CYMBAL, ANALOG PIN 0
#define piezoBPin 1 //hi tom YELLOWA1
#define piezoCPin 2 //snare drum RED A2
#define piezoDPin 3 // low tom BLUE A3
#define piezoEPin 4 // floor tom GREEN A4
#define piezoFPin 5 // GREEEN CYMBAL A5
#define piezoGPin 6 // BLUE CYMBAL A6
#define ledPin 13 // for midi out status
// analog threshold for piezo sensing
#define PIEZOTHRESHOLD1 100 //YELLOW CYMBAL
#define PIEZOTHRESHOLD2 100//YELLOW PAD
#define PIEZOTHRESHOLD3 100//RED PAD
#define PIEZOTHRESHOLD4 100 //BLUE PAD
#define PIEZOTHRESHOLD5 100 //GREEN PAD
#define PIEZOTHRESHOLD6 100 //GREEN CYMBAL
#define PIEZOTHRESHOLD7 100//BLUE CYMBAL
int switchAState = LOW;
int switchBState = LOW;
int switchCState = LOW;
int currentSwitchState = LOW;
int val,t;
void setup() {
pinMode(switchAPin, INPUT);
pinMode(switchCPin, INPUT);
digitalWrite(switchAPin, HIGH); // turn on internal pullup
digitalWrite(switchCPin, HIGH); // turn on internal pullup
pinMode(ledPin, OUTPUT);
Serial.begin(31250); // set MIDI baud rate
}
void loop() {
// deal with switchA BASS DRUM
currentSwitchState = digitalRead(switchAPin);
if( currentSwitchState == LOW && switchAState == HIGH ) // push
noteOn(drumchan, note_bassdrum, 100);
if( currentSwitchState == HIGH && switchAState == LOW ) // release
noteOff(drumchan, note_bassdrum, 0);
switchAState = currentSwitchState;
// deal with HI HAT CLOSED FOOT PEDLE
currentSwitchState = digitalRead(switchCPin);
if( currentSwitchState == LOW && switchCState == HIGH ) // push
noteOn(drumchan, note_hihatclosed, 100);
if( currentSwitchState == HIGH && switchCState == LOW ) // release
noteOff(drumchan, note_hihatclosed, 0);
switchCState = currentSwitchState;
// 1 deal with first piezo, HI HAT OPEN, YELLOW CYMBAL
val = analogRead(piezoAPin);
if( val >= PIEZOTHRESHOLD1 ) {
t=0;
while(analogRead(piezoAPin) >= PIEZOTHRESHOLD1/2) {
t++;
}
noteOn(drumchan,note_hihatopen, t*2);
delay(t);
noteOff(drumchan,note_hihatopen,0);
}
// 2 deal with second piezos, HITOM, YELLOW PAD
val = analogRead(piezoBPin);
if( val >= PIEZOTHRESHOLD2 ) {
t=0;
while(analogRead(piezoBPin) >= PIEZOTHRESHOLD2/2) {
t++;
}
noteOn(drumchan,note_hitom, t*2);
delay(t);
noteOff(drumchan,note_hitom,0);
}
// 3 deal with second piezos,SNARE DRUM RED PAD
val = analogRead(piezoCPin);
if( val >= PIEZOTHRESHOLD3 ) {
t=0;
while(analogRead(piezoCPin) >= PIEZOTHRESHOLD3/2) {
t++;
}
noteOn(drumchan,note_snaredrum, t*2);
delay(t);
noteOff(drumchan,note_snaredrum,0);
}
// 4 deal with second piezos, LOW TOM BLUE PAD
val = analogRead(piezoDPin);
if( val >= PIEZOTHRESHOLD4 ) {
t=0;
while(analogRead(piezoDPin) >= PIEZOTHRESHOLD4/2) {
t++;
}
noteOn(drumchan,note_lowtom, t*2);
delay(t);
noteOff(drumchan,note_lowtom,0);
}
// 5 deal with second piezos, FLOOR TOM GREEN PAD
val = analogRead(piezoEPin);
if( val >= PIEZOTHRESHOLD5 ) {
t=0;
while(analogRead(piezoEPin) >= PIEZOTHRESHOLD5/2) {
t++;
}
noteOn(drumchan,note_floortom, t*2);
delay(t);
noteOff(drumchan,note_floortom,0);
}
// 6 deal with second piezos,CRASH GREEN CYMBAL
val = analogRead(piezoFPin);
if( val >= PIEZOTHRESHOLD6 ) {
t=0;
while(analogRead(piezoFPin) >= PIEZOTHRESHOLD6/2) {
t++;
}
noteOn(drumchan,note_crash, t*2);
delay(t);
noteOff(drumchan,note_crash,0);
}
// 7 deal with 7TH piezos,BLUE CYMBAL
val = analogRead(piezoGPin);
if( val >= PIEZOTHRESHOLD6 ) {
t=0;
while(analogRead(piezoGPin) >= PIEZOTHRESHOLD6/2) {
t++;
}
noteOn(drumchan,note_ridecym, t*2);
delay(t);
noteOff(drumchan,note_ridecym,0);
}
}
// Send a MIDI note-on message. Like pressing a piano key
// channel ranges from 0-15
void noteOn(byte channel, byte note, byte velocity) {
midiMsg( (0x90 | channel), note, velocity);
}
// Send a MIDI note-off message. Like releasing a piano key
void noteOff(byte channel, byte note, byte velocity) {
midiMsg( (0x80 | channel), note, velocity);
}
// Send a general MIDI message
void midiMsg(byte cmd, byte data1, byte data2) {
digitalWrite(ledPin,HIGH); // indicate we're sending MIDI data
Serial.write(cmd);
Serial.write(data1);
Serial.write(data2);
digitalWrite(ledPin,LOW);
}
[code]