Hello, i wanted to control a motorized Fader with an input of my midi software, so that the value in my software is represented on my fader, i can set my fader to a position i like but the Serial Input of my Arduino does not resolve the values of my MIDI software accordingly.
I also use the Hairless MIDI bridge to recieve and send the MIDI signals over Serial.
The sending works fine, so this is not a problem.
This is my Schematic:
And this is my Code:
int statusByte;
int dataByte1;
int dataByte2;
int motorUp = 2;
int motorDown = 3;
int Fader = A0;
void setFader(int value){
int value1 = map(value, 0,127, 0, 1023);
int current = analogRead(Fader);
if(current != value1){
if(current < value){
while(current != value1){
current = analogRead(Fader);
digitalWrite(motorUp, HIGH);
//Serial.println(analogRead(A0));
}
digitalWrite(motorUp, LOW);
}else{
while(current != value1){
current = analogRead(Fader);
digitalWrite(motorDown, HIGH);
//Serial.println(analogRead(A0));
}
digitalWrite(motorDown, LOW);
}
}
}
void setup() {
// put your setup code here, to run once:
pinMode(motorUp, OUTPUT);
pinMode(motorDown, OUTPUT);
Serial.begin(115200);
Serial.write(176);
Serial.write(22);
Serial.write(0);
}
void loop() {
// put your main code here, to run repeatedly:
delay(1);
do{
if(Serial.available()){
statusByte = Serial.read();
dataByte1 = (Serial.read(), DEC);
dataByte2 = (Serial.read(), DEC);
if(statusByte >= 176 ){
setFader(dataByte2);
}
}
}
while(Serial.available() > 2);
}
The problem is that my setFader(dataByte2) is not working, the values i get from dataByte2 must not be normal, because my fader is always moving between two points, like fidgeting.
Can someone help me?
