Go Down

Topic: Puredata ardruino drum wireless - Help (Read 515 times) previous topic - next topic

balam

Feb 26, 2010, 05:27 am Last Edit: Feb 26, 2010, 05:29 am by balam Reason: 1
Hi,
I am working in a project with arduinos, xbees and puredata.
after somany days of research I was able to connect wireless a  arduino to puredata without firmata..  my arduino has 6 analogs sensors and has the code from spikezinelabs running (arduino drums).
in my Puredata patch gets data from any sensor  as a single input.
I woud like to separte the data for each sensor and make puredata bang to a software instrument.  

any suggestion is very welcome.

arduino code and puredata patch here


puredata patch ( extended version)

http://thewebclass.org/codeout/mypd-serial.pd



arduino code


//  *****************************************************************************************************************
//  *                                                                                                               *
//  *                                         SpikenzieLabs.com                                                     *
//  *                                                                                                               *
//  *                                           Drum Kit - Kit                                                      *
//  *                                                                                                               *
//  *                                                                                                               *
//  *****************************************************************************************************************
//
//  BY: MARK DEMERS Copywrite 20009
//  April. 2009
//  VERSION: 1.b

// Balam Soto 2010  add accelerometer support
//

//
//  Required - Software:
//  1. Serial MIDI converter
//  2. Garage Band, Ableton Live etc ...
//
//The pins are mapped from left to right (0 to 5).

//Starting with Analog pin 0 on the left.

//So, for your project try:

//int PadCutOff[6] = {700,700,700, your pin 3 value , your pin 4 value ,700};           // Minimum Analog value to cause a drum hit
// LEGAL:
// This code is provided as is. No guaranties or warranties are given in any form. It is your responsibilty to
// determine this codes suitability for your application.






//*******************************************************************************************************************
// User settable variables                  
//*******************************************************************************************************************

unsigned char PadNote[6] = {52,16,66,63,40,65};         // MIDI notes from 0 to 127 (Mid C = 60)


//The pins are mapped from left to right (0 to 5).
int PadCutOff[6] = {510,500,500,500,360,360};           // Minimum  default 600  Analog value to cause a drum hit
                                                       //340 average is for Y pin on accelro
                                                       // 360 average for X    

int MaxPlayTime[6] = {90,90,90,90,90,90};               // Cycles before a 2nd hit is allowed

#define  midichannel      0;                              // MIDI channel from 0 to 15 (+1 in "real world")

boolean VelocityFlag  = true;                           // Velocity ON (true) or OFF (false)





//*******************************************************************************************************************
// Internal Use Variables                  
//*******************************************************************************************************************

boolean activePad[6] = {0,0,0,0,0,0};                   // Array of flags of pad currently playing
int PinPlayTime[6] = {0,0,0,0,0,0};                     // Counter since pad started to play

unsigned char status;

int pin = 0;    
int hitavg = 0;

//*******************************************************************************************************************
// Setup                  
//*******************************************************************************************************************

void setup()
{
 Serial.begin(57600);                                  // connect to the serial port 115200
}

//*******************************************************************************************************************
// Main Program                  
//*******************************************************************************************************************

void loop()
{
 for(int pin=0; pin < 6; pin++)
 {
   hitavg = analogRead(pin);                              // read the input pin

   if((hitavg > PadCutOff[pin]))
   {
     if((activePad[pin] == false))
     {
       if(VelocityFlag == true)
       {
//          hitavg = 127 / ((1023 - PadCutOff[pin]) / (hitavg - PadCutOff[pin]));    // With full range (Too sensitive ?)
         hitavg = (hitavg / 8) -1 ;                                                 // Upper range
       }
       else
       {
         hitavg = 127;
       }

       MIDI_TX(144,PadNote[pin],hitavg);
       PinPlayTime[pin] = 0;
       activePad[pin] = true;
     }
     else
     {
       PinPlayTime[pin] = PinPlayTime[pin] + 1;
     }
   }
   else if((activePad[pin] == true))
   {
     PinPlayTime[pin] = PinPlayTime[pin] + 1;
     
     if(PinPlayTime[pin] > MaxPlayTime[pin])
     {
       activePad[pin] = false;
       MIDI_TX(128,PadNote[pin],127);
     }
   }
 }
}


//*******************************************************************************************************************
// Transmit MIDI Message                  
//*******************************************************************************************************************
void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY)
{
 status = MESSAGE + midichannel;
 Serial.print(status);
 Serial.print(PITCH);
 Serial.print(VELOCITY);
}



balam


Go Up