// Define the pins for phase detection
#define phaseAPin 18   // Pin number for phase A detection
#define phaseBPin 2    // Pin number for phase B detection
#define phaseCPin 3    // Pin number for phase C detection

// Variables to store phase states
bool phaseA;  // State of phase A (true for active, false for inactive)
bool phaseB;  // State of phase B (true for active, false for inactive)
bool phaseC;  // State of phase C (true for active, false for inactive)

void setup() {
  Serial.begin(115200);               // Initialize serial communication
  pinMode(LED_BUILTIN, OUTPUT);       // Set built-in LED pin as output
  pinMode(phaseAPin, INPUT_PULLUP);   // Set phase A pin as input with pull-up resistor
  pinMode(phaseBPin, INPUT_PULLUP);   // Set phase B pin as input with pull-up resistor
  pinMode(phaseCPin, INPUT_PULLUP);   // Set phase C pin as input with pull-up resistor

  // Read initial phase states
  phaseA = digitalRead(phaseAPin);
  phaseB = digitalRead(phaseBPin);
  phaseC = digitalRead(phaseCPin);

  // Attach interrupts to phase pins
  attachInterrupt(digitalPinToInterrupt(phaseAPin), PhaseA, CHANGE); // Attach interrupt for phase A pin
  attachInterrupt(digitalPinToInterrupt(phaseBPin), PhaseB, CHANGE);  // Attach interrupt for phase B pin
  attachInterrupt(digitalPinToInterrupt(phaseCPin), PhaseC, CHANGE);  // Attach interrupt for phase C pin
}

void loop() {
  // Print phase states to serial monitor
  Serial.println( "Phase A:= " + String(phaseA)
                  + ", Phase B:= " + String(phaseB)
                  + ", Phase C:= " + String(phaseC)
                );
}

// Interrupt service routine for phase A
void PhaseA() {
  phaseA = digitalRead(phaseAPin);  // Update phase A state
}

// Interrupt service routine for phase B
void PhaseB() {
  phaseB = digitalRead(phaseBPin);  // Update phase B state
}

// Interrupt service routine for phase C
void PhaseC() {
  phaseC = digitalRead(phaseCPin);  // Update phase C state
}
3 Phase PulseBreakout