const int touchPin = D0; const int ledPin = D1; // LED1 const int ledPin2 = D2; // LED2 const unsigned long LED_ON_MS = 500; int touchCount = 0; bool touchLatched = false; void pulseLeds(bool led1On, bool led2On) { digitalWrite(ledPin, led1On ? HIGH : LOW); digitalWrite(ledPin2, led2On ? HIGH : LOW); delay(LED_ON_MS); digitalWrite(ledPin, LOW); digitalWrite(ledPin2, LOW); } void setup() { pinMode(touchPin, INPUT); pinMode(ledPin, OUTPUT); pinMode(ledPin2, OUTPUT); Serial.begin(115200); } void loop() { int touch = digitalRead(touchPin); if (touch == HIGH && !touchLatched) { touchLatched = true; touchCount++; int phase = touchCount % 3; if (phase == 1) { pulseLeds(true, false); // 1st touch → LED1 } else if (phase == 2) { pulseLeds(false, true); // 2nd touch → LED2 } else { pulseLeds(true, true); // 3rd touch → both } } if (touch == LOW) { touchLatched = false; // ready for next touch } }