Progetto Testamobile DMX

Buonasera a tutti, sto cercando di rimodernare una mia vecchia testa mobile i motori che ho utilizzato sono quelli originali e sono degli stepper pilotati da due driver ad H.
Il mio problema è proprio nella gestione dei motori il sistema funziona abbastanza bene solo che è "lento" a rispondere alzando i canali della centralina DMX per esempio prima il pan e poi il colore rosso i colori non si eseguiranno in sieme al movimento ma, prima si posizione alla posizione comandata dal fader della centralina e poi accende il rosso.
spero di essermi spiegato Grazie per chiunque abbia la pazienza di aiutarmi.

#include <Arduino.h>
#include <TM1637Display.h>
#include <EEPROM.h>
#include <SoftwareSerial.h>
#include <DMXSerial.h>
#include <Stepper.h>
// Impostazione delle variabili
int PanPin                =   0;      // Posizione Pan
int TiltPin               =   0;      // Posizione Tilt
const int RedPin          =  10;      // PWM output pin for Red Light.
const int GreenPin        =  11;      // PWM output pin for Green Light.
const int BluePin         =  12;      // PWM output pin for Blue Light.
const int WhitePin        =  13;      // PWM output pin for White Light.
int   DMX                      ;      // Indirizzo DMX
byte  DMX_L                    ;      // Indirizzo DMX
byte  DMX_H                    ;      // Indirizzo DMX
int  ValueUp              =   0;      //
int  ValueDw              =   0;      //
long Tempo1               =   0;      //
long Tempo2               =  50;      //
int  ValueCombUp          =   5;      //
int  ValueCombDw          =   5;      //
int dimmerporcent         =   0;
int dimmer                =   0;
int strobo                =   0;
int r                     =   0;
int g                     =   0;
int b                     =   0;
int w                     =   0;
int pan                   =   0;
int tilt                  =   0;
long previous_p           =   0;
long previous_t           =   0;
long val_p                =   0;
long val_t                =   0;
boolean Set_p_ok          =   0;
boolean Set_t_ok          =   0;

