Hardware, Code & Patches

Hardware

Schematic

Board

PD Patches

===============

Arduino Code

===============

Midi output:

/*
* Program for pd + arduino workshop
*
* Copenhaguen – Bergen
* Nov. 2.007
* M. Yarza & C. Lopez
*/

int pot0 = 0;
int pot1 = 1;
int pot2 = 2;
int pot3 = 3;
int pot4 = 4;
int pot5 = 5;

int analog0 = 0;
int analog1 = 0;
int analog2 = 0;
int analog3 = 0;
int analog4 = 0;
int analog5 = 0;

int analog0old = 0;
int analog1old = 0;
int analog2old = 0;
int analog3old = 0;
int analog4old = 0;
int analog5old = 0;

int but2 = 2;
int but3 = 3;
int but4 = 4;
int but5 = 5;
int but6 = 6;
int but7 = 7;
int but8 = 8;
int but9 = 9;
int but10 = 10;
int but11 = 11;
int but12 = 12;

int digital2 = 0;
int digital3 = 0;
int digital4 = 0;
int digital5 = 0;
int digital6 = 0;
int digital7 = 0;
int digital8 = 0;
int digital9 = 0;
int digital10 = 0;
int digital11 = 0;
int digital12 = 0;

void setup(){

Serial.begin(31250);

pinMode(but2, INPUT);
pinMode(but3, INPUT);
pinMode(but4, INPUT);
pinMode(but5, INPUT);
pinMode(but6, INPUT);
pinMode(but7, INPUT);
pinMode(but8, INPUT);
pinMode(but9, INPUT);
pinMode(but10, INPUT);
pinMode(but11, INPUT);
pinMode(but12, INPUT);

}

void sendMidi(byte chan, byte cont,byte  value){
Serial.print(chan, BYTE);
delay(5);
Serial.print(cont, BYTE);
delay(5);
Serial.print(value, BYTE);
delay(5);
}

void loop(){

analog0 = analogRead(pot0);
analog1 = analogRead(pot1);
analog2 = analogRead(pot2);
analog3 = analogRead(pot3);
analog4 = analogRead(pot4);
analog5 = analogRead(pot5);

digital2 = digitalRead(but2);
digital3 = digitalRead(but3);
digital4 = digitalRead(but4);
digital5 = digitalRead(but5);
digital6 = digitalRead(but6);
digital7 = digitalRead(but7);
digital8 = digitalRead(but8);
digital9 = digitalRead(but9);
digital10 = digitalRead(but10);
digital11 = digitalRead(but11);
digital12 = digitalRead(but12);

if (digital2 == 0){
sendMidi(0xB0, 1, 1);
delay(200);
sendMidi(0xB0, 1, 0);

}

if (digital3 == 0){
sendMidi(0xB0, 2, 1);
delay(200);
sendMidi(0xB0, 2, 0);

}

if (digital4 == 0){
sendMidi(0xB0, 3, 1);
delay(200);
sendMidi(0xB0, 3, 0);

}

if (digital5 == 0){
sendMidi(0xB0, 4, 1);
delay(200);
sendMidi(0xB0, 4, 0);

}

if (digital6 == 0){
sendMidi(0xB0, 5, 1);
delay(200);
sendMidi(0xB0, 5, 0);

}

if (digital7 == 0){
sendMidi(0xB0, 6, 1);
delay(200);
sendMidi(0xB0, 6, 0);

}

if (digital8 == 0){
sendMidi(0xB0, 7, 1);
delay(200);
sendMidi(0xB0, 7, 0);

}

if (digital9 == 0){
sendMidi(0xB0, 8, 1);
delay(200);
sendMidi(0xB0, 8, 0);

}

if (digital10 == 0){
sendMidi(0xB0, 9, 1);
delay(200);
sendMidi(0xB0, 9, 0);

}

if (digital11 == 0){
sendMidi(0xB0, 10, 1);
delay(200);
sendMidi(0xB0, 10, 0);

}

if (digital12 == 0){
sendMidi(0xB0, 11, 1);
delay(200);
sendMidi(0xB0, 11, 0);

}

if ((analog0 < analog0old -50)||(analog0 > analog0old + 50)){

sendMidi(0xB1, 13, analog0/8);
analog0old = analog0;
}

if ((analog1 < analog1old -50)||(analog1 > analog1old + 50)){

sendMidi(0xB1, 14, analog1/8);
analog1old = analog1;
}
if ((analog2 < analog2old -50)||(analog2 > analog2old + 50)){

sendMidi(0xB1, 15, analog2/8);
analog2old = analog2;
}

if ((analog3 < analog3old -50)||(analog3 > analog3old + 50)){

sendMidi(0xB1, 16, analog3/8);
analog3old = analog3;
}

if ((analog4 < analog4old -50)||(analog4 > analog4old + 50)){

sendMidi(0xB1, 17, analog4/8);
analog4old = analog4;
}

if ((analog5 < analog5old -50)||(analog5 > analog5old + 50)){

sendMidi(0xB1, 18, analog5/8);
analog5old = analog5;
}

}

