Motorfader control with Arduino

Hi there,

first sorry for my bad english. Hope you can still understand what i mean.

My problem is that the motor faders influence each other or as soon as midi data is retrieved, at least one motorfader drives to the endpoint and stops. I tried it with a State machine.

here is my code:

#include <MUX74HC4067.h>
#include "Adafruit_MPR121.h"
#include "Adafruit_MCP23017.h"
#include <Wire.h>
#include <MIDIUSB.h>
Adafruit_MCP23017 mcp[2];
 
#ifndef _BV
#define _BV(bit) (1 << (bit))
#endif
 
MUX74HC4067 mux(6, 7, 8, 16 , 10);
Adafruit_MPR121 cap = Adafruit_MPR121();
 
byte motordown = 8;
byte motorup = 9;
 
double faderMax [12]; // Max Ausschlag Fader
double faderMin [12]; // Min Ausschlag Fader
 
byte Geratenummer;
int Wert;
int AnalogWert1[12];
int AnalogWert2[12];
int Wert2[12];
int FaderZielPos[12];
 
byte Fadernr;
int a = 0;
const int SMOOTH_POWER = 100;
 
uint16_t currtouched = 0;
 
void controlChange(byte channel, byte control, byte value) {
  midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
  MidiUSB.sendMIDI(event);
}
 
void setup() {
  Serial.begin(9600);
  mux.signalPin(A3, INPUT, ANALOG);
  cap.begin(0x5A);
 
 
  pinMode (4, OUTPUT);
  pinMode (6, OUTPUT);
  pinMode (5, OUTPUT);
  analogWrite(9, 255);
 
 
  mcp[0].begin(6);
  mcp[1].begin(4);
  mcp[0].pinMode(0, OUTPUT);
  mcp[0].pinMode(1, OUTPUT);
  mcp[0].pinMode(2, OUTPUT);
  mcp[0].pinMode(3, OUTPUT);
  mcp[0].pinMode(4, OUTPUT);
  mcp[0].pinMode(5, OUTPUT);
  mcp[0].pinMode(6, OUTPUT);
  mcp[0].pinMode(7, OUTPUT);
  mcp[0].pinMode(8, OUTPUT);
  mcp[0].pinMode(9, OUTPUT);
  mcp[0].pinMode(10, OUTPUT);
  mcp[0].pinMode(11, OUTPUT);
  mcp[0].pinMode(12, OUTPUT);
  mcp[0].pinMode(13, OUTPUT);
  mcp[0].pinMode(14, OUTPUT);
  mcp[0].pinMode(15, OUTPUT);
 
  mcp[1].pinMode(0, OUTPUT);
  mcp[1].pinMode(1, OUTPUT);
  mcp[1].pinMode(2, OUTPUT);
  mcp[1].pinMode(3, OUTPUT);
  mcp[1].pinMode(4, OUTPUT);
  mcp[1].pinMode(5, OUTPUT);
  mcp[1].pinMode(6, OUTPUT);
  mcp[1].pinMode(7, OUTPUT);
  mcp[1].pinMode(8, OUTPUT);
  mcp[1].pinMode(9, OUTPUT);
  mcp[1].pinMode(10, OUTPUT);
  mcp[1].pinMode(11, OUTPUT);
  mcp[1].pinMode(12, OUTPUT);
  mcp[1].pinMode(13, OUTPUT);
  mcp[1].pinMode(14, OUTPUT);
  mcp[1].pinMode(15, OUTPUT);
 
  Cali();
}
 
void loop() {
 Geratenummer = 0;
  midiEventPacket_t rx;
  rx = MidiUSB.read();
  if (rx.header != 0) {
    Geratenummer = (rx.byte1);
    Fadernr = (rx.byte2);
    Wert = (rx.byte3);
  }
  if (Geratenummer == 181) {
    if (Fadernr > 0 && Fadernr < 12) {
      FaderZielPos[Fadernr] = Wert;
    }
  for (int MCPnr = 0; MCPnr < 2; MCPnr++) {
    for (int Fadernr = 1; Fadernr < 12; Fadernr++) {
      Fader(Fadernr, FaderZielPos[Fadernr], MCPnr);
    }
  }
  }
 
  for ( int i = 0; i < 12 ; i++) {
    Touch(i);
  }
}
 
void Fader (int nr, int ZielPos, int MCPnr) {
  Wert2[nr] =map(mux.read(nr), faderMin[nr], faderMax[nr], 0, 127);
   if (MCPnr == 0 && (!(cap.touched() & (1 << 1)))) {
    while (ZielPos != Wert2[nr]){
     
      if (ZielPos < Wert2[nr]-10) {
      mcp[0].digitalWrite((nr * 2) - 1, HIGH);
      mcp[0].digitalWrite((nr * 2) - 2, LOW);
 
 
    }    
     else if (ZielPos > Wert2[nr]+10) {
     mcp[0].digitalWrite((nr * 2) - 2, HIGH);
     mcp[0].digitalWrite((nr * 2) - 1, LOW);
     
    }
 
     else {
      mcp[0].digitalWrite((nr * 2) - 1, LOW);
      mcp[0].digitalWrite((nr * 2) - 2, LOW);
    }
         }}}
 
 
 
