woodslanding
Member
Okay, I'm having a strange problem, presumably in my code, as it's happened with different teensies connected to different pots.
When I move the pot all the way down, I get a non-zero value. If I then move it slightly in the opposite direction, I get a proper zero. Then if I move to max, I get a value of around 109. If I move slightly back from max, I get a 127.
Here's my code:
Thanks in advance!!!
When I move the pot all the way down, I get a non-zero value. If I then move it slightly in the opposite direction, I get a proper zero. Then if I move to max, I get a value of around 109. If I move slightly back from max, I get a 127.
Here's my code:
Code:
/* Pedal Interface. 10 footswitches and 4 control pedals
*/
#include <Bounce.h>
const int COUNT_D = 10;
const int COUNT_A = 3;
const int PINS_D[] = {0,1,2,3,4,5,6,7,8,9};
const int CCS_D[] = {65,66,67,68,69,70,71,72,73,74};
const int sus = 0;
const int vol = 1;
const int expr = 2;
const int aux=3;
const int PINS_A[] = {sus,vol,expr,aux,};
const int CCS_A[] = { 64,11,12,13};
int VALUES_A[COUNT_A];
int midiChan = 3;
// range of ctls is 0-1023, divide by 8 for midi value
const int SENSITIVITY = 64;
const int SCALE_A = 8;
//ccVal = map(sensorValue, 0, 1023, 0, 127); //more precise, I suppose
int sens = 4;
//button debounce time
// Debounce
long debounceDelay = 20;
Bounce buttons[] = {
Bounce(PINS_D[0], debounceDelay),
Bounce(PINS_D[1], debounceDelay),
Bounce(PINS_D[2], debounceDelay),
Bounce(PINS_D[3], debounceDelay),
Bounce(PINS_D[4], debounceDelay),
Bounce(PINS_D[5], debounceDelay),
Bounce(PINS_D[6], debounceDelay),
Bounce(PINS_D[7], debounceDelay),
Bounce(PINS_D[8], debounceDelay),
Bounce(PINS_D[9], debounceDelay),
Bounce(PINS_D[10], debounceDelay),
Bounce(PINS_D[11], debounceDelay),
Bounce(PINS_D[12], debounceDelay)
};
void setup() {
for (int ctl = 0; ctl < COUNT_A; ctl++)
{
VALUES_A[ctl] = 0;
}
for (int btn = 0; btn < COUNT_D; btn++) //int btn = 0;
{
pinMode (btn, INPUT_PULLUP);
}
}
void loop() {
//BUTTONS
for (int btn = 0; btn < COUNT_D; btn++) //int btn = 0;
{
buttons[btn].update();
if (buttons[btn].risingEdge())
{
usbMIDI.sendControlChange(CCS_D[btn], 0, midiChan);
}
else if (buttons[btn].fallingEdge()) {
usbMIDI.sendControlChange(CCS_D[btn], 127, midiChan);
}
}
//POTS
for (int ctl = 0; ctl < COUNT_A; ctl++) //int ctl = 0;
{
int value = analogRead(PINS_A[ctl]);
if (0 < ctl < COUNT_A) {sens = SENSITIVITY;} else {sens = SENSITIVITY;} //default sensitivity
if (abs(VALUES_A[ctl] - value) > sens)
{
usbMIDI.sendControlChange(CCS_A[ctl], VALUES_A[ctl] / SCALE_A, midiChan); //CC,val,CH
VALUES_A[ctl] = value;
delay(50);
}
}
//pin test
/*
int pin = bCtl;
int value = analogRead(PINS_A[pin]);
if (abs(VALUES_A[pin] - value) > sens) {
usbMIDI.sendControlChange(CCS_A[pin],VALUES_A[pin] / SCALE_A, midiChan);
VALUES_A[bCtl] = value;
delay(50);
}*/
// MIDI Controllers should discard incoming MIDI messages.
// http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash
while (usbMIDI.read()) {
// ignore incoming messages
}
}
Thanks in advance!!!