Hello,
I am converting a volume pedal to usb/midi controllers messages with the Teensy 2 and latest Arduino/Teensy software
The pedal is a simple 10k potentiometer connected with a jack plug to teensy
One pin goes to +5V VCC
One pin goes to 0V GND
One pin goes to an anlogo input (pullup)
Everything is working perfect, but if I unplug/replug the pedal while midi softawre is running, the teensy program does no work anymore
I need to close and start again the midi software to be able to work again
Any idea on this?
My code is :
byte analog1=7;
long t2=0;
long oldval=0;
long newval=0;
long oldvalmidi=0;
long newvalmidi=0;
byte first=1;
...........................................
void loop() {
if (first==1){
first=0;
newval= analogRead(analog1);
}
else
{
newval +=analogRead(analog1);
newval=(newval/2);
}
if (millis()-t2>30) {
t2=millis();
newvalmidi=(((newval+1)*128)/1024);
if (newvalmidi>127) newvalmidi=127;
if (newvalmidi<0) newvalmidi=0;
if (newvalmidi!=oldvalmidi){
oldvalmidi=newvalmidi;
usbMIDI.sendControlChange(11,newvalmidi,1);
}
}
I am converting a volume pedal to usb/midi controllers messages with the Teensy 2 and latest Arduino/Teensy software
The pedal is a simple 10k potentiometer connected with a jack plug to teensy
One pin goes to +5V VCC
One pin goes to 0V GND
One pin goes to an anlogo input (pullup)
Everything is working perfect, but if I unplug/replug the pedal while midi softawre is running, the teensy program does no work anymore
I need to close and start again the midi software to be able to work again
Any idea on this?
My code is :
byte analog1=7;
long t2=0;
long oldval=0;
long newval=0;
long oldvalmidi=0;
long newvalmidi=0;
byte first=1;
...........................................
void loop() {
if (first==1){
first=0;
newval= analogRead(analog1);
}
else
{
newval +=analogRead(analog1);
newval=(newval/2);
}
if (millis()-t2>30) {
t2=millis();
newvalmidi=(((newval+1)*128)/1024);
if (newvalmidi>127) newvalmidi=127;
if (newvalmidi<0) newvalmidi=0;
if (newvalmidi!=oldvalmidi){
oldvalmidi=newvalmidi;
usbMIDI.sendControlChange(11,newvalmidi,1);
}
}