#define TastoUp              45      // Tasto +
#define TastoDw              47      // Tasto -
#define PanSet               51      // finecorsa pan
#define TiltSet              53      // finecorsa tilt
#define CLK                  43
#define DIO                  41
#define RX_PIN 0 // serial receive pin, which takes the incoming data from the MAX485.
// The amount of time (in milliseconds) between tests
#define TEST_DELAY  200
TM1637Display display(CLK, DIO);
// change this to the number of steps on your motor
#define STEPS 200
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper_t (STEPS, 2, 3, 4, 5);
Stepper stepper_p (STEPS, 6, 7, 8, 9);
void setup () {
   DMX_H =  EEPROM.read(1);
   DMX_L =  EEPROM.read(2);
   DMX = word (DMX_H,DMX_L);
//  pinMode(RX0, INPUT);  //sets serial pin to receive data
  DMXSerial.init(DMXReceiver);
  // set some default values
  DMXSerial.write(DMX, 0);
  DMXSerial.write(DMX + 1, 0);
  DMXSerial.write(DMX + 2, 0);
  DMXSerial.write(DMX + 3, 0);
  DMXSerial.write(DMX + 4, 0);
  DMXSerial.write(DMX + 5, 0);
  DMXSerial.write(DMX + 6, 0);
  DMXSerial.write(DMX + 7, 0);
// enable pwm outputs
  pinMode(RedPin,   OUTPUT); // sets the digital pin as output
  pinMode(GreenPin, OUTPUT);
  pinMode(BluePin,  OUTPUT);
  pinMode(WhitePin, OUTPUT);
  pinMode(TastoUp,   INPUT);
  pinMode(TastoDw,   INPUT);
  pinMode(PanSet,    INPUT);
  pinMode(TiltSet,   INPUT);  


  // set the speed of the motor to 90 RPMs
  stepper_p.setSpeed(90);
  stepper_t.setSpeed(90);
    int k;
  uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
  display.setBrightness(0x0f);
}
void loop() {
   display.showNumberDec(DMX);
// SET pan e tilt all'accensione
   int SetPan  = digitalRead(PanSet);
   int SetTilt = digitalRead(TiltSet);
 if (SetPan == HIGH && Set_p_ok == LOW){
  stepper_p.step(1);}
  if (SetPan == LOW && Set_p_ok == LOW){
  stepper_p.step(-1);}
 if (SetPan == LOW && Set_p_ok == LOW){
    val_p = (0);
    previous_p = (0);
    stepper_p.step(0);
    Set_p_ok = HIGH;  } 

 if (SetTilt == HIGH && Set_t_ok == LOW){
  stepper_t.step(1);}
 if (SetTilt == LOW && Set_t_ok == LOW){
  stepper_t.step(-1);}
 if (SetTilt == LOW && Set_t_ok == LOW){
    val_t = (0);
    previous_t = (0);    
    stepper_t.step(0);
    Set_t_ok = HIGH;  } 
      
  //********** TASTO *****************
  int valoreTastoUp = digitalRead(TastoUp);
  int valoreTastoDw = digitalRead(TastoDw);
  //--------INIZIO ESECUZIONE ------------------
  if (valoreTastoUp == HIGH)
  {
    DMX = DMX + 1;
 //display.showNumberDec(DMX);
  DMX_H = highByte(DMX);
  DMX_L = lowByte(DMX);
  EEPROM.write(1,DMX_H);
  EEPROM.write(2,DMX_L);
  
  if (DMX > 506) {
    (DMX = 1);
 //display.showNumberDec(DMX);
  DMX_H = highByte(DMX);
  DMX_L = lowByte(DMX);
  EEPROM.write(1,DMX_H);
  EEPROM.write(2,DMX_L);
  }}
  if (valoreTastoDw == HIGH)
  {
    DMX = DMX - 1;
 // display.showNumberDec(DMX);
  DMX_H = highByte(DMX);
  DMX_L = lowByte(DMX);
  EEPROM.write(1,DMX_H);
  EEPROM.write(2,DMX_L);
  
  if (DMX < 1) {
    (DMX = 506);
 //display.showNumberDec(DMX);
  DMX_H = highByte(DMX);
  DMX_L = lowByte(DMX);
  EEPROM.write(1,DMX_H);
  EEPROM.write(2,DMX_L);
  }}
  // Calculate how long no data backet was received
  unsigned long lastPacket = DMXSerial.noDataSince();

  if (lastPacket < 5000 && Set_p_ok == HIGH && Set_t_ok == HIGH) {
    // read recent DMX values and set pwm levels
    pan          =       (DMXSerial.read(DMX + 0));
    tilt         =       (DMXSerial.read(DMX + 1));
    r            =       (DMXSerial.read(DMX + 2));
    g            =       (DMXSerial.read(DMX + 3));
    b            =       (DMXSerial.read(DMX + 4));
    w            =       (DMXSerial.read(DMX + 5));
    dimmer       =       (DMXSerial.read(DMX + 6));
    strobo       =       (DMXSerial.read(DMX + 7));
  }
else { 
  if (Set_p_ok == HIGH && Set_t_ok == HIGH){
//Show pure red color, when no data was received since 5 seconds or more.
   display.setBrightness(7, false);  // Turn off
    display.showNumberDec(DMX);
   delay(TEST_DELAY);
   display.setBrightness(7, true); // Turn on
    display.showNumberDec(DMX);
   delay(TEST_DELAY);
  }}
if (Set_p_ok == HIGH && Set_t_ok == HIGH){
  // calcolo step motore pan = dmx x rotazioni x moltiplicatore puleggia
  val_p = (pan * -4) ;
  // calcolo step motore tilt = dmx x rotazioni x moltiplicatore puleggia
  val_t = (tilt * -20);
}
  // move a number of steps equal to the change in the
  // sensor reading
  stepper_p.step(val_p - previous_p);
  // remember the previous value of the sensor
  previous_p = val_p;

  // move a number of steps equal to the change in the
  // sensor reading
  stepper_t.step(val_t - previous_t);
  // remember the previous value of the sensor
  previous_t = val_t;

  dimmerporcent     = map(dimmer, 0, 255, 100, 0);
  int stroboporcent = map(strobo, 0, 255, 400, 10);
  int r_final_p       = r * dimmerporcent / 100;
  int g_final_p       = g * dimmerporcent / 100 ;
  int b_final_p       = b * dimmerporcent / 100 ;
  int w_final_p       = w * dimmerporcent / 100 ;


  int r_final       = map(r_final_p, 0, 255, 255, 0);
  int g_final       = map(g_final_p, 0, 255, 255, 0);
  int b_final       = map(b_final_p, 0, 255, 255, 0);
  int w_final       = map(w_final_p, 0, 255, 255, 0);
  
  if ( strobo > 1 )
  {
    analogWrite(RedPin, 0);
    analogWrite(GreenPin, 0);
    analogWrite(BluePin, 0);
    analogWrite(WhitePin, 0);
    delay(stroboporcent);

    analogWrite(RedPin, r_final);
    analogWrite(GreenPin, g_final);
    analogWrite(BluePin, b_final);  
    analogWrite(WhitePin, w_final);
    delay (stroboporcent);
  }
  else {
    analogWrite(RedPin, r_final);
    analogWrite(GreenPin, g_final);
    analogWrite(BluePin, b_final);
    analogWrite(WhitePin, w_final);
  }
}
// End.