Hey guys im having a problem with my code, im building a midi controller ,i have 20 buttons and 4 pots, i recently coded the pots but there is a constant stream of midi data which is confusing ableton live.
It is basically changing my midi mapping . is there any way i can only send data to ableton if i physically turn the pot?
Any information or alterations to the sketch (which is included) would be greatly appreciated
many thanks
Gary
void loop() {
// put your main code here, to run repeatedly:
sensor0Value = analogRead(sensor0Pin);
...
controlChange(0xB0, sensor0Value, 0x07); // VOLUME
...
}
You basically want to check for a change. For example:
if (sensor0Value != oldSensor0Value)
controlChange(0xB0, sensor0Value, 0x07); // VOLUME
oldSensor0Value = sensor0Value; // remember for next time through
Ditto for the others. Of course, you need to set up the oldSensor0Value variable.
is there any way i can only send data to ableton if i physically turn the pot?
The potentiometer is connected all the time. You read it all the time. There is no way of determining whether the potentiometer is being moved. You can, though, keep track of the last reading that resulted in a message send, and only send another message if the reading changed significantly. (You get to define what significantly means; don't make it too small, though.)
int switchAState, switchBState, switchCState, switchDState = LOW;
Only one of the 4 variables in this line is initialed to LOW. The rest get default values (which just happen to be the same value as LOW).
Some arrays would be real useful...
In readSwitch(), you pass in the previous state, read the new state, and do something if the current state is not the same as the previous state.
You need to do the same with controlChange. Don't read the values in loop(). Read them in controlChange(), instead. Compare the new reading with the old reading, and do something if the absolute value (abs()) of the difference is large enough.
sweet man thats sorted it, but the pots are all over the place in ableton i cant seem to get them to start at 0 and go up the full range of the pot, any idea why
sorry to be a pain in the neck