/*
Arduino*Leonardo*midi*controller.
Based*on*the*ARCORE*work*from*Rkistner*to*send*and *get*midi*trough*the*board*usb*conection.
ARCORE*is*working*with*Arduino*Leonardo,*Arduino*M icro*y*Bare*Conductive*Touch*Board*all*of*them*bas ed*on*atmega32u4.
*/
//CC*outputs*from*the*host*to*drive*leds*can*be*on*a ny*channel*but*CC*must*be*10*and*13.
//*Leds
*
int VUmetA=13;
// Vu metter a
*
int VUmetB=10;
// Vu metter b
*
float logcurve=10;
// Adjust the log curve can work with fractions.
*
float x;
// Used to float math.
*
//*Encoder
*
int EncPinA = 0;
*
int EncPinB = 1;
*
int PinALast =
LOW;
// last pin a value
*
int a =
LOW;
*
int b =
LOW;
*
//*variables*y*arreglos*para*la*lectura*digital
*
int Din[8] = {2, 3, 5, 7, 8, 9, 11, 12};
// Digital in array
*
int offsetD = 64;
// Note offset
*
int LDin[8];
// Last digital values array
*
int DtempRead;
// Temp digital read
*
int Chan = 4;
// General MIDI channel
*
*
// variables y arreglos para la lectura analoga
*
*
int Ain[8] = {A0, A1, A2, A3, A4, A5, A6, A7};
// Analog array
*
int offsetA = 17;
// CC Offset
*
int LAin[8];
// Last analog values array
*
int AtempRead;
// Temp analog read
*
int thresh = 4;
// To reduce the noise from pots
//*----------------arcore*setup------------------
void CC(
byte channel,
byte ccnumb,
byte value) {
****MIDIEvent*CC*=*{0x0B,*0xB0*|*channel,*ccnumb,* value};
****MIDIUSB.
write(CC);
*}**
*
*
void NOn(
byte channel,
byte pitch,
byte velocity) {
****MIDIEvent*NOn*=*{0x09,*0x90*|*channel,*pitch,* velocity};
****MIDIUSB.
write(NOn);
}
void NOff(
byte channel,
byte pitch,
byte velocity) {
****MIDIEvent*NOff*=*{0x08,*0x80*|*channel,*pitch, *velocity};
****MIDIUSB.
write(NOff);
}
*
*
//--------------------------------------------------------------------------------------------
void setup() {
**
****
// setup encoder
***
pinMode (EncPinA,
INPUT);
***
pinMode (EncPinB,
INPUT);
***
digitalWrite (EncPinA,
HIGH);
***
digitalWrite (EncPinB,
HIGH);
***
****
// setup digital
***
for (
int i=0; i<8; i++)
****{
******
pinMode (Din[i],
INPUT);
******
digitalWrite (Din[i],
HIGH);
****}
// setup digital end
****
}
//----------------------------------------------------------------------------------------------
*
void loop() {
//----------------------------------------------------------------------------------------------
**
//Read CC messages and send to pins 10 and 13 using pwm.
*****
******
if(MIDIUSB.
available() > 0) {
**********MIDIEvent*e;
**********e*=*MIDIUSB.
read();
**********
if(e.type == 0x0B && e.m2 == 10) {
// detect CC 10 from host on any channel
***************x*=*e.m3;
***************x*=*(pow((x/127),*logcurve)*x);***
// convert linear values to logaritmics.
***************
analogWrite(VUmetB, (x*2));
**********}
*****************
**********
if(e.type == 0x0B && e.m2 == 13) {
// detect CC 13 from host on any channel
***************x*=*e.m3;
***************x*=*(pow((x/127),*logcurve)*x);***
// convert linear values to logaritmics.
***************
analogWrite(VUmetA, (x*2));
**********}
}
**
//-------------------------------------------------------------------------------------------
**
**
// Encoder
*
******a*=*
digitalRead(EncPinA);
// Read a & b
******b*=*
digitalRead(EncPinB);
***
**********
if (a != PinALast) {
// test if "a" has changed from last state
**********
if(a == b) {
// compare "a" & "b" if it's equal:
***************CC(Chan,*16,*127);**
// send 127 to CC 16 of general channel defined before.
***********}****
***********
else {
// if it's not equal:
***************CC(Chan,*16,*1);****
// send 1 to CC 16 of general channel defined before.
***********}
*******PinALast*=*a;***************
// define "a" last value
}
**
//-------------------------------------------------------------------------------------------
**
**
// Digital in. All internal pullup resistors has been called so a LOW state equals a Note On message
**
***
for (
int i=0; i<8; i++)
****{
******DtempRead*=*
digitalRead(Din[i]);
******
if (DtempRead != LDin[i]) {
// If temp has changed from last state
********
if (DtempRead ==
LOW) {
// and it's (LOW):
**********NOn(Chan,*i+offsetD,*100);****
// send Note On
********}
********
else {
**********NOff(Chan,*i+offsetD,*0);*****
// if it's high send note off
********}*
********LDin[i]*=*DtempRead;************
// Last value record on the array
******}
****
****}
**
//--------------------------------------------------------------------------------------------
**
***
// Analog in
***
***
for (
int i=0; i<8; i++)
****{
******AtempRead*=*
analogRead(Ain[i]);
// Read Analog Value
******
******
if (AtempRead > LAin[i] + thresh || AtempRead < LAin[i] - thresh) {
// if it is greater or lower from a range setted with the treshold value
************************************************** *************************
**********CC(Chan,*i+offsetA,*AtempRead/8);********
// send CC
**********LAin[i]*=*AtempRead;*********************
// Last value record on the array
*********
********}*
******}***
****
*
//----------------------------------------------------------------------------------------------
**
**}
//end void loop
Bookmarks