Ci-dessous, les différences entre deux révisions de la page.
projets:malinette-brutbox:brutbox-firmware-old:accueil [2015/06/11 17:04] resonance créée |
— (Version actuelle) | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | === 6 capteurs === | ||
- | * Fichier : {{: | ||
- | ++++ 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/ | ||
- | 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, | ||
- | previousA0 = n0; | ||
- | } | ||
- | if (n1 != previousA1) { | ||
- | usbMIDI.sendControlChange(controllerA1, | ||
- | previousA1 = n1; | ||
- | } | ||
- | if (n2 != previousA2) { | ||
- | usbMIDI.sendControlChange(controllerA2, | ||
- | previousA2 = n2; | ||
- | } | ||
- | if (n3 != previousA3) { | ||
- | usbMIDI.sendControlChange(controllerA3, | ||
- | previousA3 = n3; | ||
- | } | ||
- | if (n4 != previousA4) { | ||
- | usbMIDI.sendControlChange(controllerA4, | ||
- | previousA4 = n4; | ||
- | } | ||
- | if (n5 != previousA5) { | ||
- | usbMIDI.sendControlChange(controllerA5, | ||
- | previousA5 = n5; | ||
- | } | ||
- | } | ||
- | |||
- | // MIDI Controllers should discard incoming MIDI messages. | ||
- | // http:// | ||
- | while (usbMIDI.read()) { | ||
- | // ignore incoming messages | ||
- | } | ||
- | } | ||
- | </ | ||
- | ++++ | ||
- | |||
- | === Avec Encoder === | ||
- | * Ajouter la bibliothèque : http:// | ||
- | |||
- | {{: | ||
- | |||
- | === Avec capacitif MPR121 === | ||
- | * Module MPR121 : https:// | ||
- | * Ajouter la bibliothèque : https:// | ||
- | |||
- | {{: | ||
- | |||
- | |||
- | === Teensy for BrutBox | ||
- | * Fichiers : {{: | ||
- | * Midi : https:// | ||
- | |||
- | **Avec Pure Data** : | ||
- | {{: | ||
- | |||
- | **Avec Arduino** : | ||
- | ++++ teensy_brutbox_2.ino | | ||
- | <code cpp> | ||
- | // TEENSY 2 - BRUTBOX | ||
- | // Control inputs (sensors) with MIDI messages | ||
- | // 08/06/2015 - http:// | ||
- | |||
- | #include < | ||
- | #include " | ||
- | #include < | ||
- | |||
- | // 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]; | ||
- | int currentTouchValues[touchNb]; | ||
- | int lastTouchValues[touchNb]; | ||
- | int touchCtl[] = {60, | ||
- | int touchOn = 0; | ||
- | |||
- | |||
- | // Analog setup | ||
- | int anaPins[] = {22, | ||
- | const int anaNb = 12; // number of inputs | ||
- | int anaCtl[] = {11, | ||
- | int anaStateCtl[] = {20, 21} ; // sensor on (20), sensor off (21) | ||
- | int anaState[anaNb]; | ||
- | int anaValues[anaNb]; | ||
- | int anaLastValues[anaNb]; | ||
- | |||
- | |||
- | // Encoder setup | ||
- | Encoder encoderSensor (7, 8); | ||
- | long encoderOldPosition | ||
- | 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]) | ||
- | Serial.println(anaValues[i]); | ||
- | if (anaValues[i] != anaLastValues[i]) { | ||
- | usbMIDI.sendControlChange(anaCtl[i], | ||
- | anaLastValues[i] = anaValues[i]; | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | // Capacitive loop | ||
- | | ||
- | if(touchOn == 1){ | ||
- | for (uint8_t i=0; i < touchNb; i++) { | ||
- | | ||
- | currentTouchValues[i] = cap.filteredData(i); | ||
- | if ((currentTouchValues[i] - lastTouchValues[i]) < -touchThreshold) { | ||
- | usbMIDI.sendNoteOn(touchCtl[i], | ||
- | } | ||
- | if ((currentTouchValues[i] - lastTouchValues[i]) > touchThreshold) { | ||
- | usbMIDI.sendNoteOn(touchCtl[i], | ||
- | } | ||
- | lastTouchValues[i] = currentTouchValues[i]; | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | |||
- | // Encoder | ||
- | if (encoderOn == 1) { | ||
- | | ||
- | if (encoderNewPosition != encoderOldPosition) { | ||
- | encoderOldPosition = encoderNewPosition; | ||
- | usbMIDI.sendControlChange(12, | ||
- | } | ||
- | } | ||
- | } | ||
- | | ||
- | // 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]) { | ||
- | | ||
- | if (touchOn == 1) { | ||
- | | ||
- | for (uint8_t i=0; i<4; i++) {lastTouchValues[i] = cap.filteredData(i); | ||
- | } | ||
- | } | ||
- | else if (control == encoderStateCtl) {encoderOn = value;} | ||
- | } | ||
- | </ | ||
- | ++++ |