void Touch(int i) {
  if (cap.touched () & (1 << i)) {
    AnalogWert1[i] = mux.read(i);
    AnalogWert2[i] = map (AnalogWert1[i], 950, 60, 127, 0);
    if ( AnalogWert2[i] > 127) {
      AnalogWert2[i] = 127;
    }
    if (AnalogWert2[i] < 0) {
        AnalogWert2[i] = 0;
    }
    controlChange (181, i, AnalogWert2[i]);
    MidiUSB.flush();
  }
 
}
void Cali () {
  mcp[0].digitalWrite(0, HIGH);
  delay(100);
  mcp[0].digitalWrite(0, LOW);
  faderMax[1] = mux.read(1);
  mcp[0].digitalWrite(1, HIGH);
  delay(100);
  mcp[0].digitalWrite(1, LOW);
  faderMin[1] = mux.read(1);
  mcp[0].digitalWrite(2, HIGH);
  delay(100);
  mcp[0].digitalWrite(2, LOW);
  faderMax[2] = mux.read(2);
  mcp[0].digitalWrite(3, HIGH);
  delay(100);
  mcp[0].digitalWrite(3, LOW);
  faderMin[2] = mux.read(2);
  mcp[0].digitalWrite(4, HIGH);
  delay(100);
  mcp[0].digitalWrite(4, LOW);
  faderMax[3] = mux.read(3);
  mcp[0].digitalWrite(5, HIGH);
  delay(100);
  mcp[0].digitalWrite(5, LOW);
  faderMin[3] = mux.read(3);
  mcp[0].digitalWrite(6, HIGH);
  delay(100);
  mcp[0].digitalWrite(6, LOW);
  faderMax[4] = mux.read(4);
  mcp[0].digitalWrite(7, HIGH);
  delay(100);
  mcp[0].digitalWrite(7, LOW);
  faderMin[4] = mux.read(4);
  mcp[0].digitalWrite(8, HIGH);
  delay(100);
  mcp[0].digitalWrite(8, LOW);
  faderMax[5] = mux.read(5);
  mcp[0].digitalWrite(9, HIGH);
  delay(100);
  mcp[0].digitalWrite(9, LOW);
  faderMin[5] = mux.read(5);
  mcp[0].digitalWrite(10, HIGH);
  delay(100);
  mcp[0].digitalWrite(10, LOW);
  faderMax[6] = mux.read(6);
  mcp[0].digitalWrite(11, HIGH);
  delay(100);
  mcp[0].digitalWrite(11, LOW);
  faderMin[6] = mux.read(6);
  mcp[0].digitalWrite(12, HIGH);
  delay(100);
  mcp[0].digitalWrite(12, LOW);
  faderMax[7] = mux.read(7);
  mcp[0].digitalWrite(13, HIGH);
  delay(100);
  mcp[0].digitalWrite(13, LOW);
  faderMin[7] = mux.read(7);
  mcp[0].digitalWrite(14, HIGH);
  delay(100);
  mcp[0].digitalWrite(14, LOW);
  faderMax[8] = mux.read(8);
  mcp[0].digitalWrite(15, HIGH);
  delay(100);
  mcp[0].digitalWrite(15, LOW);
  faderMin[8] = mux.read(8);
  mcp[1].digitalWrite(0, HIGH);
  delay(100);
  mcp[1].digitalWrite(0, LOW);
  faderMax[9] = mux.read(9);
  mcp[1].digitalWrite(1, HIGH);
  delay(100);
  mcp[1].digitalWrite(1, LOW);
  faderMin[9] = mux.read(9);
  mcp[1].digitalWrite(2, HIGH);
  delay(100);
  mcp[1].digitalWrite(2, LOW);
  faderMax[10] = mux.read(10);
  mcp[1].digitalWrite(3, HIGH);
  delay(100);
  mcp[1].digitalWrite(3, LOW);
  faderMin[10] = mux.read(10);
  mcp[1].digitalWrite(4, HIGH);
  delay(100);
  mcp[1].digitalWrite(4, LOW);
  faderMax[11] = mux.read(11);
  mcp[1].digitalWrite(5, HIGH);
  delay(100);
  mcp[1].digitalWrite(5, LOW);
  faderMin[11] = mux.read(11);
  delay(100);
  delay(1000);
}

can somebody Help me to solve the problem ?
best regards

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

Hi, i updatet the first post.

considering both the lack of comments in the code and symbols not in english, it would help if you provide an explanation of what the program is expected to do, what each function is expected to do.

try your best

Hi
Ops circuit;

Tom... :slight_smile: