its being used as a midi effects pot
it seems to be jumping channels and from note to control chainge any help would be great
/* The format of the message to send via serial */
typedef struct {
uint8_t command;
uint8_t channel;
uint8_t data2;
uint8_t data3;
}
t_midiMsg;
int potPin[] = {
0}; //choose the input pin for a potentometer
int potVal[] = {
0}; //variable for reading potentiometer value
int mappedPotVal[] = {
0}; //variable for holding remapped pot value
int prevPotVal[] = {
0}; //variable for storing our prev pot value
int THRESHOLD = 2;
int MAX_POT = sizeof(potPin);
int channel = 1;
void setup() {
// set up serial port
Serial.begin(31250);
}
void loop() {
for (int mypots = 0; mypots < MAX_POT /2; mypots++){
potVal[mypots] = analogRead(potPin[mypots]); //read input from potentiometer
mappedPotVal[mypots] = map(potVal[mypots], 0, 1023, 0, 127); //map value to 0-127
if(abs(mappedPotVal[mypots] - prevPotVal[mypots]) >= THRESHOLD){
sendmidi(0xB0, mypots, mappedPotVal[mypots]); //Control Change (Ch 1), Controller 7 - default control for volume.
prevPotVal[mypots] = mappedPotVal[mypots];
}
else{
}
// end pot code
}
}
void sendmidi(int command,int data2, int data3){
t_midiMsg msg;
int ind;
/* Send the notes */
msg.command = command; //noteon
msg.channel = channel;
msg.data2 = data2; //note
msg.data3 = data3; /* Velocity */
Serial.write((uint8_t *)&msg, sizeof(msg));
}
sorry for the late responce i found out from trial and error that the midi message needed to be send using 4 parts
and ended up using Serial.write()\s insted of
/* The format of the message to send via serial */
typedef struct {
uint8_t command;
uint8_t channel;
uint8_t data2;
uint8_t data3;
}
t_midiMsg;
int potPin[] = {
0}; //choose the input pin for a potentometer
int potVal[] = {
0}; //variable for reading potentiometer value
int mappedPotVal[] = {
0}; //variable for holding remapped pot value
int prevPotVal[] = {
0}; //variable for storing our prev pot value
int THRESHOLD = 2;
int MAX_POT = sizeof(potPin)/2;
int channel = 1;
void setup() {
// set up serial port
Serial.begin(115200);
}
void loop() {
for (int mypots = 0; mypots < MAX_POT; mypots++){
potVal[mypots] = analogRead(potPin[mypots]); //read input from potentiometer
mappedPotVal[mypots] = map(potVal[mypots], 0, 1023, 0, 127); //map value to 0-127
if(abs(mappedPotVal[mypots] - prevPotVal[mypots]) >= THRESHOLD){
//controlChange(channel, 0xB0, mappedPotVal[mypots]);
controlChange(0xB0,1,0x01,mappedPotVal[mypots]);
//Serial.println("---------------------");
//Serial.println(mypots);
//Serial.println(mappedPotVal[mypots]);
//Serial.println("---------------------");
//delay(100);
prevPotVal[mypots] = mappedPotVal[mypots];
}
// end pot code
}
}
void controlChange(byte statusbit,byte channel, byte control, byte value)
{
Serial.write(statusbit);
Serial.write(control);
Serial.write(channel);
Serial.write(value);
}
int potPin[] = {
0}; //choose the input pin for a potentometer
int potVal[] = {
0}; //variable for reading potentiometer value
int mappedPotVal[] = {
0}; //variable for holding remapped pot value
int prevPotVal[] = {
0}; //variable for storing our prev pot value
One element arrays have absolutely no advantage over scalar variables.