 #define SEL_B 31 //0 su 2
 #define BT_A A14 //0 premuto
 #define BT_B A8 //1 premuto
+#define SEL_Gp A5 //0 su G e 1 su p
 
 long muovi(char let, int vel, int posA, int posB, int posC = 0);
 long t0 = 0;
+long dd = 100;
+long tdd = 0;
+
+uint8_t channels[16] = {53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38};
 
 void setup() {
   pinMode(MAINSW, INPUT_PULLUP);

    {
      if (digitalRead(BT_A) == 0)  //premuto
      {
        Serial.println("motore B/D orario");
        ///////////////////////////
        Serial2.print("P 3000");
        Serial2.print('\r');
        delay(100);
        Serial2.print("p 0 10");
        Serial2.print('\r');
        delay(100);
        Serial2.print("G 3000");
        Serial2.print('\r');
        delay(100);
        Serial2.print("g 0 -10 0");
        Serial2.print('\r');
        ////////////////////////////
        delay(1000);
      }
      else if (digitalRead(BT_B) == 1)  //premuto
      {
        Serial.println("motore B/D antiorario");
        ///////////////////////////
        Serial2.print("P 3000");
        Serial2.print('\r');
        delay(100);
        Serial2.print("p 0 -10");
        Serial2.print('\r');
        delay(100);
        Serial2.print("G 3000");
        Serial2.print('\r');
        delay(100);
        Serial2.print("g 0 10 0");
        Serial2.print('\r');
        ////////////////////////////
        delay(1000);
      }
    }

int act = 0;
long att1 = 0;
long att2 = 0;
bool inviatoG = false;
bool inviatop = false;

void loop() {
  while (digitalRead(MAINSW)) //SHOW
  {
    if (act == 0) {
      t0= millis();
      Serial.println("ACT 0");
      inviatop = false;
      inviatoG = false;
      act++;
    }
    show_uno();
  }
  while (!digitalRead(MAINSW)) //TEST
  {
    act = 0;

    if (Serial.available() > 0) {
      Serial2.write(Serial.read());
    }

    if ((digitalRead(SEL_A) == 0) && (digitalRead(SEL_B) == 1)) //A
    {
      if (digitalRead(BT_A) == 0)  //premuto
      {
        if (digitalRead(SEL_Gp)) //1 è piccolo
        {
          Serial.println("motore A orario");
          ///////////////////////////
          Serial2.print("P 3000");
          Serial2.print('\r');
          delay(100);
          Serial2.print("p 10 0");
          Serial2.print('\r');
        }
        else
        {
          Serial.println("motore C orario");
          Serial2.print("G 3000");
          Serial2.print('\r');
          delay(100);
          Serial2.print("g 10 0 0");
          Serial2.print('\r');
          ////////////////////////////
        }
        delay(1000);
      }
      else if (digitalRead(BT_B) == 1)  //premuto
      {
        if (digitalRead(SEL_Gp)) //1 è piccolo
        {
          Serial.println("motore A antiorario");
          ///////////////////////////
          Serial2.print("P 3000");
          Serial2.print('\r');
          delay(100);
          Serial2.print("p -10 0");
          Serial2.print('\r');
        }
        else
        {
          Serial.println("motore C antiorario");
          Serial2.print("G 3000");
          Serial2.print('\r');
          delay(100);
          Serial2.print("g -10 0 0");
          Serial2.print('\r');
          ////////////////////////////
        }
        delay(1000);
      }
    }
