1 knob for live

I’ve been trying to set one knob on the Arduino Uno to control a parameter on Ableton Live.
I’ve been revising tutorials and stuff on this forum and others, but I’m still stuck.

I have a potentiometer on pin 0, I’m using the MIDI Library, the serial messages go through Hairless and I have MIDI Monitor to see whats happening. The MIDI messages go through IAC Bus 1.

What I have accomplished so far is having the board send MIDI Messages. What messages it is sending is confusing since MIDI Monitor tells me different things, from note on/off to pitchbend and other invalid commands whenever I twist the knob.

This is my code:

#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

MIDI_CREATE_DEFAULT_INSTANCE();

int sensorPin = 0;
int ledPin = 9;
int sensorValue = 0;
int sensorValuePrev = 127;


void setup()
{
   Serial.begin(9600);       // Default speed of MIDI serial port
   
   pinMode(ledPin, OUTPUT);
   
   MIDI.begin(1);
}

void loop() {
  
  
  fade();
  
  sensorValue = analogRead(0)/4;
  
  if((sensorValue - sensorValuePrev) >  || (sensorValue - sensorValuePrev) < -1) {
    if(sensorValue != sensorValuePrev) {
      MIDI.sendControlChange(1, sensorValue, 1);
      sensorValuePrev = sensorValue;
    }
  }


}
   

void fade() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin)/4;    
  // turn the ledPin sensorValue
  analogWrite(ledPin, sensorValue);  
 
}

There is an LED. It’s brightness changes depending according to the knob.

The goal for this small project is to build a controller with a bunch of knobs. I would appreciate if the comments and advises would go in that direction in the sense that i would prefer if I don’t have to use a Serial to MIDI converter.

This is the first time I’m posting something here. Let me know if i’m not being specific enough or if i’m missing something.

What are you using MIDI for?

If you're sending control change messages, the value has to be within the range of 0 to 127. analogRead will return values in the range of 0 to 1023. You're dividing by four so this will give you values in the range of 0 to 255

Try changing sensorValue = analogRead(0)/4; to sensorValue = analogRead(0)/8;

 if((sensorValue - sensorValuePrev) >  || (sensorValue - sensorValuePrev) < -1) {

if((sensorValue - sensorValuePrev) is greater than what?
Looks like your trying to compare it with nothing.

goodinventor:
What are you using MIDI for?

To control any parameter in Ableton Live. The goal is to have a 16 knob MIDI Controller.

Henry_Best:

 if((sensorValue - sensorValuePrev) >  || (sensorValue - sensorValuePrev) < -1) {

if((sensorValue - sensorValuePrev) is greater than what?
Looks like your trying to compare it with nothing.

There should be a 1 there, my bad. Some Potentiometers are really sensitive or too shitty so messages shouldn’t be sent unless the difference between the current and last read is grater than 1.

KenF:
If you’re sending control change messages, the value has to be within the range of 0 to 127. analogRead will return values in the range of 0 to 1023. You’re dividing by four so this will give you values in the range of 0 to 255

Try changing
sensorValue = analogRead(0)/4;
to
sensorValue = analogRead(0)/8;

I just changed that and nothing happened. I’ll post some pictures of the reading in Hairless and the readings in MIDI Monitor.

http://imgur.com/SOIrb68,LZmkOa3#0

Some times the board doesn't stop sending messages and the readings go on and on.

When just go to the serial monitor weird symbols appear.

Did you sort out the issue that Henry_Best pointed out in answer #3?

Edit. OK Scrap that I see you have.