RobertSinger
Member
Hi there
I have adapted a project from the following blog, and was hoping for some help
http://little-scale.blogspot.com/2012/10/a-very-simple-diy-usb-midi-controller.html
I want the teensy to act as a midi device, and to enable a potentiometer to send MIDI data to different MIDI control channels depending upon the state of a switch. I am just putting the code together and was wondering if anyone could help me get it right?
Circuit Architecture:
I have a 10K potentiometer placed between the +5v and Ground rails, with the actuator connected to pin: A0
I have a rocker switch enabling 5V to be sent to pin: A4 when it is in one position, and 0V to A4 when in the other position
Aim
*I would like the pot to send data to MIDI Control channel 1 when the switch is in state 0 (0V to pin: A4),
*and for the pot to send data to Midi Control channel 2 when the switch is in its state 1 (5V to A4).
Code so far:
int val;
int swPin = 4; // This is the pin which recieves the 5V from the switch
int conNum; // this is the MIDI controller number that will be altered
//depending upon the state of the switch
void setup() {
pinMode (swPin, INPUT);
// define pin: A4 as an input
}
void loop() {
val = analogRead(swPin); //read the switch state
if (val = HIGH)
{conNum = 1; //If the switch is on, conNum is 2
}
else
{conNum = 2; //If the switch is off, conNum is 1
}
//The following is the standard MIDI function from...
//teensy, with the controll change lane defined...
//as the number that has been chosen from above
usbMIDI.sendControlChange(conNum, analogRead(0) / 8, 1);
//delay for stability
delay(5);
//Ignore incoming midi from computer as this is a...
//send-data controller only
while (usbMIDI.read()) {
}
}
I have adapted a project from the following blog, and was hoping for some help
http://little-scale.blogspot.com/2012/10/a-very-simple-diy-usb-midi-controller.html
I want the teensy to act as a midi device, and to enable a potentiometer to send MIDI data to different MIDI control channels depending upon the state of a switch. I am just putting the code together and was wondering if anyone could help me get it right?
Circuit Architecture:
I have a 10K potentiometer placed between the +5v and Ground rails, with the actuator connected to pin: A0
I have a rocker switch enabling 5V to be sent to pin: A4 when it is in one position, and 0V to A4 when in the other position
Aim
*I would like the pot to send data to MIDI Control channel 1 when the switch is in state 0 (0V to pin: A4),
*and for the pot to send data to Midi Control channel 2 when the switch is in its state 1 (5V to A4).
Code so far:
int val;
int swPin = 4; // This is the pin which recieves the 5V from the switch
int conNum; // this is the MIDI controller number that will be altered
//depending upon the state of the switch
void setup() {
pinMode (swPin, INPUT);
// define pin: A4 as an input
}
void loop() {
val = analogRead(swPin); //read the switch state
if (val = HIGH)
{conNum = 1; //If the switch is on, conNum is 2
}
else
{conNum = 2; //If the switch is off, conNum is 1
}
//The following is the standard MIDI function from...
//teensy, with the controll change lane defined...
//as the number that has been chosen from above
usbMIDI.sendControlChange(conNum, analogRead(0) / 8, 1);
//delay for stability
delay(5);
//Ignore incoming midi from computer as this is a...
//send-data controller only
while (usbMIDI.read()) {
}
}