Hi,
This is my first project with a Teensy so please excuse my ignorance. I have a Teensy 3.6. I have made many MIDI controllers before using an Arduino Mega so I am familiar with the process, but I have never used a Teensy before.
For now I am trying to use a potentiometer on Analog input 0, a Membrane Potentiometer on Analog input 1` and another Potentiometer on Analog input 2. (nothing is wired to Analog input 3 at the moment, but it's in the code).
I also have 16 button switches in there, and they all work fine.
The issue I am having is that I can't get the full range out of the Membrane Potentiometer. I have one wire going to 3.3V, one to Ground and one to the Analog pin. There is a resistor between the Analog pin and Ground. I am doing this on a breadboard to figure it out.
For the resistor used with this Membrane Potentiometer, if I use a 220 Ohms resistor the sensor only goes up to 82 ( in midi control change value) at the max, but when I am not touching the sensor it is at 0 (which is good). If I use a 3.3K resistor it goes up to 123 at the max and I get a solid 0 when not touching it. If I use a 4.7 K ohms resistor the sensor goes up to 124 at max, but sort of fluctuates between 0 and 1 when I'm not touching it (which is bad), and the pots on A0 and A2, who should be at 0, go to 1 when I touch the membrane potentiometer, so it is affecting the neighboring sensors.
Ideally, I would like this membrane potentiometer to go to 127 at the max, be at 0 when I am not touching it, and not affect the neighboring sensors.
Is there a way to do this? Should I add some decoupling caps in there? Is there something I can add in the code? Is there a better way to wire this?
I am also doing this with an FSR (force sensitive resistor) and getting the same problem. Hopefully there is a way around this.
The code I am using is a combination of the example code from the "AnalogControlChange" example and the "Buttons" example under USBMidi.
I have a question about this code too. Why is the Analog read number divided by 8? Like in this line of code:
int n0 = analogRead(A0) / 8;
Thank you in advance for your help. Hopefully there is a solution.
This is my first project with a Teensy so please excuse my ignorance. I have a Teensy 3.6. I have made many MIDI controllers before using an Arduino Mega so I am familiar with the process, but I have never used a Teensy before.
For now I am trying to use a potentiometer on Analog input 0, a Membrane Potentiometer on Analog input 1` and another Potentiometer on Analog input 2. (nothing is wired to Analog input 3 at the moment, but it's in the code).
I also have 16 button switches in there, and they all work fine.
The issue I am having is that I can't get the full range out of the Membrane Potentiometer. I have one wire going to 3.3V, one to Ground and one to the Analog pin. There is a resistor between the Analog pin and Ground. I am doing this on a breadboard to figure it out.
For the resistor used with this Membrane Potentiometer, if I use a 220 Ohms resistor the sensor only goes up to 82 ( in midi control change value) at the max, but when I am not touching the sensor it is at 0 (which is good). If I use a 3.3K resistor it goes up to 123 at the max and I get a solid 0 when not touching it. If I use a 4.7 K ohms resistor the sensor goes up to 124 at max, but sort of fluctuates between 0 and 1 when I'm not touching it (which is bad), and the pots on A0 and A2, who should be at 0, go to 1 when I touch the membrane potentiometer, so it is affecting the neighboring sensors.
Ideally, I would like this membrane potentiometer to go to 127 at the max, be at 0 when I am not touching it, and not affect the neighboring sensors.
Is there a way to do this? Should I add some decoupling caps in there? Is there something I can add in the code? Is there a better way to wire this?
I am also doing this with an FSR (force sensitive resistor) and getting the same problem. Hopefully there is a way around this.
The code I am using is a combination of the example code from the "AnalogControlChange" example and the "Buttons" example under USBMidi.
I have a question about this code too. Why is the Analog read number divided by 8? Like in this line of code:
int n0 = analogRead(A0) / 8;
Thank you in advance for your help. Hopefully there is a solution.
Code:
/* USB MIDI AnalogControlChange Example
You must select MIDI from the "Tools > USB Type" menu
http://www.pjrc.com/teensy/td_midi.html
This example code is in the public domain.
*/
#include <Bounce.h>
// the MIDI channel number to send messages
const int channel = 1;
// the MIDI continuous controller for each analog input
const int controllerA0 = 1; // control change 1
const int controllerA1 = 2; //control change 2
const int controllerA2 = 3; //control change 3
const int controllerA3 = 4; // control change 4
const int controllerA14 = 14; // control change 15
const int controllerA15 = 15; // control change 15
const int controllerA16 = 16; // control change 16
const int controllerA17 = 17;
const int controllerA18 = 18;
const int controllerA19 = 19;
const int controllerA20 = 20;
const int controllerA21 = 21;
const int controllerA22 = 22;
const int controllerA23 = 23;
const int controllerA24 = 24;
const int controllerA25 = 25;
const int controllerA26 = 26;
const int controllerA27 = 27;
const int controllerA28 = 28;
const int controllerA29 = 29;
const int controllerA30 = 30;
// Create Bounce objects for each button. The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5); // 5 = 5 ms debounce time
Bounce button2 = Bounce(2, 5); // which is appropriate for good
Bounce button3 = Bounce(3, 5); // quality mechanical pushbuttons
Bounce button4 = Bounce(4, 5);
Bounce button5 = Bounce(5, 5); // if a button is too "sensitive"
Bounce button6 = Bounce(6, 5); // to rapid touch, you can
Bounce button7 = Bounce(7, 5); // increase this time.
Bounce button8 = Bounce(8, 5);
Bounce button9 = Bounce(9, 5);
Bounce button10 = Bounce(10, 5);
Bounce button11 = Bounce(11, 5);
Bounce button12 = Bounce(12, 5); // goes out of order because other pins double as analog inputs
Bounce button24 = Bounce(24, 5);
Bounce button25 = Bounce(25, 5);
Bounce button26 = Bounce(26, 5);
Bounce button27 = Bounce(27, 5);
void setup() {
pinMode(0, INPUT_PULLUP); // for button swithces
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(24, INPUT_PULLUP);
pinMode(25, INPUT_PULLUP);
pinMode(26, INPUT_PULLUP);
pinMode(27, INPUT_PULLUP);
}
// store previously sent values, to detect changes
int previousA0 = -1;
int previousA1 = -1;
int previousA2 = -1;
int previousA3 = -1;
elapsedMillis msec = 0;
void loop() {
{
button0.update(); // this button code works, goes from 0 to 127 when pressed
button1.update();
button2.update();
button3.update();
button4.update();
button5.update();
button6.update();
button7.update();
button8.update();
button9.update();
button10.update();
button11.update();
button12.update();
button24.update();
button25.update();
button26.update();
button27.update();
if (button0.fallingEdge()) { // this deals with reading the button swithces
usbMIDI.sendControlChange(controllerA14, 127, channel);
}
if (button0.risingEdge()) {
usbMIDI.sendControlChange(controllerA14, 0, channel);
}
if (button1.fallingEdge()) {
usbMIDI.sendControlChange(controllerA15, 127, channel);
}
if (button1.risingEdge()) {
usbMIDI.sendControlChange(controllerA15, 0, channel);
}
if (button2.fallingEdge()) {
usbMIDI.sendControlChange(controllerA16, 127, channel);
}
if (button2.risingEdge()) {
usbMIDI.sendControlChange(controllerA16, 0, channel);
}
if (button3.fallingEdge()) {
usbMIDI.sendControlChange(controllerA17, 127, channel);
}
if (button3.risingEdge()) {
usbMIDI.sendControlChange(controllerA17, 0, channel);
}
if (button4.fallingEdge()) {
usbMIDI.sendControlChange(controllerA18, 127, channel);
}
if (button4.risingEdge()) {
usbMIDI.sendControlChange(controllerA18, 0, channel);
}
if (button5.fallingEdge()) {
usbMIDI.sendControlChange(controllerA19, 127, channel);
}
if (button5.risingEdge()) {
usbMIDI.sendControlChange(controllerA19, 0, channel);
}
if (button6.fallingEdge()) {
usbMIDI.sendControlChange(controllerA20, 127, channel);
}
if (button6.risingEdge()) {
usbMIDI.sendControlChange(controllerA20, 0, channel);
}
if (button7.fallingEdge()) {
usbMIDI.sendControlChange(controllerA21, 127, channel);
}
if (button7.risingEdge()) {
usbMIDI.sendControlChange(controllerA21, 0, channel);
}
if (button8.fallingEdge()) {
usbMIDI.sendControlChange(controllerA22, 127, channel);
}
if (button8.risingEdge()) {
usbMIDI.sendControlChange(controllerA22, 0, channel);
}
if (button9.fallingEdge()) {
usbMIDI.sendControlChange(controllerA23, 127, channel);
}
if (button9.risingEdge()) {
usbMIDI.sendControlChange(controllerA23, 0, channel);
}
if (button10.fallingEdge()) {
usbMIDI.sendControlChange(controllerA24, 127, channel);
}
if (button10.risingEdge()) {
usbMIDI.sendControlChange(controllerA24, 0, channel);
}
if (button11.fallingEdge()) {
usbMIDI.sendControlChange(controllerA25, 127, channel);
}
if (button11.risingEdge()) {
usbMIDI.sendControlChange(controllerA25, 0, channel);
}
if (button12.fallingEdge()) {
usbMIDI.sendControlChange(controllerA26, 127, channel);
}
if (button12.risingEdge()) {
usbMIDI.sendControlChange(controllerA26, 0, channel);
}
if (button24.fallingEdge()) {
usbMIDI.sendControlChange(controllerA27, 127, channel);
}
if (button24.risingEdge()) {
usbMIDI.sendControlChange(controllerA27, 0, channel);
}
if (button25.fallingEdge()) {
usbMIDI.sendControlChange(controllerA28, 127, channel);
}
if (button25.risingEdge()) {
usbMIDI.sendControlChange(controllerA28, 0, channel);
}
if (button26.fallingEdge()) {
usbMIDI.sendControlChange(controllerA29, 127, channel);
}
if (button26.risingEdge()) {
usbMIDI.sendControlChange(controllerA29, 0, channel);
}
if (button27.fallingEdge()) {
usbMIDI.sendControlChange(controllerA30, 127, channel);
}
if (button27.risingEdge()) {
usbMIDI.sendControlChange(controllerA30, 0, channel);
}
}
// only check the analog inputs 50 times per second,
// to prevent a flood of MIDI messages
if (msec >= 10) { // i changed this value to 10 from 20 for faster updates
msec = 0;
int n0 = analogRead(A0) / 8;
int n1 = analogRead(A1) / 8;
int n2 = analogRead(A2) / 8;
int n3 = analogRead(A3) / 8;
// only transmit MIDI messages if analog input changed
if (n0 != previousA0) {
usbMIDI.sendControlChange(controllerA0, n0, channel);
previousA0 = n0;
}
if (n1 != previousA1) {
usbMIDI.sendControlChange(controllerA1, n1, channel);
previousA1 = n1;
}
if (n2 != previousA2) {
usbMIDI.sendControlChange(controllerA2, n2, channel);
previousA2 = n2;
}
if (n3 != previousA3) {
usbMIDI.sendControlChange(controllerA3, n3, channel);
previousA3 = n3;
}
}
// 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
}
}