Wiki

Reso-nance numérique | Arts et cultures libres

Outils du site


projets:malinette-brutbox:brutbox-firmware-old:accueil

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

projets:malinette-brutbox:brutbox-firmware-old:accueil [2015/06/11 17:04]
resonance créée
— (Version actuelle)
Ligne 1: Ligne 1:
-=== 6 capteurs === 
-  * Fichier : {{:projets:malinette-brutbox:teensy_brutbox_x6.ino|}} 
  
-++++ teensy_brutbox_x6.ino | 
-<code cpp> 
-// the MIDI channel number to send messages 
-const int channel = 1; 
- 
-// the MIDI continuous controller for each analog input 
-const int controllerA0 = 10; // 10 = pan position 
-const int controllerA1 = 11; // 11 = volume/expression 
-const int controllerA2 = 12; // 91 = reverb level 
-const int controllerA3 = 13; // 93 = chorus level 
-const int controllerA4 = 14; // 93 = chorus level 
-const int controllerA5 = 15; // 93 = chorus level 
- 
-void setup() { 
-} 
- 
-// store previously sent values, to detect changes 
-int previousA0 = -1; 
-int previousA1 = -1; 
-int previousA2 = -1; 
-int previousA3 = -1; 
-int previousA4 = -1; 
-int previousA5 = -1; 
-elapsedMillis msec = 0; 
- 
-void loop() { 
-  // only check the analog inputs 50 times per second, 
-  // to prevent a flood of MIDI messages 
-  if (msec >= 50) { 
-    msec = 0; 
-    int n0 = analogRead(A0) / 8; 
-    int n1 = analogRead(A1) / 8; 
-    int n2 = analogRead(A2) / 8; 
-    int n3 = analogRead(A3) / 8; 
-    int n4 = analogRead(A4) / 8; 
-    int n5 = analogRead(A5) / 8;     
-    // only transmit MIDI messages if analog input changed 
-    if (n0 != previousA0) { 
-      usbMIDI.sendControlChange(controllerA0, n0, channel); 
-      previousA0 = n0; 
-    } 
-    if (n1 != previousA1) { 
-      usbMIDI.sendControlChange(controllerA1, n1, channel); 
-      previousA1 = n1; 
-    } 
-    if (n2 != previousA2) { 
-      usbMIDI.sendControlChange(controllerA2, n2, channel); 
-      previousA2 = n2; 
-    } 
-    if (n3 != previousA3) { 
-      usbMIDI.sendControlChange(controllerA3, n3, channel); 
-      previousA3 = n3; 
-    } 
-    if (n4 != previousA4) { 
-      usbMIDI.sendControlChange(controllerA4, n4, channel); 
-      previousA4 = n4; 
-    } 
-    if (n5 != previousA5) { 
-      usbMIDI.sendControlChange(controllerA5, n5, channel); 
-      previousA5 = n5; 
-    } 
-  } 
- 
-  // MIDI Controllers should discard incoming MIDI messages. 
-  // http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash 
-  while (usbMIDI.read()) { 
-    // ignore incoming messages 
-  } 
-} 
-</code> 
-++++ 
- 
-=== Avec Encoder === 
-  * Ajouter la bibliothèque : http://www.pjrc.com/teensy/arduino_libraries/Encoder.zip ([[https://www.pjrc.com/teensy/td_libs_Encoder.html|source]]) 
- 
-{{:projets:malinette-brutbox:rotary_encoder_arduino_hookup.png?200|}} 
- 
-=== Avec capacitif MPR121 === 
-  * Module MPR121 : https://www.adafruit.com/products/1982. Alimention possible en 5V ou 3.3V 
-  * Ajouter la bibliothèque : https://github.com/adafruit/Adafruit_MPR121_Library ([[https://learn.adafruit.com/adafruit-mpr121-12-key-capacitive-touch-sensor-breakout-tutorial/wiring|source]]) 
- 
-{{:projets:malinette-brutbox:mpr121.png?200|}} 
- 
- 
-=== Teensy for BrutBox  === 
-  * Fichiers : {{:projets:malinette-brutbox:pd-teensy-brutbox.zip|}} 
-  * Midi : https://www.pjrc.com/teensy/td_midi.html et https://www.pjrc.com/teensy/td_libs_MIDI.html 
- 
-**Avec Pure Data** : 
-{{:projets:malinette-brutbox:pd-brutbox.png|}} 
- 
-**Avec Arduino** : 
-++++ teensy_brutbox_2.ino | 
-<code cpp> 
-// TEENSY 2 - BRUTBOX 
-// Control inputs (sensors) with MIDI messages 
-// 08/06/2015 - http://reso-nance.org 
- 
-#include <Wire.h> 
-#include "Adafruit_MPR121.h" 
-#include <Encoder.h> 
- 
-// Capacitive apacitive MPR121 
-// Connection Teensy2  
-// USB wiring : d+ : SDA, d- : SCL, SCL = DO, SDA = D1  
-Adafruit_MPR121 cap = Adafruit_MPR121(); 
-const int touchNb = 12; // number of touch inputs 
-const int touchThreshold = 60; 
-int touchStateCtl[] = {40, 41, 42} ; // touch on/off 
-int touchState[touchNb]; // state : on/off 
-int currentTouchValues[touchNb];  
-int lastTouchValues[touchNb]; 
-int touchCtl[] = {60,61,62,63,64,65,66,67,68,69,70,71}; // note in 
-int touchOn = 0; 
- 
- 
-// Analog setup 
-int anaPins[] = {22,11,12,13,14,15,16,17,18,19,20,21}; // analog pins 
-const int anaNb = 12; // number of inputs 
-int anaCtl[] = {11,10,9,8,7,6,5,4,3,2,1,0}; // controller in 
-int anaStateCtl[] = {20, 21} ; // sensor on (20), sensor off (21) 
-int anaState[anaNb]; // state : on/off 
-int anaValues[anaNb]; // current analog values 
-int anaLastValues[anaNb]; // previous analog values 
- 
- 
-// Encoder setup 
-Encoder encoderSensor (7, 8); 
-long encoderOldPosition  = -999; 
-long encoderNewPosition; 
-int encoderStateCtl = 13; // receive ctlout 13 
-int encoderOn = 0; 
- 
-const int channel = 1; 
- 
-// Sampling rate 
-const long interval = 30; 
-unsigned long currentMillis; 
-unsigned long previousMillis = 0; 
- 
- 
-void setup() {  
-  // Midi receive : on/off sensors  
-  usbMIDI.setHandleControlChange(OnControlChange); 
- 
- 
-void loop() { 
-  currentMillis = millis(); 
-  if(currentMillis - previousMillis >= interval) { 
-      previousMillis = currentMillis; 
- 
-      // Analog sensors loop 
-      for (int i = 0; i < anaNb; i++) { 
-          if(anaState[i] == 1)  { // check first if the sensor is on 
-              anaValues[i] = (int) analogRead(anaPins[i])  / 8 ; 
-              Serial.println(anaValues[i]); 
-              if (anaValues[i] != anaLastValues[i]) {   
-                  usbMIDI.sendControlChange(anaCtl[i], anaValues[i], channel); 
-                  anaLastValues[i] = anaValues[i]; 
-       } 
-          } 
-       } 
-        
-      // Capacitive loop 
-       
-      if(touchOn == 1){ 
-      for (uint8_t i=0; i < touchNb; i++) { 
-         if(touchState[i] == 1)  { // check first if the sensor is on 
-          currentTouchValues[i] = cap.filteredData(i); 
-          if ((currentTouchValues[i] - lastTouchValues[i]) < -touchThreshold) { 
-            usbMIDI.sendNoteOn(touchCtl[i], 127, channel); 
-          } 
-          if ((currentTouchValues[i] - lastTouchValues[i]) > touchThreshold) { 
-            usbMIDI.sendNoteOn(touchCtl[i], 0, channel); 
-          } 
-          lastTouchValues[i] = currentTouchValues[i]; 
-        } 
-      } 
-      } 
-      
-      
-     // Encoder 
-     if (encoderOn == 1) { 
-     encoderNewPosition = encoderSensor.read(); 
-     if (encoderNewPosition != encoderOldPosition) { 
-      encoderOldPosition = encoderNewPosition; 
-      usbMIDI.sendControlChange(12, encoderNewPosition, channel); 
-      } 
-     } 
-  } 
-     
-  // Discard incoming MIDI messages. 
-  while (usbMIDI.read()) {} 
-} 
- 
-// Receive Midi Control Change 
-void OnControlChange(byte channel, byte control, byte value) { 
-   // Analog sensors on/off 
-   if (control == anaStateCtl[0]) {anaState[-value+(anaNb-1)] = 0;} 
-   else if (control == anaStateCtl[1]) {anaState[-value+(anaNb-1)] = 1;} 
-   else if (control == touchStateCtl[0]) {touchState[value] = 0;} 
-   else if (control == touchStateCtl[1]) {touchState[value] = 1;} 
-   else if (control == touchStateCtl[2]) { 
-     touchOn = value; 
-     if (touchOn == 1) { 
-       cap.begin(0x5A); 
-       for (uint8_t i=0; i<4; i++) {lastTouchValues[i] = cap.filteredData(i); } 
-     } 
-   } 
-   else if (control == encoderStateCtl) {encoderOn = value;} 
-} 
-</code> 
-++++ 
/home/resonancg/www/wiki/data/attic/projets/malinette-brutbox/brutbox-firmware-old/accueil.1434035079.txt.gz · Dernière modification: 2015/06/11 17:04 de resonance