xxxxxxxxxx
import themidibus.*;
import processing.serial.*;
import cc.arduino.*;
MidiBus myBus; // The MidiBus
Arduino arduino;
color off = color(4, 79, 111);
color on = color(84, 145, 158);
void setup() {
size(470, 470);
textSize (32);
textAlign(CENTER,CENTER);
fill(0);
text ("[arduino firmata -> MIDI CC]",width/2,height/2);
// Prints out the available serial ports.
println(Arduino.list());
// Modify this line, by changing the "0" to the index of the serial
// port corresponding to your Arduino board (as it appears in the list
// printed by the line above).
arduino = new Arduino(this, Arduino.list()[11], 57600);
// Alternatively, use the name of the serial port corresponding to your
// Arduino (in double-quotes), as in the following line.
//arduino = new Arduino(this, "/dev/tty.usbmodem621", 57600);
// Set the Arduino digital pins as inputs.
for (int i = 0; i <= 13; i++)
arduino.pinMode(i, Arduino.INPUT);
MidiBus.list(); // List all available Midi devices on STDOUT. This will show each device's index and name.
myBus = new MidiBus(this, -1, "Bus 1"); // Create a new MidiBus with no input device and the default Java Sound Synthesizer as the output device.
}
void draw() {
background(off);
stroke(on);
// Draw a filled box for each digital pin that's HIGH (5 volts).
for (int i = 0; i <= 13; i++) {
if (arduino.digitalRead(i) == Arduino.HIGH)
fill(on);
else
fill(off);
rect(420 - i * 30, 30, 20, 20);
}
// Draw a circle whose size corresponds to the value of an analog input.
noFill();
for (int i = 0; i <= 5; i++) {
ellipse(280 + i * 30, 240, arduino.analogRead(i) / 16, arduino.analogRead(i) / 16);
}
//myBus.sendControllerChange(channel, number, value); // Send a controllerChange
// analog read is 0-1023
// midi CC is 0-127
int midiVal = int(map(arduino.analogRead(0),0,1023,0,127));
myBus.sendControllerChange(0, 0, midiVal); // Send a controllerChange
}
void controllerChange(int channel, int number, int value) {
// Receive a controllerChange
println();
println("Controller Change:");
println("--------");
println("Channel:"+channel);
println("Number:"+number);
println("Value:"+value);
}
void delay(int time) {
int current = millis();
while (millis () < current+time) Thread.yield();
}