Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
|
projets:teensy4malinette:accueil [2015/05/05 11:25] resonance [Mode MIDI] |
— (Version actuelle) | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ====== Teensy4Malinette ====== | ||
| - | * Porteur du projet : fenshu | ||
| - | * Date : 09 > 12/2014 | ||
| - | * Licence : libre ! | ||
| - | * Contexte : Développement pour le projet [[: | ||
| - | * Fichiers : ... | ||
| - | * Lien : ... | ||
| - | ===== Description ===== | ||
| - | {{ : | ||
| - | |||
| - | **Utiliser Teensy 2.0 en mode hid (joystick) ou midi** \\ | ||
| - | L' | ||
| - | ===== Matériaux ===== | ||
| - | * Carte teensy (2.0) | ||
| - | * Capteurs | ||
| - | * Pure-data ou pas (en mode MIDI) | ||
| - | |||
| - | ===== Installation ===== | ||
| - | * [[https:// | ||
| - | |||
| - | ===== Mode HID joystick ===== | ||
| - | - Choisir mouse, | ||
| - | - Ouvrir l' | ||
| - | [[https:// | ||
| - | |||
| - | **Les Entrées analogiques : route dans pd-extended** \\ | ||
| - | Ouvrir l'aide de l' | ||
| - | {{ : | ||
| - | * F1 = 4 | ||
| - | * ... | ||
| - | * ... | ||
| - | * ... | ||
| - | * | ||
| - | |||
| - | |||
| - | |||
| - | :!: **Attention Hid ne parait pas stable.**.. trop d'info ? Interval a mettre resample ? | ||
| - | |||
| - | ===== Mode MIDI ===== | ||
| - | |||
| - | L' | ||
| - | |||
| - | {{ : | ||
| - | |||
| - | **Note :** la pin 4 en pwm ne marche pas .... ??? \\ | ||
| - | A télécharger : {{: | ||
| - | |||
| - | **Code Arduino** pour configurer les pins de la teensy en midi | ||
| - | ++++ teensy4malinette.ino (midi) | | ||
| - | <code java> | ||
| - | |||
| - | // PIN CONFIGURATION : | ||
| - | // | ||
| - | // 5 analog input : a0, | ||
| - | // 6 digital input : 16, | ||
| - | // OUT ::: | ||
| - | // 4 digital | ||
| - | // 4 pwm : 4 5 9 10 | ||
| - | // 3 servo : 6 7 8 CCOUT:106 107 108 | ||
| - | |||
| - | // !! COMMENT : pin 4 pwm marche pas ! digout allumé au debut...? | ||
| - | |||
| - | // MIDI CHANNEL : 1 | ||
| - | // ---------------------- | ||
| - | |||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | // the MIDI channel number to send messages | ||
| - | const int channel = 1; | ||
| - | |||
| - | //analog in | ||
| - | // the MIDI continuous controller for each analog input | ||
| - | const int controllerA0 = 10; //CCin n° | ||
| - | const int controllerA1 = 11; | ||
| - | const int controllerA2 = 12; | ||
| - | const int controllerA3 = 13; | ||
| - | const int controllerA4 = 14; | ||
| - | // store previously sent values, to detect changes | ||
| - | int previousA0 = -1; | ||
| - | int previousA1 = -1; | ||
| - | int previousA2 = -1; | ||
| - | int previousA3 = -1; | ||
| - | int previousA4 = -1; | ||
| - | elapsedMillis msec = 0; | ||
| - | |||
| - | // digital in | ||
| - | Bounce button0 = Bounce(16, 5); | ||
| - | Bounce button1 = Bounce(15, 5); // 5 = 5 ms debounce time | ||
| - | Bounce button2 = Bounce(14, 5); // which is appropriate for good | ||
| - | Bounce button3 = Bounce(13, 5); // quality mechanical pushbuttons | ||
| - | Bounce button4 = Bounce(12, 5); | ||
| - | Bounce button5 = Bounce(11, 5); | ||
| - | |||
| - | // DIGITAL OUT | ||
| - | int digout1 = 0; //pin definition | ||
| - | int digout2 = 1; | ||
| - | int digout3 = 2; | ||
| - | int digout4 = 3; | ||
| - | int valdigout1 = 0; | ||
| - | int valdigout2 = 0; | ||
| - | int valdigout3 = 0; | ||
| - | int valdigout4 = 0; | ||
| - | |||
| - | // PWM | ||
| - | int pwm1 = 4; //pin definition | ||
| - | int pwm2 = 5; | ||
| - | int pwm3 = 9; | ||
| - | int pwm4 = 10; | ||
| - | int valpwm1 = 0; // variable to store the pwm | ||
| - | int valpwm2 = 0; | ||
| - | int valpwm3 = 0; | ||
| - | int valpwm4 = 0; | ||
| - | |||
| - | //servo | ||
| - | Servo myservo1; | ||
| - | Servo myservo2; | ||
| - | Servo myservo3; | ||
| - | int pos1 = 0; // variable to store the servo position | ||
| - | int pos2 = 0; | ||
| - | int pos3 = 0; | ||
| - | |||
| - | |||
| - | // =============SETUPPPPPP ============================= | ||
| - | |||
| - | void setup() { | ||
| - | //digital IN BUTTON | ||
| - | pinMode(16, INPUT_PULLUP); | ||
| - | pinMode(15, INPUT_PULLUP); | ||
| - | pinMode(14, INPUT_PULLUP); | ||
| - | pinMode(13, INPUT_PULLUP); | ||
| - | pinMode(12, INPUT_PULLUP); | ||
| - | pinMode(11, INPUT_PULLUP); | ||
| - | | ||
| - | usbMIDI.setHandleControlChange(OnControlChange); | ||
| - | //servo | ||
| - | myservo1.attach(6); | ||
| - | myservo2.attach(7); | ||
| - | myservo3.attach(8); | ||
| - | | ||
| - | usbMIDI.setHandleNoteOn(OnNoteOn); | ||
| - | // | ||
| - | pinMode(digout1, | ||
| - | pinMode(digout2, | ||
| - | pinMode(digout3, | ||
| - | pinMode(digout4, | ||
| - | // pwm | ||
| - | pinMode(pwm1, | ||
| - | pinMode(pwm2, | ||
| - | pinMode(pwm3, | ||
| - | pinMode(pwm4, | ||
| - | } | ||
| - | |||
| - | // ==========LOOOOOOPP ============================= | ||
| - | void loop() { | ||
| - | // pour ecouter le midi pour les sorties | ||
| - | usbMIDI.read(1); | ||
| - | |||
| - | //update button (digital in) | ||
| - | button0.update(); | ||
| - | button1.update(); | ||
| - | button2.update(); | ||
| - | button3.update(); | ||
| - | button4.update(); | ||
| - | button5.update(); | ||
| - | | ||
| - | if (button0.fallingEdge()) { | ||
| - | usbMIDI.sendNoteOn(60, | ||
| - | } | ||
| - | if (button1.fallingEdge()) { | ||
| - | usbMIDI.sendNoteOn(61, | ||
| - | } | ||
| - | if (button2.fallingEdge()) { | ||
| - | usbMIDI.sendNoteOn(62, | ||
| - | } | ||
| - | if (button3.fallingEdge()) { | ||
| - | usbMIDI.sendNoteOn(63, | ||
| - | } | ||
| - | if (button4.fallingEdge()) { | ||
| - | usbMIDI.sendNoteOn(64, | ||
| - | } | ||
| - | if (button5.fallingEdge()) { | ||
| - | usbMIDI.sendNoteOn(65, | ||
| - | } | ||
| - | | ||
| - | // | ||
| - | if (button0.risingEdge()) { | ||
| - | usbMIDI.sendNoteOff(60, | ||
| - | } | ||
| - | if (button1.risingEdge()) { | ||
| - | usbMIDI.sendNoteOff(61, | ||
| - | } | ||
| - | if (button2.risingEdge()) { | ||
| - | usbMIDI.sendNoteOff(62, | ||
| - | } | ||
| - | if (button3.risingEdge()) { | ||
| - | usbMIDI.sendNoteOff(63, | ||
| - | } | ||
| - | if (button4.risingEdge()) { | ||
| - | usbMIDI.sendNoteOff(64, | ||
| - | } | ||
| - | if (button5.risingEdge()) { | ||
| - | usbMIDI.sendNoteOff(65, | ||
| - | } | ||
| - | | ||
| - | | ||
| - | // only check the analog inputs 50 times per second, | ||
| - | // to prevent a flood of MIDI messages | ||
| - | if (msec >= 20) { | ||
| - | 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; | ||
| - | // 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; | ||
| - | } | ||
| - | } | ||
| - | |||
| - | |||
| - | |||
| - | // MIDI Controllers should discard incoming MIDI messages. | ||
| - | // http:// | ||
| - | while (usbMIDI.read()) { | ||
| - | // ignore incoming messages | ||
| - | } | ||
| - | } | ||
| - | |||
| - | // mapping NOTEOUT ON : digitalout | ||
| - | void OnNoteOn(byte channel, byte note, byte velocity) { | ||
| - | Serial.print(" | ||
| - | Serial.print(channel, | ||
| - | Serial.print(", | ||
| - | Serial.print(note, | ||
| - | Serial.print(", | ||
| - | Serial.print(velocity, | ||
| - | Serial.println(); | ||
| - | | ||
| - | if (note== 0) { | ||
| - | int valdigout1=velocity/ | ||
| - | digitalWrite(digout1, | ||
| - | } | ||
| - | | ||
| - | if (note== 1) { | ||
| - | int valdigout2=velocity/ | ||
| - | digitalWrite(digout2, | ||
| - | } | ||
| - | | ||
| - | if (note== 2) { | ||
| - | int valdigout3=velocity/ | ||
| - | digitalWrite(digout3, | ||
| - | } | ||
| - | | ||
| - | if (note== 3) { | ||
| - | int valdigout4=velocity/ | ||
| - | digitalWrite(digout4, | ||
| - | } | ||
| - | } | ||
| - | |||
| - | // mapping CC OUT :: PWM & SERVO | ||
| - | void OnControlChange(byte channel, byte control, byte value) { | ||
| - | //PWM | ||
| - | if (control== 102) { | ||
| - | int valpwm1=map(value, | ||
| - | analogWrite(pwm1, | ||
| - | } | ||
| - | if (control== 103) { | ||
| - | int valpwm2=map(value, | ||
| - | analogWrite(pwm2, | ||
| - | } | ||
| - | if (control== 104) { | ||
| - | int valpwm3=map(value, | ||
| - | analogWrite(pwm3, | ||
| - | } | ||
| - | if (control== 105) { | ||
| - | int valpwm4=map(value, | ||
| - | analogWrite(pwm4, | ||
| - | } | ||
| - | | ||
| - | //SERVO | ||
| - | if (control== 106) { | ||
| - | int pos1=map(value, | ||
| - | myservo1.write(pos1); | ||
| - | } | ||
| - | if (control== 107) { | ||
| - | int pos2=map(value, | ||
| - | myservo2.write(pos2); | ||
| - | } | ||
| - | if (control== 108) { | ||
| - | int pos3=map(value, | ||
| - | myservo3.write(pos3); | ||
| - | } | ||
| - | | ||
| - | } | ||
| - | |||
| - | |||
| - | </ | ||
| - | ++++ | ||
| - | ==== Servo midi ==== | ||
| - | Controler un servo en midi | ||
| - | |||
| - | <code c> | ||
| - | #include < | ||
| - | Servo myservo; | ||
| - | // a maximum of eight servo objects can be created | ||
| - | int pos = 0; // variable to store the servo position | ||
| - | |||
| - | void setup() | ||
| - | { | ||
| - | myservo.attach(20); | ||
| - | usbMIDI.setHandleNoteOn(myNoteOn); | ||
| - | } | ||
| - | |||
| - | void loop() | ||
| - | { | ||
| - | usbMIDI.read(1); | ||
| - | } | ||
| - | |||
| - | void myNoteOn(byte channel, byte note, byte velocity) | ||
| - | { | ||
| - | int pos=map(note, | ||
| - | myservo.write(pos); | ||
| - | } | ||
| - | |||
| - | </ | ||
| - | ===== Photos ===== | ||
| - | Autres photos, galerie, ... | ||
| - | |||
| - | {{tag> | ||