#define M1_1 3        // router
#define M1_2 5
#define M3_1 6        // drill, ftnano: 6 and 9 for PWM
#define M3_2 9
#define M5_1 10       // table
#define M5_2 11
#define SWITCH A0
#define LED 2

const int PWMSpeedTable = 200;      // PWM for table speed (~80 - 255)
const int TableDelay = 360;         // ms  delay after IR detect - try out

void setup() 
{
  pinMode (M1_1, OUTPUT);   // router
  pinMode (M1_2, OUTPUT);
  pinMode (M3_1, OUTPUT);   // drill
  pinMode (M3_2, OUTPUT);
  pinMode (M5_1, OUTPUT);   // table
  pinMode (M5_2, OUTPUT);
  pinMode (SWITCH, INPUT);
  pinMode (LED, OUTPUT);

  digitalWrite (M1_1, LOW);   // engines stop
  digitalWrite (M1_2, LOW);
  digitalWrite (M3_1, LOW);
  digitalWrite (M3_2, LOW);
  digitalWrite (M5_1, LOW);
  digitalWrite (M5_2, LOW);
  digitalWrite (LED, LOW);   // ON
}

void loop() {
  analogWrite (M5_1, PWMSpeedTable);    // engine table start

  if (digitalRead(SWITCH))    // rotate nearly complete
  {
    delay (TableDelay);         // rotate a little bit more
    analogWrite (M5_1, 0);      // engine table stop
    digitalWrite (LED, HIGH);   // OFF
    delay (2000);  // just wait
    digitalWrite (LED, LOW);   // ON

    digitalWrite (M1_1, HIGH);  // router start
    analogWrite (M3_2, 75);     // drill start right direction (into), slow
    delay (1500);
    analogWrite (M3_2, 0);     // drill stop
    delay (500);
    analogWrite (M3_1, 150);     // drill start left rotation (out), fast
    delay (1000);
    analogWrite (M3_1, 0);     // drill stop
    delay (2000);
    digitalWrite (M1_1, LOW);  // router stop
    delay (200);  // just wait
  }
}
