Hi
I am currently trying to build a drumkit that triggers sounds in pro tools. i have got it working using buttons. However I am now trying to find a way to replace the button with a piezo. Any help with this would be very apreciated.
Thanks
The code below works with 8 buttons
// what midi channel we're sending on
// ranges from 0?15
#define drumchan 9 // Equates to MIDI Channel 10
// general midi drum notes
#define note_bassdrum 36
#define note_snaredrum 38
#define note_clap 39
#define note_hihat 42
#define note_rim 45
#define note_openhat 46
#define note_hattype 51
#define note_horn 43
// define the pins we use
#define switchAPin 10
#define switchBPin 9
#define switchCPin 8
#define switchDPin 7
#define switchEPin 6
#define switchFPin 5
#define switchGPin 4
#define switchHPin 3
#define ledPin 13 // for midi out status
int switchAState = LOW;
int switchBState = LOW;
int switchCState = LOW;
int switchDState = LOW;
int switchEState = LOW;
int switchFState = LOW;
int switchGState = LOW;
int switchHState = LOW;
int currentSwitchState = LOW;
int val,t;
void setup() {
pinMode(switchAPin, INPUT);
pinMode(switchBPin, INPUT);
pinMode(switchCPin, INPUT);
pinMode(switchDPin, INPUT);
pinMode(switchEPin, INPUT);
pinMode(switchFPin, INPUT);
pinMode(switchGPin, INPUT);
pinMode(switchHPin, INPUT);
digitalWrite(switchAPin, HIGH); // turn on internal pullup
digitalWrite(switchBPin, HIGH); // turn on internal pullup
digitalWrite(switchCPin, HIGH); // turn on internal pullup
digitalWrite(switchDPin, HIGH); // turn on internal pullup
digitalWrite(switchEPin, HIGH); // turn on internal pullup
digitalWrite(switchFPin, HIGH); // turn on internal pullup
digitalWrite(switchGPin, HIGH); // turn on internal pullup
digitalWrite(switchHPin, HIGH); // turn on internal pullup
pinMode(ledPin, OUTPUT);
Serial.begin(57600); // set MIDI baud rate
}
void loop() {
// deal with switchA
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 switchB
currentSwitchState = digitalRead(switchBPin);
if( currentSwitchState == LOW && switchBState == HIGH ) // push
noteOn(drumchan, note_snaredrum, 100);
if( currentSwitchState == HIGH && switchBState == LOW ) // release
noteOff(drumchan, note_snaredrum, 0);
switchBState = currentSwitchState;
// deal with switchC
currentSwitchState = digitalRead(switchCPin);
if( currentSwitchState == LOW && switchCState == HIGH ) // push
noteOn(drumchan, note_clap, 100);
if( currentSwitchState == HIGH && switchCState == LOW ) // release
noteOff(drumchan, note_clap, 0);
switchCState = currentSwitchState;
// deal with switchD
currentSwitchState = digitalRead(switchDPin);
if( currentSwitchState == LOW && switchDState == HIGH ) // push
noteOn(drumchan, note_hihat, 100);
if( currentSwitchState == HIGH && switchDState == LOW ) // release
noteOff(drumchan, note_hihat, 0);
switchDState = currentSwitchState;
// deal with switchE
currentSwitchState = digitalRead(switchEPin);
if( currentSwitchState == LOW && switchEState == HIGH ) // push
noteOn(drumchan, note_rim, 100);
if( currentSwitchState == HIGH && switchEState == LOW ) // release
noteOff(drumchan, note_rim, 0);
switchEState = currentSwitchState;
// deal with switchF
currentSwitchState = digitalRead(switchFPin);
if( currentSwitchState == LOW && switchFState == HIGH ) // push
noteOn(drumchan, note_openhat, 100);
if( currentSwitchState == HIGH && switchFState == LOW ) // release
noteOff(drumchan, note_openhat, 0);
switchFState = currentSwitchState;
// deal with switchG
currentSwitchState = digitalRead(switchGPin);
if( currentSwitchState == LOW && switchGState == HIGH ) // push
noteOn(drumchan, note_hattype, 100);
if( currentSwitchState == HIGH && switchGState == LOW ) // release
noteOff(drumchan, note_hattype, 0);
switchGState = currentSwitchState;
// deal with switchH
currentSwitchState = digitalRead(switchHPin);
if( currentSwitchState == LOW && switchHState == HIGH ) // push
noteOn(drumchan, note_horn, 100);
if( currentSwitchState == HIGH && switchHState == LOW ) // release
noteOff(drumchan, note_horn, 0);
switchHState = currentSwitchState;
// Send a MIDI note on message. L ? ike 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(byte(cmd));
Serial.write(byte(data1));
Serial.write(byte(data2));
digitalWrite(ledPin,LOW);
}