Hi,
I am using the arduino to take inputs from a Spectra industries linear softpot (basically like a potentiometer with a floating wiper when not actuated by pressure) as well as a Yamaha BC3 breath controller (a breath-pressure sensor for musical instrument control). The data is then sent out via midi to a synthsizer.
The softpot sends out 'pitchbend data', the breath-controller sends out 'control change data' - you can just think of them as data types 'A' and 'B'
The softpot works fine in this setup, always sending out Pitchbend. The breath-controller works fine when I don't use the softpot (I comment out the softpot part of the code), but when used together it transmits both Control-change and Pitchbend. I think the code is sound (although I am completely new to any sort of programming), so I think that the problem is on the hardware side.
What have I done wrong?
Here's the circuit:
And here's the code:
#include <MIDI.h>
// These constants won't change:
const int sensorPin = A0; // pin that the sensor is attached to
const int pitchpin = A1;
// variables:
int sensorValue = 0; // the sensor value
int sensorMin = 1023; // minimum sensor value
int sensorMax = 0; // maximum sensor value
int midval = 0;
int prevmidval = 0;
int THRESHOLD = 2;
int pitchbendval = 0;
int prevpitch = 0;
int pitchthresh = 1;
void setup() {
// turn on LED to signal the start of the calibration period:
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
MIDI.begin(1);
{
Serial.begin(31250
);
}
// // calibrate during the first five seconds
while (millis() < 5000) {
sensorValue = analogRead(sensorPin);
// // record the maximum sensor value
if (sensorValue > sensorMax) {
sensorMax = sensorValue;
}
//
// // record the minimum sensor value
if (sensorValue < sensorMin) {
sensorMin = sensorValue;
}
}
// // signal the end of the calibration period
// digitalWrite(13, LOW);
}
void loop() {
// // read the sensor:
sensorValue = analogRead(sensorPin);
// // apply the calibration to the sensor reading
sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 127);
//
// // in case the sensor value is outside the range seen during calibration
sensorValue = constrain(sensorValue, 0, 127);
//
midval = -sensorValue+127 ;
if(abs(midval - prevmidval) >= THRESHOLD){
MIDI.sendControlChange(02, midval, 1);
prevmidval = midval;
}
pitchbendval = analogRead(pitchpin) ;
pitchbendval = map(pitchbendval, 0, 1023, 0, 16383);
if (pitchbendval==0) if (prevpitch > 2) {
pitchbendval = 8192;
}
if(abs(pitchbendval - prevpitch) >= pitchthresh){
MIDI.sendPitchBend( pitchbendval , 1);
prevpitch = pitchbendval;
}
// delay (1000) ;
// Serial.println(midval, DEC);
}