Teensy 2

N'est plus fabriqué par son concepteur, mais on trouve des clones sur Ebay ou Aliexpress. Parfait pour des interfaces USB midi.

Une version teensy2+ existe avec d'avantage d'E/S.

Nécessite une installation spéciale depuis le site de prjc

https://www.pjrc.com/store/teensy.html

Exemple de code pour reception midi :

//pour Teensy
#define channel_Led  16
#define controllerLed1  1
#define LED1 3 //Digital output with PWM
void setup() {
  // put your setup code here, to run once:
pinMode(LED1, OUTPUT);
analogWrite(LED1,0);

usbMIDI.setHandleControlChange(OnControlChange);
}

void OnControlChange(byte channel, byte control, byte value) {

  if (channel == channel_Led) {
    if (control == controllerLed1) {
      analogWrite(LED1,value*2);
    }
  }
  else {}
}

void loop() {
  // put your main code here, to run repeatedly:

}

autre exemple :

//mise en oeuvre extension de port
//commande les LED par le canal 16
#include <Wire.h>
byte nombreDePotar = 2;
//parametrage
int channel = 1;
int firstNote = 30;
int velocity = 100;
int firstCC  = 1;
int totalCtrl = 3; //nombre d'entrées utilisées pour les controleurs
unsigned long send_interval = 15;
//variables
byte digitalInputState[]      = {0,0,0,0,0,0,0,0,0,0,0,0,0};
byte digitalInputState_prev[] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
byte pinOrder[]               = {0,1,2,3,4,5,6,7,8,9,10,23,24};