———————————————————————————-

USB output:

/*
* Program for pd + arduino workshop
*
* Arduino sends data over USB
*
* Copenhaguen – Bergen
* Nov. 2.007
* M. Yarza & C. Lopez
*/

// var

int pot0 = 0;
int pot1 = 1;
int pot2 = 2;
int pot3 = 3;
int pot4 = 4;
int pot5 = 5;

int analog0 = 0;
int analog1 = 0;
int analog2 = 0;
int analog3 = 0;
int analog4 = 0;
int analog5 = 0;

int analog0old = 0;
int analog1old = 0;
int analog2old = 0;
int analog3old = 0;
int analog4old = 0;
int analog5old = 0;

int but2 = 2;
int but3 = 3;
int but4 = 4;
int but5 = 5;
int but6 = 6;
int but7 = 7;
int but8 = 8;
int but9 = 9;
int but10 = 10;
int but11 = 11;
int but12 = 12;

int digital2 = 0;
int digital3 = 0;
int digital4 = 0;
int digital5 = 0;
int digital6 = 0;
int digital7 = 0;
int digital8 = 0;
int digital9 = 0;
int digital10 = 0;
int digital11 = 0;
int digital12 = 0;

void setup(){

Serial.begin(19200);

pinMode(but2, INPUT);
pinMode(but3, INPUT);
pinMode(but4, INPUT);
pinMode(but5, INPUT);
pinMode(but6, INPUT);
pinMode(but7, INPUT);
pinMode(but8, INPUT);
pinMode(but9, INPUT);
pinMode(but10, INPUT);
pinMode(but11, INPUT);
pinMode(but12, INPUT);
}

void sendUSB(int chan, int value){
Serial.print(chan,BYTE);
delay(5);
Serial.print(value,BYTE);
delay(5);
}

void loop(){

analog0 = analogRead(pot0);    // reads all analog inputs
analog1 = analogRead(pot1);
analog2 = analogRead(pot2);
analog3 = analogRead(pot3);
analog4 = analogRead(pot4);
analog5 = analogRead(pot5);

digital2 = digitalRead(but2);   // reads all digital inputs
digital3 = digitalRead(but3);
digital4 = digitalRead(but4);
digital5 = digitalRead(but5);
digital6 = digitalRead(but6);
digital7 = digitalRead(but7);
digital8 = digitalRead(but8);
digital9 = digitalRead(but9);
digital10 = digitalRead(but10);
digital11 = digitalRead(but11);
digital12 = digitalRead(but12);

// sends data only when a button is pressed

if (digital2 == 0){
Serial.print(200,BYTE);      // sends the code 200 for the first button
delay(200);                  // 201 – 2nd button
}                              // 202 – 3rd button
// ……
if (digital3 == 0){
Serial.print(201,BYTE);
delay(200);
}

if (digital4 == 0){
Serial.print(202,BYTE);
delay(200);
}

if (digital5 == 0){
Serial.print(203,BYTE);
delay(200);
}

if (digital6 == 0){
Serial.print(204,BYTE);
delay(200);
}

if (digital7 == 0){
Serial.print(205,BYTE);
delay(200);
}

if (digital8 == 0){
Serial.print(206,BYTE);
delay(200);
}

if (digital9 == 0){
Serial.print(207,BYTE);
delay(200);
}

if (digital10 == 0){
Serial.print(208,BYTE);
delay(200);
}

if (digital11 == 0){
Serial.print(209,BYTE);
delay(200);
}

if (digital12 == 0){
Serial.print(210,BYTE);
delay(200);
}

// sends data only when a potenciometer changes its value

if ((analog0 < analog0old -10)||(analog0 > analog0old + 10)){
sendUSB(211,analog0/8);      // sends the code 211 for the first potenciometer
analog0old = analog0;        // 212 – 2nd pot
}                              // …..

if ((analog1 < analog1old -10)||(analog1 > analog1old + 10)){
sendUSB(212,analog1/8);
analog1old = analog1;
}
if ((analog2 < analog2old -10)||(analog2 > analog2old + 10)){
sendUSB(213,analog2/8);
analog2old = analog2;
}

if ((analog3 < analog3old -10)||(analog3 > analog3old + 10)){
sendUSB(214,analog3/8);
analog3old = analog3;
}

if ((analog4 < analog4old -10)||(analog4 > analog4old + 10)){
sendUSB(215,analog4/8);
analog4old = analog4;
}

if ((analog5 < analog5old -10)||(analog5 > analog5old + 10)){
sendUSB(216,analog5/8);
analog5old = analog5;
}
}

One response

28 05 2009
instintov

hi do you have a pd pach????
sorry Im not speack inglish

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.

%d bloggers like this: