Using Pogo Connector to activate MP3 file

Good day, all. Been a while since needing help and working on a new clock project. I have the attached code working quite well with my project (minus the pogo connections part); however, now I am struggling to successfully activate a file on the DF Mini Player via pogo connectors. Admittedly, I have tried AI to no avail, as it just doesn’t understand what I want and, if it does, gives me the runaround in wiring configurations and eventually frustratedly typing at it in anger! :laughing:
Below are the details (if you want to know the basis of my project) and ( if TL;DR) my Request: at the end before my currently working code. Thank you in advance and if I’ve missed anything, please be kind. I have tried to understand the forum protocols and am not, by nature, a programmer or coder.

Project: “Lego” Darth Vader Clock w/ 4-stud and 8-stud key/coin tray base.
Hardware includes: ESP32 Wemos D1 Mini Node MCU (38 pin), TM1637 display, Rotary Encoder Module, DF Mini Player (& 23 mm 8ohm/2W speaker), TTP223B Touch Sensor Module, 2-pin M/F Pogo Pin Connector, 300 mm Red LED Filament, SMD LEDs (reds, green), 3V LED Beads.
Setup: All components are installed in the legs/body of the figurine. The TM1637 rests in the chest area, just below the speaker. Above the TM1637 is the DF Mini Player and above it is the rotary encoder dial (dial stem sets inside the neck) and the figurine head sets on the dial stem. Pushing down on the head (or the helmet, if placed on the head) cycles through the clock features (timer, alarm, etc.), turning the head makes adjustments (selecting hrs/min, timer seconds, time format, etc.) and pushing the head sets the selection. Each push of the head triggers one of 11 MP3 “Darth Vader” files.
SMD LEDs are in the chest covering and three Red LEDs (listed in code as Blue from previous build) flash on/off each second with the clock’s colon, one Red LED fades in/out consistently and the Green (listed in code as White from previous build) LED activates with the others when alarms/timers are activated.
Each foot has an LED bulb attached in the bottom opening and are activated via an embedded TTP223B Touch Sensor located on the inside of leg.
The light saber (aka ELED) is “hermetically” sealed (all glued up and cannot access without printing another one) with the 330 mm LED filament and resistor and lights up when magnetically placed in the right hand, connected to 3.3V and GND.
Wiring: All wiring is Dupont connectors or soldered wire and grounded via Wago connectors. Except for the ELED, every component is powered via the 5V pin (SMDs have enough resistance to accommodate and are in parallel.) The waist and upper body have 2x3mm magnets on their perimeters to be able to access the display (to change out from Red to Blue or other colors, depending on visual preferences) and to make changes to the SD card on the DF Mini Player or wiring issues if necessary.

Request: I have the 3.3V pin of my ESP32 connected to pin 1 (positive) of the male pogo connector (MPP1). Pin 1 (positive) of the hermetically sealed (and henceforth inaccessible) female connector (FPP1) goes to the anode of the LED. The cathode connects to a 220 ohm resistor and then to pin 2 (negative) of the female connector (FPP2). Pin 2 (negative) of the male pogo connector (MPP2) is attached to Ground and the LED is brightly lit. What I want to accomplish is when the pogo connectors are mated, the LED will light up brightly and trigger the MP3 player to play MP3 file #4 one time. What I DO NOT WANT is for the ELED to flash in sync (float) while the file plays NOR DO I want the file to play when the pogo connectors are un-mated. IF it is necessary to use a 3-pin pogo connector or NPN/PNP transistors, I do have them available… somewhere.

Thank you again for your consideration and Continue to Be Blessed!

/*----------------------------------------------
 * Darth Vader Clock
 *
 * Board: Node32s
 * 
 *--------------------------------------------*/

#include "WiFiManager.h"
#include "ezTime.h"
#include "SevenSegmentExtended.h"
#include "SevenSegmentTM1637.h"
#include "SevenSegmentFun.h"
#include <HardwareSerial.h>
#include "DFRobotDFPlayerMini.h"
#include <EEPROM.h>

//========================USEFUL VARIABLES=============================
const char* ssid = "DARTH_VADER_WIFI";
const char* password = "USE_THE_FORCE";
uint16_t notification_volume = 25;
int Display_backlight = 45;
int BlueLED_brightness = 255;
const char* ntpServer = "pool.ntp.org";
const String timezone_posix_string = "EST5EDT,M3.2.0/2:00:00,M11.1.0/2:00:00";
//=====================================================================

// Call WiFi Manager
WiFiManager wifiManager;

// Call a Timezone
Timezone TZ;

#define CLK 23
#define DT 19
#define SW 18
#define RED_LED 27
#define WHITE_LED 26
#define BLUE_LED 25
#define sensor_pin 33
#define L_FOOT_LED 14  // Renamed GPIO 14
#define R_FOOT_LED 5   // Added new GPIO 5
#define POGO_TRIGGER_PIN 13
enum SETUP { SHOW_TIME,
             TIMER,
             TIME_FORMAT,
             ALARM_ONOFF,
             ALARM_HOUR,
             ALARM_MIN };
SETUP setupMode = SHOW_TIME;
enum SHOW { HOURS,
            MINUTES };

//Uncomment to reset EEPROM data
//#define RESET_EEPROM
#define EEPROM_ADDRESS 0
#define EEPROM_MAGIC 0x0DAD0BAD
typedef struct {
  uint32_t magic;
  bool timeFormat;
  bool alarmOn;
  int8_t alarmHour;
  int8_t alarmMinute;
} EEPROM_DATA;

EEPROM_DATA EepromData;

bool set24 = false;
bool setAO = false;
int8_t setAH = 0;
int8_t setAM = 0;
bool alarmCancelled = false;
bool colon = true;

float counter = 0;
int currentStateCLK;
int lastStateCLK;
String currentDir = "";
unsigned long lastButtonPress = 0;
int laststate = LOW;
int currentstate;
int ledstate = LOW;
int timer_secs = 0;
int timer_mins = 0;
float inc_red_led = 0;

const int BlueChannel = 1;
const int freq = 5000;
const int resolution = 8;
int lastPogoState = HIGH;

SevenSegmentExtended blue1(21, 22);
SevenSegmentFun words(21, 22);

#define DFPLAYER_RX_PIN 16
#define DFPLAYER_TX_PIN 17

HardwareSerial dfPlayerSerial(2);
DFRobotDFPlayerMini myDFPlayer;

void printDetail(uint8_t type, int value);
void configModeCallback(WiFiManager* myWiFiManager);
void saveConfigCallback();
void checkPogoConnector();
void showTime();
void showPartialTime(SHOW s, int num, bool leadingZeros, bool on, bool c);
void setTimeFormat();
void showTimeFormat();
void setAlarmState();
void showAlarmState();
void setAlarmHour();
void showAlarmHour();
void setAlarmMinute();
void showAlarmMinute();
void turnOnAlarm();
bool setupTimer();
void Countdown(float timer_counter);
void playFolderTrackWithLights(int track);
int readRotaryEncoder();
void waitMilliseconds(uint16_t msWait);
void writeEepromData();
void readEepromData();

void printDetail(uint8_t type, int value) {
  switch (type) {
    case TimeOut:
      Serial.println(F("Time Out!"));
      break;
    case WrongStack:
      Serial.println(F("Stack Wrong!"));
      break;
    case DFPlayerCardInserted:
      Serial.println(F("Card Inserted!"));
      break;
    case DFPlayerCardRemoved:
      Serial.println(F("Card Removed!"));
      break;
    case DFPlayerCardOnline:
      Serial.println(F("Card Online!"));
      break;
    case DFPlayerUSBInserted:
      Serial.println(F("USB Inserted!"));
      break;
    case DFPlayerUSBRemoved:
      Serial.println(F("USB Removed!"));
      break;
    case DFPlayerPlayFinished:
      Serial.print(F("Number:"));
      Serial.print(value);
      Serial.println(F(" Play Finished!"));
      break;
    case DFPlayerError:
      Serial.print(F("DFPlayerError:"));
      switch (value) {
        case Busy:
          Serial.println(F("Busy"));
          break;
        case Sleeping:
          Serial.println(F("Sleeping"));
          break;
        case SerialWrongStack:
          Serial.println(F("Get Wrong Stack"));
          break;
        case CheckSumNotMatch:
          Serial.println(F("Check Sum Not Match"));
          break;
        case FileIndexOut:
          Serial.println(F("File Index Out of Bound"));
          break;
        case FileMismatch:
          Serial.println(F("Cannot Find File"));
          break;
        case Advertise:
          Serial.println(F("In Advertise"));
          break;
        default:
          break;
      }
      break;
    default:
      break;
  }
}

void configModeCallback(WiFiManager* myWiFiManager) {
  Serial.println("Entered WiFi Manager config mode..");
  Serial.println(WiFi.softAPIP());
  Serial.println(myWiFiManager->getConfigPortalSSID());
}

bool shouldSaveConfig = false;

void saveConfigCallback() {
  Serial.println("Should save config");
  shouldSaveConfig = true;
}

// Debounce timing
unsigned long lastPogoTriggerTime = 0;
const unsigned long debounceDelay = 100;  // Adjust as needed, in milliseconds

void checkPogoConnector() {
  int pogoState = digitalRead(POGO_TRIGGER_PIN);

  // // Trigger on Connection (pin goes from HIGH to LOW)
  // Trigger on Connection (pin goes from HIGH to LOW)
  // if (pogoState == LOW && lastPogoState == HIGH) {
  //   if (millis() - lastPogoTriggerTime > debounceDelay) {
  //     myDFPlayer.play(4);
  //     Serial.println("Pogo pins connected! Playing track 4.");
  //     lastPogoTriggerTime = millis();
  //   }
  // }

  // This line helps you see if the pin state is stable
  if (pogoState != lastPogoState) {
    Serial.print("Pogo pin state changed to: ");
    Serial.println(pogoState == LOW ? "LOW" : "HIGH");
  }


  // // Trigger on Disconnection (pin goes from LOW to HIGH)
  if (pogoState == HIGH && lastPogoState == LOW) {
    if (millis() - lastPogoTriggerTime > debounceDelay) {
      myDFPlayer.play(4);
      Serial.println("Pogo pins disconnected! Playing track 4.");
      lastPogoTriggerTime = millis();
    }
  }

  lastPogoState = pogoState;
}

void setup() {
  words.setBacklight(80);
  words.begin();
  words.scrollingText("USE THE FORCE JOSHUA AND LEYLANE", 2);

  pinMode(CLK, INPUT);
  pinMode(DT, INPUT);
  pinMode(SW, INPUT_PULLUP);
  pinMode(RED_LED, OUTPUT);
  pinMode(WHITE_LED, OUTPUT);
  pinMode(BLUE_LED, OUTPUT);
  pinMode(sensor_pin, INPUT);
  pinMode(L_FOOT_LED, OUTPUT);  // Updated to L_FOOT_LED
  pinMode(R_FOOT_LED, OUTPUT);  // Added R_FOOT_LED
  pinMode(POGO_TRIGGER_PIN, INPUT_PULLUP);

  ledcSetup(0, 5000, 8);
  ledcAttachPin(RED_LED, 0);

  Serial.begin(115200);

  wifiManager.setAPStaticIPConfig(IPAddress(192, 168, 2, 1), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0));
  WiFiManagerParameter custom_text("<p>Welcome to Darth Vader: Please connect to WiFi using this portal</p>");
  wifiManager.addParameter(&custom_text);
  wifiManager.setAPCallback(configModeCallback);
  wifiManager.autoConnect(ssid, password);
  words.scrollingText("CONNECT TO DARTH VADER WIFI", 2);
  wifiManager.setSaveConfigCallback(saveConfigCallback);
  wifiManager.setConfigPortalTimeout(600);

  blue1.setBacklight(Display_backlight);
  blue1.begin();
  dfPlayerSerial.begin(9600, SERIAL_8N1, DFPLAYER_RX_PIN, DFPLAYER_TX_PIN);

  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
  if (!myDFPlayer.begin(dfPlayerSerial, true, true)) {
    Serial.println(F("Unable to begin:"));
    Serial.println(F("1.Please recheck the connection!"));
    Serial.println(F("2.Please insert the SD card!"));
    while (true) {
      delay(0);
    }
  }
  Serial.println(F("DFPlayer Mini online."));

  myDFPlayer.volume(notification_volume);

  Serial.print("IP assigned by DHCP is ");
  Serial.println(WiFi.localIP());

  Serial.println("\n Should be connected: Waiting for time sync");
  waitForSync();

  lastStateCLK = digitalRead(CLK);
  TZ.setPosix(timezone_posix_string);
  Serial.println("UTC: " + UTC.dateTime());
  Serial.println("Local Time: " + TZ.dateTime("G") + ":" + TZ.dateTime("i"));

  EEPROM.begin(sizeof(EEPROM_DATA));
  readEepromData();

  showTime();
  lastPogoState = digitalRead(POGO_TRIGGER_PIN);
}

void loop() {
  if (myDFPlayer.available()) {
    printDetail(myDFPlayer.readType(), myDFPlayer.read());
  }
  checkPogoConnector();

  if (minuteChanged()) {
    colon = !colon;
    showTime();

    Serial.println("Time " + String(TZ.hour()) + ":" + String(TZ.minute()));
    Serial.println("alarmOn=" + String(EepromData.alarmOn) + ", alarmCancelled=" + String(alarmCancelled));
    Serial.println("alarmTime=" + String(EepromData.alarmHour) + ":" + String(EepromData.alarmMinute));

    if (alarmCancelled && (TZ.hour() != EepromData.alarmHour || TZ.minute() != EepromData.alarmMinute)) {
      alarmCancelled = false;
    } else if (EepromData.alarmOn && !alarmCancelled && TZ.hour() == EepromData.alarmHour && TZ.minute() == EepromData.alarmMinute) {
      Serial.println("*** ALARM ON ****");
      turnOnAlarm();
      alarmCancelled = true;
    }
  } else if (secondChanged()) {
    colon = !colon;
    showTime();
  }

  ledcWrite(0, inc_red_led);
  digitalWrite(WHITE_LED, LOW);
  {
    int currentstate = digitalRead(sensor_pin);
    if (laststate == LOW && currentstate == HIGH) {
      if (ledstate == LOW) {
        ledstate = HIGH;
      } else if (ledstate == HIGH) {
        ledstate = LOW;
      }
      // Updated to control both foot LEDs
      digitalWrite(L_FOOT_LED, ledstate);
      digitalWrite(R_FOOT_LED, ledstate);
    }
    laststate = currentstate;
  }
  if (digitalRead(SW) == LOW) {
    if (millis() - lastButtonPress > 50) {
      Serial.println("Timer Button pressed!");
      bool repeatLoop = true;
      while (repeatLoop) {
        setupMode = (setupMode == ALARM_MIN) ? SHOW_TIME : (SETUP)((int)setupMode + 1);
        switch (setupMode) {
          case SHOW_TIME:
            showTime();
            repeatLoop = false;
            break;

          case TIMER:
            repeatLoop = setupTimer();
            if (!repeatLoop) {
              setupMode = SHOW_TIME;
              showTime();
            }
            break;

          case TIME_FORMAT:
            set24 = EepromData.timeFormat;
            setAO = EepromData.alarmOn;
            setAH = EepromData.alarmHour;
            setAM = EepromData.alarmMinute;
            setTimeFormat();
            break;

          case ALARM_ONOFF:
            setAlarmState();
            break;

          case ALARM_HOUR:
            setAlarmHour();
            break;

          case ALARM_MIN:
            setAlarmMinute();
            if (setAO != EepromData.alarmOn || setAH != EepromData.alarmHour || setAM != EepromData.alarmMinute || set24 != EepromData.timeFormat) {
              EepromData.timeFormat = set24;
              EepromData.alarmOn = setAO;
              EepromData.alarmHour = setAH;
              EepromData.alarmMinute = setAM;
              writeEepromData();
            }
            break;
        }
      }
    }
    lastButtonPress = millis();
  }
  inc_red_led = (inc_red_led <= 254) ? inc_red_led + 0.1 : 0;
  delay(1);
}

void showTime() {
  if (EepromData.timeFormat) {
    showPartialTime(HOURS, TZ.dateTime("H").toInt(), true, true, colon);
  } else {
    showPartialTime(HOURS, TZ.dateTime("g").toInt(), false, true, colon);
  }
  showPartialTime(MINUTES, TZ.dateTime("i").toInt(), true, true, colon);
  digitalWrite(BLUE_LED, colon ? HIGH : LOW);
}