byte analogInputValue[]       = {0,0,0,0,0,0,0,0,0,0,0,0};
byte analogInputValue_prev[]  = {0,0,0,0,0,0,0,0,0,0,0,0};
unsigned long analogInputTime[] = {0,0,0,0,0,0,0,0,0,0,0,0};
//////////////////////
byte LEDOnOff[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
//////////////////////

void max6956_init (byte add)
{
  Wire.beginTransmission (add); // transmit to outputs
  Wire.write (0x02);         // sends register address (global current)
  Wire.write (0x0F);         // sends set global current to max (20mA)   
  Wire.endTransmission ();   // stop transmitting

  Wire.beginTransmission (add); // transmit to outputs
  Wire.write (0x04);         // sends register address (config)
  Wire.write (0x01);         // sends set transition detect = 0 /global current set = 1 / normal op.
  Wire.endTransmission ();   // stop transmitting

  Wire.beginTransmission (add); // transmit to outputs
  Wire.write (0x09);         // sends register address (port config)
  Wire.write (0x00);              // 4 - 7 dummy
  Wire.write (0x00);              // 8 -11 dummy
  Wire.write (0x00);             // sends set port 12-14 as LED driver 
  Wire.write (0x00);         // sends set poet 16-17 as LED driver
  Wire.write (0x00);         // sends set port 18-19 as LED driver
  Wire.write (0x00);             // sends set port 24-27 as LED driver
  Wire.write (0x00);              // sends set port 28-31 as LED driver
  Wire.endTransmission ();   // stop transmitting

  Wire.beginTransmission (add); // transmit 
  Wire.write (0x2C);         // sends register address (port 12 on/off) 
  for( int p = 0; p<20; p++)
  {
  Wire.write ((int)0x00);              // port 12-31  OFF
  }
  Wire.endTransmission ();   // stop transmitting
}

void LED_to_MAX6956(byte add)
{
    Wire.beginTransmission (add);                  // transmit to outputs
    Wire.write (0x2C);                          // output P12
    Wire.write ((int)LEDOnOff[0]);                        // P12 led 0
    Wire.write ((int)LEDOnOff[1]);                        // P13 led 1
    Wire.write ((int)LEDOnOff[2]);                        // P14 led 2 
    Wire.write ((int)LEDOnOff[3]);                        // P15 led 3  
    Wire.write ((int)LEDOnOff[4]);                        // P16 led 4   
    Wire.write ((int)LEDOnOff[5]);                        // P17 led 5                          
    Wire.write ((int)LEDOnOff[6]);                        // P18 led 6
    Wire.write ((int)LEDOnOff[7]);                        // P19 led 7
    Wire.write ((int)LEDOnOff[8]);                        // P20 led 8 
    Wire.write ((int)LEDOnOff[9]);                        // P21 led 9  
    Wire.write ((int)LEDOnOff[10]);                       // P22 led 10   
    Wire.write ((int)LEDOnOff[11]);                       // P23 led 11 
    Wire.write ((int)LEDOnOff[12]);                       // P24 led 12
    Wire.write ((int)LEDOnOff[13]);                       // P25 led 13
    Wire.write ((int)LEDOnOff[14]);                       // P26 led 14 
    Wire.write ((int)LEDOnOff[15]);                       // P27 led 15  
    Wire.write ((int)LEDOnOff[16]);                       // P28 led 16   
    Wire.write ((int)LEDOnOff[17]);                       // P29 led 17                          
    Wire.write ((int)LEDOnOff[18]);                       // P30 led 18
    Wire.write ((int)LEDOnOff[19]);                       // P31 led 19 
    Wire.endTransmission () ;                       // stop transmitting
}

void setup() {
for(byte i = 0; i < 13; i++) {  
  pinMode(pinOrder[i], INPUT_PULLUP); 
  //digitalWrite(pinOrder[i], HIGH);

//*****MAX6956********************************************
Wire.begin ();      // join i2c bus
delay(10);
max6956_init (0x44); // send the initilization handshake
//*********************************************************

 }
}


void loop() {
//lire l'état des entrées
for(byte i = 0; i < 13; i++) {   
 digitalInputState[i] = digitalRead(pinOrder[i]); 
 }
for(int i = 0; i < 13; i++) {   
   if(digitalInputState[i] != digitalInputState_prev[i]) {
     if(digitalInputState[i] == 0) {
       //usbMIDI.sendNoteOn(firstNote + i, velocity, channel);
       usbMIDI.sendControlChange(firstCC+ 20 + i, 127,channel);
       digitalInputState_prev[i] = digitalInputState[i];
     }
     if(digitalInputState[i] == 1) {
       //usbMIDI.sendNoteOff(firstNote + i, 0, channel);
       usbMIDI.sendControlChange(firstCC+ 20 + i, 0,channel);
       digitalInputState_prev[i] = digitalInputState[i];
     }     
   }  
 }
 for(byte i = 0; i < totalCtrl; i++) {
  analogInputValue[i] = map(analogRead(i), 0,1023,0,127);
  analogInputValue[i] =  constrain(analogInputValue[i], 0 ,127);
 } 
 for(byte i = 0; i < nombreDePotar; i++) {
   if(millis() - analogInputTime[i] > send_interval && analogInputValue[i] != analogInputValue_prev[i]) {
     analogInputTime[i] = millis();
     analogInputValue_prev[i] = analogInputValue[i];
     usbMIDI.sendControlChange(firstCC + i, analogInputValue[i],channel); 
  } 
 }

//reception du midi depuis l'ordinateur sur canal 16 
if(usbMIDI.read(16) > 0) {  // 
   if(usbMIDI.getType() == 3) { // 3 = CC
     byte data1 = usbMIDI.getData1();
     byte data2 = usbMIDI.getData2();
     if(data1 > 19) { // à réception d'une valeur de CC# au dela des 20 leds, toutes les LED à zéro !
       for (byte i = 0; i<19; i++) {
       LEDOnOff[i] = 0; //all LED off
       }
     }
     else {

       LEDOnOff[data1] = bitRead(data2,6);
     }
   }
 }

LED_to_MAX6956(0x44); 
}//end loop

nom du port USB :

// To give your project a unique name, this code must be
// placed into a .c file (its own tab).  It can not be in
// a .cpp file or your main sketch (the .ino file).

#include "usb_names.h"

// Edit these lines to create your own name.  The length must
// match the number of characters in your custom name.

#define MANUFACTURER_NAME   {'O','L','I','_','L','A','B'}
#define MANUFACTURER_NAME_LEN  7
#define MIDI_NAME   {'M','E','L','E','C','1'}
#define MIDI_NAME_LEN  6
#define SERIAL_NUM {'1'}
#define SERIAL_NUM_LEN 1
#define MIDI_PORT1_NAME {'V','i','d','e','o','_','c','o','n','t','r','o','l'}
#define MIDI_PORT1_NAME_LEN 13

// Do not change this part.  This exact format is required by USB.

struct usb_string_descriptor_struct usb_string_manufacturer_name = {
        2 + MANUFACTURER_NAME_LEN * 2,
        3,
        MANUFACTURER_NAME
};

struct usb_string_descriptor_struct usb_string_product_name = {
        2 + MIDI_NAME_LEN * 2,
        3,
        MIDI_NAME
};


struct usb_string_descriptor_struct usb_string_serial_number = {
        2 + SERIAL_NUM_LEN * 2,
        3,
        SERIAL_NUM
};


struct usb_string_descriptor_struct usb_string_midi_port1 = {
        2 + MIDI_PORT1_NAME_LEN * 2,
        3,
        MIDI_PORT1_NAME
};

et placer ce fichier nommé usb_names.h dans C:\Users[username]\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.59.0\cores\teensy