Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
wiki:flossmanuals:controleur-midi-pour-image:accueil [2021/04/29 13:50] 127.0.0.1 modification externe |
wiki:flossmanuals:controleur-midi-pour-image:accueil [2021/06/01 17:23] (Version actuelle) damien.muti |
||
---|---|---|---|
Ligne 9: | Ligne 9: | ||
* carte Arduino Uno / Seeduino | * carte Arduino Uno / Seeduino | ||
* bouton poussoir | * bouton poussoir | ||
- | * | + | * 2 potentiomètres rotatifs |
+ | * 2 potentiomètres slider | ||
---- | ---- | ||
Ligne 18: | Ligne 19: | ||
L’idée est de pouvoir gérer du visuel en interaction avec la musique, grâce à un contrôleur midi constitué de deux slider, deux potentiomètres, | L’idée est de pouvoir gérer du visuel en interaction avec la musique, grâce à un contrôleur midi constitué de deux slider, deux potentiomètres, | ||
+ | |||
+ | {{: | ||
===== Plans et schémas de fonctionnement ===== | ===== Plans et schémas de fonctionnement ===== | ||
+ | |||
+ | {{: | ||
Ligne 25: | Ligne 30: | ||
==== Arduino ==== | ==== Arduino ==== | ||
- | === essai 1 === | + | === essai 1 / SerialCallResponse |
- | + | < | |
- | const int potentiometer | + | int potentiometre1 |
- | const int potentiometer2 | + | int potentiometre2 |
- | const int bouton | + | int potentiometre3 |
- | const int slider | + | int potentiometre4 |
- | + | int bouton = 8; // digital sensor | |
+ | int inByte = 0; // incoming serial byte | ||
void setup() { | void setup() { | ||
+ | // start serial port at 9600 bps: | ||
Serial.begin(9600); | Serial.begin(9600); | ||
- | | + | |
+ | | ||
+ | } | ||
+ | pinMode(8, INPUT); | ||
+ | establishContact(); | ||
} | } | ||
void loop() { | void loop() { | ||
- | | + | // if we get a valid byte, read analog ins: |
- | | + | if (Serial.available() > 0) { |
- | Serial.println(analogRead(potentiometer2)); | + | // get incoming byte: |
- | | + | inByte = Serial.read(); |
- | Serial.println(digitalRead(bouton)); | + | // read first analog input, divide by 4 to make the range 0-255: |
- | delay(500); | + | potentiometre1 = analogRead(A0) / 4; |
- | | + | // delay 10ms to let the ADC recover: |
- | + | | |
+ | // read second analog input, divide by 4 to make the range 0-255: | ||
+ | potentiometre2 = analogRead(A1) / 4; | ||
+ | delay(10); | ||
+ | | ||
+ | // delay 10ms to let the ADC recover: | ||
+ | | ||
+ | // read second analog input, divide by 4 to make the range 0-255: | ||
+ | potentiometre4 = analogRead(A3) / 4; | ||
+ | // read switch, map it to 0 or 255L | ||
+ | bouton = map(digitalRead(8), 0, 1, 0, 255); | ||
+ | // send sensor values: | ||
+ | Serial.write(potentiometre1); | ||
+ | Serial.write(potentiometre2); | ||
+ | Serial.write(potentiometre3); | ||
+ | Serial.write(potentiometre4); | ||
+ | | ||
+ | } | ||
} | } | ||
+ | void establishContact() { | ||
+ | while (Serial.available() <= 0) { | ||
+ | Serial.print(' | ||
+ | delay(300); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
==== Processing ==== | ==== Processing ==== | ||
J'ai trouvé ce programme [[https:// | J'ai trouvé ce programme [[https:// | ||
+ | < | ||
import processing.serial.*; | import processing.serial.*; | ||
- | Serial myPort; | + | // variables pour stoquer les données arduino (au nombre de 5) |
- | + | ||
- | import themidibus.*; | + | |
- | import javax.sound.midi.MidiMessage; | + | |
- | import javax.sound.midi.SysexMessage; | + | |
- | import javax.sound.midi.ShortMessage; | + | |
- | MidiBus myBus; | + | |
- | // Setting up the triangles | + | // variables |
float widthgap; | float widthgap; | ||
float heightgap; | float heightgap; | ||
Ligne 70: | Ligne 98: | ||
int rows = 11; | int rows = 11; | ||
int numOfTriangles; | int numOfTriangles; | ||
- | Triangle[] triangles; | + | Triangle[] triangles; |
- | // How many frames from old variable to the next, higher is smoother but less responsive. | + | float animationSpeed = 50; |
- | int animationSpeed = 50; | + | |
- | // Lowering this leads to fadeytrails. | + | |
float backgroundOpacity = 100; | float backgroundOpacity = 100; | ||
- | //Serial myPort; | ||
- | void setup() { | + | Serial |
- | printArray(Serial.list()); | + | int Narduino = 5; // nombre de données envoyées par la carte Arduino |
- | myPort | + | int[] serialInArray |
+ | int serialCount = 0; | ||
+ | int xpos, ypos; // A count of how many bytes we receive | ||
+ | boolean firstContact = false; | ||
+ | |||
+ | void setup() { | ||
size(1920, 1080, P3D); | size(1920, 1080, P3D); | ||
// | // | ||
Ligne 87: | Ligne 117: | ||
background(0); | background(0); | ||
smooth(); | smooth(); | ||
+ | | ||
- | // Set up gap to lay out spacing between the triangles | + | |
+ | |||
+ | | ||
widthgap = 100; | widthgap = 100; | ||
heightgap = 100; | heightgap = 100; | ||
numOfTriangles = cols*rows; | numOfTriangles = cols*rows; | ||
+ | ; | ||
+ | // Print a list of the serial ports, for debugging purposes: | ||
+ | printArray(Serial.list()); | ||
- | //MidiBus.list(); // List all available Midi devices | + | // I know that the first port in the serial |
- | //myBus = new MidiBus(this, 0, 0); // Create a new MidiBus object | + | // is always my FTDI adaptor, so I open Serial.list()[0]. |
- | // String portName = Serial.list()[4]; | + | |
- | // myPort = new Serial(this, | + | // Open whatever port is the one you're using. |
+ | | ||
+ | myPort = new Serial(this, | ||
+ | |||
- | // Create an array of all the triangles | ||
triangles = new Triangle[numOfTriangles]; | triangles = new Triangle[numOfTriangles]; | ||
for (int i=0; i< | for (int i=0; i< | ||
int row = i/cols; | int row = i/cols; | ||
- | int col = i%cols; | + | int col = i%cols; |
triangles[i] = new Triangle(col, | triangles[i] = new Triangle(col, | ||
triangles[i] = new Triangle(col, | triangles[i] = new Triangle(col, | ||
} | } | ||
} | } | ||
- | void draw() { | ||
- | | + | void draw() { |
+ | | ||
fill(0, 0, 0, backgroundOpacity); | fill(0, 0, 0, backgroundOpacity); | ||
translate(-width*2, | translate(-width*2, | ||
rect(0, 0, width*5, height*5); | rect(0, 0, width*5, height*5); | ||
- | translate(width*2, | + | translate(width*2, |
- | // Update and draw all the triangles | ||
for (int i=0; i< | for (int i=0; i< | ||
triangles[i].update(); | triangles[i].update(); | ||
Ligne 126: | Ligne 162: | ||
} | } | ||
- | void keyPressed() { | + | void serialEvent(Serial myPort) { |
- | + | // read a byte from the serial port: | |
- | if (keyCode | + | int inByte = myPort.read(); |
- | | + | // if this is the first byte received, and it's an A, |
- | | + | // clear the serial buffer and note that you' |
+ | // had first contact from the microcontroller. | ||
+ | // Otherwise, add the incoming byte to the array: | ||
+ | if (firstContact | ||
+ | | ||
+ | | ||
+ | firstContact | ||
+ | myPort.write(' | ||
} | } | ||
- | } | + | } else { |
+ | // Add the latest byte from the serial port to array: | ||
+ | serialInArray[serialCount] = inByte; | ||
+ | serialCount++; | ||
- | | + | // If we have 3 bytes: |
- | for (int i=0; i< | + | |
- | triangles[i].newSize-=10; | + | for (int i=0; i< |
- | } | + | triangles[i].newSize = serialInArray[0]; |
- | | + | |
+ | | ||
+ | triangles[i].newHueOffset | ||
+ | ypos = serialInArray[4]; | ||
- | if (keyCode == LEFT) { | + | // print the values |
- | backgroundOpacity-=10; | + | |
- | } | + | |
- | if (keyCode == RIGHT) { | + | // Send a capital A to request new sensor readings: |
- | | + | myPort.write(' |
+ | // Reset serialCount: | ||
+ | serialCount | ||
+ | } | ||
} | } | ||
} | } | ||
+ | } | ||
+ | </ | ||
+ | ===== Améliorations ===== | ||
+ | |||
+ | Le problème que j'ai rencontré c'est un manque de réactivité entre mon geste et le résultat obtenu sur processing, le but étant justement de pouvoir créer et modifier du visuel en live il vaudrait peut-être mieux envoyer directement des valeurs plutôt que des A. | ||
+ | |||
+ | |||
==== Références : DIY midi controller ==== | ==== Références : DIY midi controller ==== |