Teensy 2.0 Auto Mode

Status
Not open for further replies.
Hi all........I'm making another MIDI controller using a Teensy 2.0 & 2 x 16 channel multiplexes and I keep getting this Automatic mode disabled message.
I've used variations of this code before without problems. I've tried it on 3 different computers with same result. I loaded the Demo Reel 100 Fast LED code which works fine so I'm at a brick wall. Any ideas?

// MIDI channel
#define mchannel 10
#include "FastLED.h"
#define DATA_PIN 10 Auto mode pic.png#include <MIDI.h>
//#define CLOCK_PIN 2
//byte hue = 0;
#define NUM_LEDS 25
#define BRIGHTNESS 50
// Define the array of leds
CRGB leds[NUM_LEDS];

// Baud rate (31250 is MIDI baud rate)
#define data_rate 31250
//Mux control pins

int s0 = 1;
int s1 = 2;
int s2 = 3;
int s3 = 4;


int SendPin = 0;

int controlPin[] = {s0,s1,s2,s3};

//int LEDpin = 11;
//Mux in "SIG" pin
int SIG_pin1 = A2;
int SIG_pin2 = A3;


// The number of milliseconds between successive sends of the CC data.
#define ccdelay 10
#define cclowestChan 12
#define chanPerMUX 16



struct CCPotStruct {
int CCnum;//channel number
int CCval;//current value
int CCprev;//previous value
int CCtype;
//set to 0 if channel is not used.
//set to 1 if pot
//set to 2 if switch

};
CCPotStruct CCPot1[chanPerMUX];
CCPotStruct CCPot2[chanPerMUX];

long lastScan = 0;

// Continuous controllers

void setup()

{
FastLED.addLeds<WS2812B, DATA_PIN>(leds, NUM_LEDS);

pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
//pinMode(LEDpin, OUTPUT);

digitalWrite(s0, LOW);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);





// Set up the serial port for MIDI use
// Serial.begin(data_rate);
//Serial.begin (9600);
// Serial.println("test");

// pinMode(13, OUTPUT);
// Set up the physical serial port
pinMode(0, INPUT_PULLUP);


//initialise dead channel flags to 0
for (int x = 0; x < chanPerMUX; x++)
{
CCPot1[x].CCtype = 1;
CCPot2[x].CCtype = 1;


// initialise this and last values to -1 so they all light up
CCPot1[x].CCprev = -1;
CCPot2[x].CCprev = -1;


CCPot1[x].CCval = -2;
CCPot2[x].CCval = -2;



}

//THESE ARE YOUR SWITCH CHANNELS!!!
//MUX 1 = CH 0 to CH 15
CCPot1[0].CCtype = 0;
// CCPot1[1].CCtype = 0;
// CCPot1[15].CCtype = 0;
//MUX 2 = CH16 to CH31
CCPot2[0].CCtype = 0;//2; //Ch16 - 16 = 0;
// CCPot2[12].CCtype = 2;//2; //Ch27 - 16 = 11
// CCPot2[8].CCtype = 2;//2; //Ch31 - 16 = 15
// CCPot2[6].CCtype = 2; //RH SW1
// CCPot2[7].CCtype = 2; //RH SW2




}

