Go Down

Topic: piezo Midi drums (Read 1 time) previous topic - next topic


Apr 21, 2011, 06:38 am Last Edit: Apr 21, 2011, 11:30 pm by Pitchoilcan Reason: 1
Hi all, I 've been working on a midi drum project and I am alittle stuck. The idea is to trigger one of sixteen notes (sensorID) depending on which of the sixteen piezo sensors are touched with velocity senitivity. Can anyome help me formatting the code for viewing the serial monitor. As it is now I see only unreadable characters in the monitor and might be the least of my worries. I am not sure I'm assinging the sensorID's correctly but I making progress.
Code: [Select]
/* ReadMultiplexedSensorsAndSendMIDI
* ------------
* Reads 2 8 channel Multiplexers and sends the values
//#define CONTROLpin1 1
#define drumchan           1
#define CONTROLpin2 2
#define CONTROLpin3 3
#define CONTROLpin4 4
#define ledPin 13
int piezoPin = 0;
int THRESHOLD = 100; // set minimum value that indicates a knock
int val,t;
int actualSensorValue;             // value from the analog input
// Variables:
char sensorID[16] = { 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74};
char sensorValueToSend = 0;            // Value of the sensor
// Some error chacking would be good here.
//If the values exceede 128 the will not fit in one byte.
//void sendCommand(char command, char sensorID, char value) {
//  Serial.print(command, BYTE);
//  Serial.print(sensorID, BYTE);
//  Serial.print(value, BYTE);
// Send a MIDI note-on message.  Like pressing a piano key
// channel ranges from 0-15
void noteOn(byte channel, byte sensorID, byte velocity) {
 midiMsg( (0x90 | channel), sensorID, velocity);

// Send a MIDI note-off message.  Like releasing a piano key
void noteOff(byte channel, byte sensorID, byte velocity) {
 midiMsg( (0x80 | channel), sensorID, velocity);

// Send a general MIDI message
void midiMsg(byte cmd, byte data1, byte data2) {
 digitalWrite(ledPin,HIGH);  // indicate we're sending MIDI data
 Serial.print(cmd, BYTE);
 Serial.print(data1, BYTE);
 Serial.print(data2, BYTE);
void setup() {
 //  set the states of the I/O pins:
 pinMode(ledPin, OUTPUT);
 //pinMode(CONTROLpin1, OUTPUT);
 pinMode(CONTROLpin2, OUTPUT);
 pinMode(CONTROLpin3, OUTPUT);
 pinMode(CONTROLpin4, OUTPUT);
void loop() {
 int i;
 int j;
 for (i=0; i <8; i++) {
   // set control pins on the multiplexers
   digitalWrite(CONTROLpin3 (i&4)>>2);//bit3
   digitalWrite(CONTROLpin2 (i&2)>>1);//bit2
   digitalWrite(CONTROLpin1 (i&1)   );//bit1
   // read the analogue inputs and send the values of the sensors.
   for(j=0; j<2; j++){
     //actualSensorValue = analogRead(j)>>3:
     // You will have to adjust this line so that can send the
     // sensor value in one byte.
     //sensorValueToSend = actualSensorValue / 7;
     //sendCommand(0x90, i+8*j, sensorValueToSend);
// deal with piezos, this is kind of a hack
 val = analogRead(j);
 if( val >= THRESHOLD ) {
   digitalWrite(ledPin, HIGH);
   while(analogRead(j) >= THRESHOLD/2) {
   noteOn(drumchan,sensorID[i], t*2);
   digitalWrite(ledPin, LOW);
   // if you uncomment this line you can check the control pins
   // of the multiplexers with your multimeter.


By viewing in the monitor I mean byte channe, btye senorID, byte, velocity.
Thanks again
Think different
Think UbuntuStudio


Change "BYTE" to "HEX" to see the data in hexadecimal or "DEC" to see it in decimal.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Go Up