void showPartialTime(SHOW s, int num, bool leadingZeros, bool on, bool c) {
  num = max(min(num, 99), 0);
  int b = (s == HOURS) ? 0 : 2;
  for (int i = 0; i < 2; i++) {
    if (on && (num > 0 || i == 0 || leadingZeros)) {
      blue1.setColonOn(c);
      blue1.printRaw(blue1.encode((int16_t)(num % 10)), b + 1 - i);
    } else {
      blue1.printRaw((uint8_t)TM1637_CHAR_SPACE, b + 1 - i);
    }
    num = num / 10;
  }
}

void setTimeFormat() {
  Serial.println("In time format!");
  showTimeFormat();
  digitalWrite(RED_LED, HIGH);
  digitalWrite(WHITE_LED, HIGH);
  myDFPlayer.play(9);
  delay(500);
  while (digitalRead(SW) == HIGH) {
    if (myDFPlayer.available()) {
      printDetail(myDFPlayer.readType(), myDFPlayer.read());
    }
    switch (readRotaryEncoder()) {
      case 1:
        set24 = true;
        showTimeFormat();
        break;
      case -1:
        set24 = false;
        showTimeFormat();
        break;
      default: break;
    }
    delay(1);
  }
  Serial.println("Exit time format!");
}

void showTimeFormat() {
  blue1.printRaw(TM1637_CHAR_T, 0);
  blue1.printRaw(TM1637_CHAR_f, 1);
  if (set24) {
    blue1.printRaw(TM1637_CHAR_2, 2);
    blue1.printRaw(TM1637_CHAR_4, 3);
  } else {
    blue1.printRaw(TM1637_CHAR_1, 2);
    blue1.printRaw(TM1637_CHAR_2, 3);
  }
}

void setAlarmState() {
  Serial.println("In alarm state!");
  showAlarmState();
  digitalWrite(RED_LED, HIGH);
  digitalWrite(WHITE_LED, HIGH);
  myDFPlayer.play(10);
  delay(500);
  while (digitalRead(SW) == HIGH) {
    if (myDFPlayer.available()) {
      printDetail(myDFPlayer.readType(), myDFPlayer.read());
    }
    switch (readRotaryEncoder()) {
      case 1:
        setAO = true;
        showAlarmState();
        break;
      case -1:
        setAO = false;
        showAlarmState();
        break;
      default: break;
    }
    delay(1);
  }
  Serial.println("Exit alarm State!");
}

void showAlarmState() {
  blue1.printRaw(TM1637_CHAR_A, 0);
  blue1.printRaw((uint8_t)TM1637_CHAR_SPACE, 1);
  blue1.printRaw(TM1637_CHAR_o, 2);
  blue1.printRaw((setAO) ? TM1637_CHAR_n : TM1637_CHAR_f, 3);
}

void setAlarmHour() {
  Serial.println("In alarm hour!");
  showAlarmHour();
  digitalWrite(RED_LED, HIGH);
  digitalWrite(WHITE_LED, HIGH);
  myDFPlayer.play(1);
  delay(500);
  while (digitalRead(SW) == HIGH) {
    if (myDFPlayer.available()) {
      printDetail(myDFPlayer.readType(), myDFPlayer.read());
    }
    switch (readRotaryEncoder()) {
      case 1:
        setAH = (setAH + 1) % 24;
        showAlarmHour();
        break;
      case -1:
        setAH = (setAH + 23) % 24;
        showAlarmHour();
        break;
      default: break;
    }
    delay(1);
  }
  Serial.println("Exit alarm hour!");
}

void showAlarmHour() {
  uint8_t buffer[2];
  blue1.printRaw(TM1637_CHAR_A, 0);
  blue1.printRaw(TM1637_CHAR_h, 1);
  buffer[0] = blue1.encode(int16_t(setAH / 10));
  buffer[1] = blue1.encode(int16_t(setAH % 10));
  blue1.printRaw(buffer, 2, 2);
}