void loop()
{
long timeNOW = millis();
bool SendVal = !digitalRead(SendPin);
//int raw = 0;
// This is the other logic for the pads, to send note on and note off (note on, 0 velocity) messages.
// Continuous controllers

if (timeNOW >= lastScan + ccdelay)
{

for (int i = 0; i < chanPerMUX; i++)
{

//first MUX - get data from Analog input.

CCPot1.CCnum = i + cclowestChan;// starts populating at lowest channel number
CCPot1.CCprev = CCPot1.CCval;
if (CCPot1.CCtype == 0)//cancel data on dead channels
{
CCPot1.CCval = 0;
}
else if (CCPot1.CCtype == 1)//pot type mapping
{
CCPot1.CCval = map(readMux(i, SIG_pin1, s0), 0, 1022, 0, 127);
CCPot1.CCval = constrain(CCPot1.CCval, 0, 127);
//smoothing
CCPot1.CCval = (CCPot1.CCprev * 2 + CCPot1.CCval) / 3;
}
else if (CCPot1.CCtype == 2)//switch type mapping
{
CCPot1.CCval = readMux(i, SIG_pin1, s0);
if (CCPot1.CCval > 500)
{
CCPot1.CCval = 126;
}
else
{
CCPot1.CCval = 0;
}

}



//second MUX - get data from Analog input.
CCPot2.CCnum = i + cclowestChan + chanPerMUX; //starts populating at lowest channel number PLUS numbr of used mux channels (16)
CCPot2.CCprev = CCPot2.CCval;

if (CCPot2.CCtype == 0)//cancel data on dead channels
{
CCPot2.CCval = 0;
}
else if (CCPot2.CCtype == 1)//pot type mapping
{
CCPot2.CCval = map(readMux(i, SIG_pin2, s0), 0, 1022, 0, 127);
CCPot2.CCval = constrain(CCPot2.CCval, 0, 127);
//smoothing
CCPot2.CCval = (CCPot2.CCprev * 2 + CCPot2.CCval) / 3;
}
else if (CCPot2.CCtype == 2)//switch type mapping
{
CCPot2.CCval = readMux(i, SIG_pin2, s0);
if (CCPot2.CCval > 850)
{
CCPot2.CCval = 126;
}
else
{
CCPot2.CCval = 0;
}
}
/*else if (CCPot2.CCtype == 3)//pot type mapping
{
raw = readMux(i, SIG_pin2, s0);
if (i == 3)
{
Serial.println(raw);
}
CCPot2.CCval = map(raw, 0, 1022, 0, 127);
//smoothing
CCPot2.CCval = (CCPot2.CCprev * 2 + CCPot2.CCval) / 3;
}
*/


if (abs(CCPot1.CCval - CCPot1.CCprev) >= 1 || SendVal)
{
// usbMIDI.sendControlChange (CCPot1.CCnum , CCPot1.CCval, 4);
// Serial.println(CCPot1.CCval);
leds = CHSV(map (CCPot1.CCval, 0, 127, 150, 0), 255, 255);
lastScan = timeNOW;
}

if (abs(CCPot2.CCval - CCPot2.CCprev) >= 1 || SendVal)
{
usbMIDI.sendControlChange (CCPot2.CCnum , CCPot2.CCval, 4);
// Serial.println(CCPot2.CCval);
leds[i + chanPerMUX * (2 - 1)] = CHSV(map (CCPot2.CCval, 0, 127, 150, 0), 255, 255);
lastScan = timeNOW;
}


SendVal = false;
}
FastLED.show();

}



}



////PROCEDURE TO READ MUX CHANNELS////



int readMux(int channel, int Apin, int Cpin)
//channel = the MUX channel currently being read
//Apin = the Analogue pin the MUX output is attached to
//Cpin = the first control pin. The control pins MUST be sequential (e,g, pins 0,1,2,3 NOT 0,3,5,8)
{
int muxChannel[16][4] =
{
{0, 0, 0, 0}, //channel 0
{1, 0, 0, 0}, //channel 1
{0, 1, 0, 0}, //channel 2
{1, 1, 0, 0}, //channel 3
{0, 0, 1, 0}, //channel 4
{1, 0, 1, 0}, //channel 5
{0, 1, 1, 0}, //channel 6
{1, 1, 1, 0}, //channel 7
{0, 0, 0, 1}, //channel 8
{1, 0, 0, 1}, //channel 9
{0, 1, 0, 1}, //channel 10
{1, 1, 0, 1}, //channel 11
{0, 0, 1, 1}, //channel 12
{1, 0, 1, 1}, //channel 13
{0, 1, 1, 1}, //channel 14
{1, 1, 1, 1}, //channel 15

};
for (int i = 0; i < 4; i ++)
{
digitalWrite(controlPin, muxChannel[channel]);
}

//read the value at the signal pin
//delay(1);
int val = analogRead(Apin);

//return the value
return val;
}
 
Status
Not open for further replies.
Back
Top