void setAlarmMinute() {
  Serial.println("In alarm minute!");
  showAlarmMinute();
  digitalWrite(RED_LED, HIGH);
  digitalWrite(WHITE_LED, HIGH);
  myDFPlayer.play(7);
  delay(500);
  while (digitalRead(SW) == HIGH) {
    if (myDFPlayer.available()) {
      printDetail(myDFPlayer.readType(), myDFPlayer.read());
    }
    switch (readRotaryEncoder()) {
      case 1:
        setAM = (setAM + 1) % 60;
        showAlarmMinute();
        break;
      case -1:
        setAM = (setAM + 59) % 60;
        showAlarmMinute();
        break;
      default: break;
    }
    delay(1);
  }
  Serial.println("Exit alarm minute!");
}

void showAlarmMinute() {
  uint8_t buffer[2];
  blue1.printRaw(TM1637_CHAR_A, 0);
  blue1.printRaw(TM1637_CHAR_n, 1);
  buffer[0] = blue1.encode(int16_t(setAM / 10));
  buffer[1] = blue1.encode(int16_t(setAM % 10));
  blue1.printRaw(buffer, 2, 2);
}

void turnOnAlarm() {
  bool playTrack4 = true;                   // Start with track 4
  unsigned long lastBlink = 0;              // For LED blinking
  const unsigned long blinkInterval = 300;  // ms
  bool ledState = false;

  int currentTrack = playTrack4 ? 4 : 5;
  myDFPlayer.play(currentTrack);

  float redBrightness = 0;
  bool fadingUp = true;

  while (digitalRead(SW) == HIGH && !minuteChanged()) {
    // Blink WHITE and BLUE LEDs intermittently
    if (millis() - lastBlink >= blinkInterval) {
      lastBlink = millis();
      ledState = !ledState;
      digitalWrite(WHITE_LED, ledState);
      digitalWrite(BLUE_LED, ledState);
    }

    // Fade RED LED smoothly
    if (fadingUp) {
      redBrightness += 5;
      if (redBrightness >= 255) {
        redBrightness = 255;
        fadingUp = false;
      }
    } else {
      redBrightness -= 5;
      if (redBrightness <= 0) {
        redBrightness = 0;
        fadingUp = true;
      }
    }
    ledcWrite(0, int(redBrightness));  // Update RED LED brightness

    // Process DFPlayer events
    if (myDFPlayer.available()) {
      uint8_t type = myDFPlayer.readType();
      int value = myDFPlayer.read();

      // Only switch track when the current track finishes
      if (type == DFPlayerPlayFinished && value == currentTrack) {
        playTrack4 = !playTrack4;
        currentTrack = playTrack4 ? 4 : 5;
        myDFPlayer.play(currentTrack);  // start next track
      }
    }

    delay(20);  // small delay for smooth fade and CPU time
  }

  // Stop alarm and turn off LEDs
  myDFPlayer.stop();
  digitalWrite(WHITE_LED, LOW);
  digitalWrite(BLUE_LED, LOW);
  ledcWrite(0, 0);  // RED LED off

  // Wait for button release
  while (digitalRead(SW) == LOW) {}
}

bool setupTimer() {
  Serial.println("In Timer State!");
  blue1.printTime(88, 88, false);
  digitalWrite(RED_LED, HIGH);
  digitalWrite(WHITE_LED, HIGH);
  myDFPlayer.play(6);
  delay(1000);
  while (digitalRead(SW) == HIGH) {
    if (myDFPlayer.available()) {
      printDetail(myDFPlayer.readType(), myDFPlayer.read());
    }
    counter += float(readRotaryEncoder() * 10);
    if (counter < 0) {
      counter = 0;
    }
    timer_mins = counter / 60;
    timer_secs = ((counter / 60) - timer_mins) * 60;
    blue1.printTime(timer_mins, timer_secs, false);
    delay(1);
  }
  bool timerNotUsed = (counter == 0);
  if (counter > 0) {
    Countdown(counter);
  }
  Serial.println("Exit Timer State!");
  return timerNotUsed;
}

void Countdown(float timer_counter) {
  myDFPlayer.play(8);
  delay(1000);
  while (digitalRead(SW) == HIGH) {
    if (myDFPlayer.available()) {
      printDetail(myDFPlayer.readType(), myDFPlayer.read());
    }
    for (int i = 10; i > 0; i--) {
      timer_counter = timer_counter - 0.1;
      timer_mins = timer_counter / 60;
      timer_secs = ((timer_counter / 60) - timer_mins) * 60;
      blue1.printTime(timer_mins, timer_secs, false);
      delay(100);
      digitalWrite(RED_LED, LOW);
    }
    if (timer_counter <= 0) {
      playFolderTrackWithLights(3);
      playFolderTrackWithLights(11);
      //playFolderTrackWithLights(5);
      break;
    };
  }
  while (digitalRead(SW) == LOW) {}
  counter = 0;
}

void playFolderTrackWithLights(int track) {
  myDFPlayer.play(track);
  for (int i = 0; i < 9; i++) {
    ledcWrite(0, 255);
    waitMilliseconds(random(10, 150));
    digitalWrite(WHITE_LED, HIGH);
    waitMilliseconds(random(10, 150));
    ledcWrite(0, 0);
    waitMilliseconds(random(10, 150));
    digitalWrite(WHITE_LED, LOW);
    waitMilliseconds(random(10, 150));
  }
}

int readRotaryEncoder() {
  int result = 0;
  currentStateCLK = digitalRead(CLK);
  if (currentStateCLK != lastStateCLK && currentStateCLK == 1) {
    if (digitalRead(DT) != currentStateCLK) {
      result = -1;
      currentDir = "CCW";
    } else {
      result = 1;
      currentDir = "CW";
    }
    Serial.print("Direction: ");
    Serial.print(currentDir);
    Serial.print(" | Counter: ");
    Serial.println(counter);
  }
  lastStateCLK = currentStateCLK;
  return result;
}

void waitMilliseconds(uint16_t msWait) {
  uint32_t start = millis();
  while ((millis() - start) < msWait && digitalRead(SW) == HIGH) {
    if (myDFPlayer.available()) {
      printDetail(myDFPlayer.readType(), myDFPlayer.read());
    }
    delay(1);
  }
}

void writeEepromData() {
  EEPROM.put(EEPROM_ADDRESS, EepromData);
  EEPROM.commit();
}

void readEepromData() {
  EEPROM.get(EEPROM_ADDRESS, EepromData);
#ifndef RESET_EEPROM
  if (EepromData.magic != EEPROM_MAGIC)
#endif
  {
    EepromData.magic = EEPROM_MAGIC;
    EepromData.timeFormat = false;
    EepromData.alarmOn = false;
    EepromData.alarmHour = 6;
    EepromData.alarmMinute = 0;
    writeEepromData();
    EEPROM.commit();
  }
}

if you can get to the "sealed connections, you should be able to use the contact as a switch to pull a digital input high or low.

Then an if-statement to "do something" if the pin goes high or low.

The Input Pullup Example shows you how to enable the internal pull-up which can be "overpowered" with a switch wired to ground. The internal pullup allows you to use a switch without adding an external pull-up or pull-down resistor. But that may not work with the existing LED and resistor, depending on how they are wired. :frowning:

For those of us unfamiliar with pogo connectors, a picture or photo might be helpful, as there appear to be many versions of these.

2 Likes

About the title - I wonder how the connector can activate the file...

AI suggested to have the GND of the ELED circuit connect to the GPIO13 (since almost every other pin I have is used) via a transistor to open the gate and bring either HIGH or LOW to trigger the MP3 file, as listed in the code under “void checkPogoConnector”.
Issues being the file plays upon connection (HIGH>LOW), but the “float” brings the the brightness of the ELED waaaay down. Going another way (LOW>HIGH) lights brightly but only plays the file when disconnected, and that defeats the purpose of the sound of a light saber being activated.

Thank you, sir. I did reprint these files and have access to a 3-pin pogo connector. The issues there are connecting the two grounds or the two VCCs together on the female side (sealed up in the handle of the saber) so that it triggers that third pin to do something to the board or via a transistor/diode/etc... It’s not impossible, but I would have to engineer the connectors in a way to fit all three inside.
The ultimate goal is to have the Saber at full 3.3V brightness when connected to trigger that sound file of the saber lighting up. It’s just a classic scene in the movie and I want this to do justice for that!