Loop getting stuck and not looping

I have an esp32, pn532 NFC, and an i2c oled display.

I have a problem where the button press is not being detected unless I tap the NFC reader. I highly suspect its somehow getting stuck somewhere in void loop. but i have no idea where..

In the loop if i disable checkNfcTag() the button then gets detected

So something in this section of code is causing the loop to get stuck...

any advice appreciated

void checkNfcTag() {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;

  // Wait for an NFC card
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

  if (success) {
    // Display the UID to the serial monitor
    Serial.print("Found an NFC tag with UID: ");
    for (uint8_t i = 0; i < uidLength; i++) {
      Serial.print(uid[i], HEX);
      Serial.print(" ");
    }
    Serial.println();
    nfc.SAMConfig();  // Reinitialize the NFC reader for the next scan

    // Handle the NFC tag event
   // handleNfc();
  }
}

full code below

#include <WiFi.h>
#include <HTTPClient.h>
#include <U8g2lib.h>
#include <Wire.h>
#include <Adafruit_PN532.h>
#include <Adafruit_NeoPixel.h>

// Initialize U8g2 for SH1106 display using I2C
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA);

// PN532 pins
#define PN532_SCK  (18)
#define PN532_MOSI (23)
#define PN532_SS   (5)
#define PN532_MISO (19)

#define PIN 15
#define NUMPIXELS 24
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

// Initialize the PN532 module
Adafruit_PN532 nfc(PN532_SS);

// Wi-Fi credentials
const char* ssid = "wifi2g";      // Your Wi-Fi SSID
const char* password = "qwerty12"; // Your Wi-Fi Password

// URL for retrieving wait times for user1
const char* url = "https://www.magicwaits.com/WebViewer/WaitTime.php?username=user1";

// Button pin
const int buttonPin = 27;
bool buttonPressed = false;  // State to track button press
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 200;  // 200 ms debounce time

unsigned long lastSerialOutputTime = 0;  // Time to track 5-second intervals

// Variables to store ride data
String rideNames[20];  // Array to store ride names
String waitTimes[20];  // Array to store wait times
int totalRides = 0;    // Total number of rides
int currentRideIndex = 0;  // Index for current ride being displayed

// Additional variables for non-ride data
int daysUntilHoliday = 0;
bool clockMode = false;
bool displayHoliday = false;

// 'Untitled', 127x64px (your splash screen image)
const unsigned char epd_bitmap_Untitled[] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0x7f, 0xff, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0xff, 0xfb, 0x3f, 0xff, 0xf1, 0x1f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0xff, 0xf1, 0x3f, 0xfe, 0xf1, 0x07, 0x30, 0xf0, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0xff, 0xf1, 0x1f, 0xfe, 0xe0, 0x03, 0x00, 0x30, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0xff, 0xe1, 0x1f, 0xfe, 0xe0, 0x01, 0x00, 0x10, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0xff, 0xe0, 0x0f, 0x7c, 0xc0, 0x00, 0x00, 0x10, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0xff, 0xc0, 0x07, 0x7c, 0xc0, 0x80, 0x81, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0xff, 0xc0, 0x07, 0x3c, 0x80, 0xe0, 0x73, 0x00, 0xb8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0x7f, 0x80, 0x03, 0x38, 0x00, 0xe0, 0x9b, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0x7f, 0x80, 0x01, 0x18, 0x00, 0x30, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0x7f, 0x00, 0x01, 0x10, 0x00, 0x30, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0x3f, 0x00, 0x00, 0x10, 0x04, 0x30, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0x3f, 0x00, 0x00, 0x00, 0x0e, 0x30, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0x1f, 0x00, 0x20, 0x00, 0x0e, 0xe0, 0x03, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0x1f, 0x08, 0x70, 0x20, 0x02, 0xe0, 0x83, 0x00, 0x38, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0x1f, 0x1c, 0x70, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0x0f, 0x1c, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0x0f, 0x3c, 0xf8, 0x00, 0x00, 0x00, 0x20, 0x10, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0x0f, 0x7c, 0xfc, 0xc0, 0x3f, 0x00, 0x30, 0x30, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0x0f, 0x7e, 0xfe, 0xc0, 0x7f, 0x30, 0x18, 0x70, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0x7f, 0xfe, 0xfe, 0xe5, 0x7f, 0xfc, 0xbf, 0x3f, 0x83, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0x3f, 0x3e, 0xff, 0x07, 0x00, 0x0c, 0xfc, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0xe3, 0xc7, 0x1f, 0x18, 0x3e, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0xc0, 0x87, 0x1f, 0x18, 0x3e, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0xc0, 0x87, 0x0f, 0x08, 0x3c, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0xc1, 0x03, 0x0f, 0x08, 0x3c, 0x10, 0x00, 0x04, 0xfe, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0x81, 0x03, 0x07, 0x04, 0x38, 0x70, 0x00, 0xf4, 0xff, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0x81, 0x01, 0x06, 0x06, 0x38, 0x70, 0x60, 0xf0, 0xff, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0x03, 0x01, 0x02, 0x02, 0x30, 0x70, 0x60, 0xe0, 0xff, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x03, 0x30, 0x70, 0x60, 0x00, 0xfe, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x01, 0x20, 0x70, 0xf0, 0x00, 0xf8, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x80, 0xc1, 0x00, 0x70, 0xf0, 0x01, 0xf0, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0x0f, 0x10, 0x80, 0xc0, 0x40, 0x30, 0xf0, 0x07, 0xf0, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0x0f, 0x30, 0xc0, 0xe0, 0x01, 0x30, 0xf0, 0x3f, 0xe0, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0x1f, 0x38, 0x40, 0x00, 0x00, 0x30, 0xf0, 0x7f, 0xe0, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0x1f, 0x78, 0x20, 0x00, 0x00, 0x30, 0xf0, 0x7d, 0xe0, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0x1f, 0x7c, 0x20, 0x00, 0x00, 0x31, 0xf0, 0x00, 0xf0, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0x3f, 0xfc, 0x10, 0x00, 0x00, 0x10, 0xf0, 0x00, 0xf0, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0x3f, 0xfe, 0x10, 0xf0, 0x07, 0x10, 0x70, 0x00, 0xf0, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0x19, 0xf8, 0x07, 0x12, 0x70, 0x00, 0xf8, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0x79, 0xfc, 0x8f, 0xff, 0xf8, 0x01, 0xfe, 0xff, 0xff, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x7f, 0xfe, 0xcf, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x80, 0x01, 0x7e, 0xfe, 0xcf, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x80, 0x00, 0x78, 0xfc, 0x87, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x30, 0xfc, 0x83, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x20, 0xf8, 0x83, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x20, 0xf8, 0x01, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x2e, 0x78, 0x00, 0xf0, 0x00, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81, 0x1f, 0xfc, 0x00, 0xe0, 0x00, 0x7e, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81, 0x0f, 0xfc, 0x00, 0x60, 0x00, 0x7e, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x0f, 0xfc, 0x01, 0x00, 0x00, 0x7e, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x0f, 0xfc, 0x01, 0x00, 0x00, 0x7c, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x7c, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x87, 0x81, 0x7f, 0xf8, 0x00, 0x00, 0x08, 0x7c, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x01, 0x8e, 0x00, 0x20, 0x03, 0x0c, 0x78, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x01, 0x00, 0x01, 0x20, 0x07, 0x1c, 0x78, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x03, 0x00, 0x02, 0x00, 0x07, 0x1e, 0x78, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x07, 0x00, 0x02, 0x08, 0x0f, 0x1f, 0x70, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x0f, 0x00, 0x01, 0x84, 0x0f, 0x3f, 0x70, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x87, 0x1f, 0x80, 0x8f, 0x83, 0x9f, 0x3f, 0x78, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0x9f, 0x9f, 0x3f, 0x7f, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f

};

// Function to display the bitmap image
void displayImage() {
  u8g2.clearBuffer();
  u8g2.drawXBMP(0, 0, 127, 64, epd_bitmap_Untitled);  // Draw the bitmap
  u8g2.sendBuffer();
}

void setup() {
  // Initialize serial, OLED display, and PN532
  Serial.begin(115200);
  u8g2.begin();
  pinMode(buttonPin, INPUT_PULLUP);
  // Initialize the PN532
  nfc.begin();
  uint32_t versiondata = nfc.getFirmwareVersion();
  if (!versiondata) {
    Serial.println("Didn't find PN53x module");
    while (1);
  }
  
  // Configure PN532 to read MiFare cards
  nfc.SAMConfig();

  // Initialize the button pin
  pinMode(buttonPin, INPUT_PULLUP);

  // Start connecting to Wi-Fi
  WiFi.begin(ssid, password);

  // Display the splash screen while connecting to Wi-Fi
  unsigned long startTime = millis();
  while (millis() - startTime < 10000) {  // Display splash for 10 seconds
    displayImage();  // Continuously display the splash screen
    delay(100);  // Short delay to avoid overloading the loop
  }

  // Wait for Wi-Fi connection (if not connected yet)
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("Connected to Wi-Fi");

  // Fetch and display data after the splash screen
  fetchDataAndStoreRides();
  displayRide(currentRideIndex);
}


void loop() {
  // 1. Check the button state first to ensure it works independently of NFC
  checkButtonPress();

  // 2. Only scan for NFC tag if button is not pressed
  if (!buttonPressed) {
    static unsigned long lastNfcCheck = 0;
    if (millis() - lastNfcCheck >= 500) {  // NFC check every 500ms
      lastNfcCheck = millis();
      //checkNfcTag();
    }
  }

  // 3. Periodically update the display (e.g., fetching data every 2 seconds)
  static unsigned long lastDisplayUpdate = 0;
  if (millis() - lastDisplayUpdate >= 2000) {
    lastDisplayUpdate = millis();
    displayRide(currentRideIndex);  // Update the OLED display periodically
  }
}

// Non-blocking button press check with debounce
void checkButtonPress() {
  int buttonState = digitalRead(buttonPin);  // Read button state

  if (buttonState == LOW && !buttonPressed && (millis() - lastDebounceTime > debounceDelay)) {
    buttonPressed = true;  // Mark button as pressed
    lastDebounceTime = millis();  // Reset debounce timer
    Serial.println("Button Press Detected");

    // Action when button is pressed
    cycleRides();
  }

  if (buttonState == HIGH) {
    buttonPressed = false;  // Reset button press state when released
  }
}

// Non-blocking NFC tag detection with timeout to prevent blocking
void checkNfcTag() {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the UID
  uint8_t uidLength;

  // Use a timeout to ensure NFC polling doesn't block other tasks
  uint32_t nfcTimeout = millis() + 50;  // NFC timeout of 50ms

  while (millis() < nfcTimeout) {
    // Attempt to detect an NFC tag (this should not block)
    success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

    if (success) {
      // NFC tag detected, print UID and handle the event
      Serial.print("Found an NFC tag with UID: ");
      for (uint8_t i = 0; i < uidLength; i++) {
        Serial.print(uid[i], HEX);
        Serial.print(" ");
      }
      Serial.println();
      nfc.SAMConfig();  // Reinitialize the NFC reader for the next scan

      // Handle the NFC tag event
      handleNfc();
      break;  // Exit after successfully detecting a tag
    }
  }
}

// Handle NFC actions
void handleNfc() {
  // Place NFC-related actions here
  Serial.println("NFC DETECTED");
  disney();
  disneyaccess();
  delay(2000);
  disneyoff();
}



void fetchDataAndStoreRides() {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    http.begin(url);
    int httpResponseCode = http.GET();

    if (httpResponseCode == 200) {
      String payload = http.getString();
      Serial.println("Full Payload: " + payload);  // Output full payload for debugging

      // Split the payload by commas
      int lastCommaIndex = 0;
      int currentCommaIndex = 0;
      String parsedData[20];  // Array to store split data (increase size if needed)
      int elementCount = 0;

      while ((currentCommaIndex = payload.indexOf(',', lastCommaIndex)) != -1) {
        parsedData[elementCount++] = payload.substring(lastCommaIndex, currentCommaIndex);
        lastCommaIndex = currentCommaIndex + 1;
      }
      parsedData[elementCount++] = payload.substring(lastCommaIndex);  // Add last part

      // Parse the non-ride data (first 6 elements)
      daysUntilHoliday = parsedData[0].toInt();
      clockMode = parsedData[1].toInt() == 1;
      displayHoliday = parsedData[2].toInt() == 1;
      String timeZone = parsedData[3];
      String holidayDate = parsedData[5];

      // Process the rides data (starting from element 6)
      totalRides = 0;  // Reset total rides count
      for (int i = 6; i < elementCount; i++) {
        String rideData = parsedData[i];
        int colonIndex = rideData.indexOf(':');
        rideNames[totalRides] = rideData.substring(0, colonIndex);
        waitTimes[totalRides] = rideData.substring(colonIndex + 1);
        totalRides++;
      }
    } else {
      Serial.println("Error on HTTP request");
    }
    http.end();
  }
}
// Function to cycle through the rides
void cycleRides() {
  currentRideIndex = (currentRideIndex + 1) % totalRides;  // Increment the index and wrap around
  displayRide(currentRideIndex);  // Update the OLED display with the next ride
}


void disney(){
  Serial.print("Disney");
  pixels.setPixelColor(23, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(23, pixels.Color(0,0,0));
  pixels.setPixelColor(22, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(22, pixels.Color(0,0,0));
  pixels.setPixelColor(21, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(21, pixels.Color(0,0,0));
  pixels.setPixelColor(20, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(20, pixels.Color(0,0,0));
  pixels.setPixelColor(19, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(19, pixels.Color(0,0,0));
  pixels.setPixelColor(18, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(18, pixels.Color(0,0,0));
  pixels.setPixelColor(17, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(17, pixels.Color(0,0,0));
  pixels.setPixelColor(16, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(16, pixels.Color(0,0,0));
  pixels.setPixelColor(15, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(15, pixels.Color(0,0,0));
  pixels.setPixelColor(14, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(14, pixels.Color(0,0,0));
  pixels.setPixelColor(13, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(13, pixels.Color(0,0,0));
  pixels.setPixelColor(12, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(12, pixels.Color(0,0,0));
  pixels.setPixelColor(11, pixels.Color(0,25,0));
  pixels.show();
  delay(50); 
  pixels.setPixelColor(11, pixels.Color(0,0,0));
  pixels.setPixelColor(10, pixels.Color(0,25,0));
  pixels.show();
  delay(50); 
  pixels.setPixelColor(10, pixels.Color(0,0,0));
  pixels.setPixelColor(9, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(9, pixels.Color(0,0,0));
  pixels.setPixelColor(8, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(8, pixels.Color(0,0,0));
  pixels.setPixelColor(7, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(7, pixels.Color(0,0,0));
  pixels.setPixelColor(6, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(6, pixels.Color(0,0,0));
  pixels.setPixelColor(5, pixels.Color(0,25,0));
  pixels.show();
  delay(50);  
  pixels.setPixelColor(5, pixels.Color(0,0,0));
  pixels.setPixelColor(4, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(4, pixels.Color(0,0,0));
  pixels.setPixelColor(3, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(3, pixels.Color(0,0,0));
  pixels.setPixelColor(2, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(2, pixels.Color(0,0,0));
  pixels.setPixelColor(1, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(1, pixels.Color(0,0,0));
  pixels.setPixelColor(0, pixels.Color(0,25,0));
  pixels.show();
  delay(50);
  pixels.setPixelColor(0, pixels.Color(0,0,0));
  pixels.show();
  delay(50);
}



void disneyaccess()
{
//  player.play(1); 
  Serial.print("Disney access");
 pixels.setPixelColor(0, pixels.Color(0,25,0));
 pixels.setPixelColor(1, pixels.Color(0,25,0));
 pixels.setPixelColor(2, pixels.Color(0,25,0));
 pixels.setPixelColor(3, pixels.Color(0,25,0));
 pixels.setPixelColor(4, pixels.Color(0,25,0));
 pixels.setPixelColor(5, pixels.Color(0,25,0));
 pixels.setPixelColor(6, pixels.Color(0,25,0));
 pixels.setPixelColor(7, pixels.Color(0,25,0));
 pixels.setPixelColor(8, pixels.Color(0,25,0));
 pixels.setPixelColor(9, pixels.Color(0,25,0));
 pixels.setPixelColor(10, pixels.Color(0,25,0));
 pixels.setPixelColor(11, pixels.Color(0,25,0));
 pixels.setPixelColor(12, pixels.Color(0,25,0));
 pixels.setPixelColor(13, pixels.Color(0,25,0));
 pixels.setPixelColor(14, pixels.Color(0,25,0));
 pixels.setPixelColor(15, pixels.Color(0,25,0));
 pixels.setPixelColor(16, pixels.Color(0,25,0));
 pixels.setPixelColor(17, pixels.Color(0,25,0));
 pixels.setPixelColor(18, pixels.Color(0,25,0));
 pixels.setPixelColor(19, pixels.Color(0,25,0));
 pixels.setPixelColor(20, pixels.Color(0,25,0));
 pixels.setPixelColor(21, pixels.Color(0,25,0));
 pixels.setPixelColor(22, pixels.Color(0,25,0));
 pixels.setPixelColor(23, pixels.Color(0,25,0));
 pixels.show();
 delay(2000);
    disneyoff();
 

//  if(digitalRead(relay) == HIGH)
//     {
//    digitalWrite(relay,LOW);
//    Serial.println("Relay off"); 
//    }
//    else
//    {
//    digitalWrite(relay,HIGH);
//    Serial.println("Relay on"); 
//    }


}

void disneyoff()
{
    Serial.print("Disney off");
pixels.setPixelColor(0, pixels.Color(0,0,0));
 pixels.setPixelColor(1, pixels.Color(0,0,0));
 pixels.setPixelColor(2, pixels.Color(0,0,0));
 pixels.setPixelColor(3, pixels.Color(0,0,0));
 pixels.setPixelColor(4, pixels.Color(0,0,0));
 pixels.setPixelColor(5, pixels.Color(0,0,0));
 pixels.setPixelColor(6, pixels.Color(0,0,0));
 pixels.setPixelColor(7, pixels.Color(0,0,0));
 pixels.setPixelColor(8, pixels.Color(0,0,0));
 pixels.setPixelColor(9, pixels.Color(0,0,0));
 pixels.setPixelColor(10, pixels.Color(0,0,0));
 pixels.setPixelColor(11, pixels.Color(0,0,0));
 pixels.setPixelColor(12, pixels.Color(0,0,0));
 pixels.setPixelColor(13, pixels.Color(0,0,0));
 pixels.setPixelColor(14, pixels.Color(0,0,0));
 pixels.setPixelColor(15, pixels.Color(0,0,0));
 pixels.setPixelColor(16, pixels.Color(0,0,0));
 pixels.setPixelColor(17, pixels.Color(0,0,0));
 pixels.setPixelColor(18, pixels.Color(0,0,0));
 pixels.setPixelColor(19, pixels.Color(0,0,0));
 pixels.setPixelColor(20, pixels.Color(0,0,0));
 pixels.setPixelColor(21, pixels.Color(0,0,0));
 pixels.setPixelColor(22, pixels.Color(0,0,0));
 pixels.setPixelColor(23, pixels.Color(0,0,0));
 pixels.show();

}

void displayRide(int rideIndex) {
  String rideName = rideNames[rideIndex];
  String waitTime = waitTimes[rideIndex];

  // Clear the display buffer
  u8g2.clearBuffer();

  // Split the ride name into two lines
  int midPoint = rideName.length() / 2;
  String line1 = rideName.substring(0, midPoint);
  String line2 = rideName.substring(midPoint);

  // Set the font and display the first part of the ride name
  u8g2.setFont(u8g2_font_ncenB08_tr);  // Choose font
  int rideWidth1 = u8g2.getStrWidth(line1.c_str());
  int rideWidth2 = u8g2.getStrWidth(line2.c_str());
  u8g2.drawStr((128 - rideWidth1) / 2, 16, line1.c_str());  // Center the first line
  u8g2.drawStr((128 - rideWidth2) / 2, 32, line2.c_str());  // Center the second line

  // Display the wait time below the ride name, centered
  int waitTimeWidth = u8g2.getStrWidth(waitTime.c_str());
  u8g2.drawStr((128 - waitTimeWidth) / 2, 48, waitTime.c_str());  // Center the wait time

  // Display the "Disney in X days!" at the bottom, centered
  if (displayHoliday) {
    String holidayText = "Disney in " + String(daysUntilHoliday) + " days!";
    int holidayWidth = u8g2.getStrWidth(holidayText.c_str());
    u8g2.setFont(u8g2_font_6x10_tf);  // Smaller font for holiday text
    u8g2.drawStr((128 - holidayWidth) / 2, 64, holidayText.c_str());  // Center and display at the bottom
  }

  // Send all data to the display
  u8g2.sendBuffer();
}

Sounds like your button press logic is flawed. Maybe use a library of proven code?

sorry in what way. are you able to give me some more detail? im kinda stumbling through all of this

Button code seems easy, but it is not. I would concentrate on that by sticking in Serialprintln in a few places to see if what is happening is what you expected. OR use a library, there are probably hundreds.

Think about this line. And the comment. Does that sound like non blocking code to you?

thankyou very much.

so i made the below change and its now working... mostly.

I find i need to press the button a couple of times or press and hold to make it work. so i think the nfc is still tripping it up a little. is there a better way of doing this?

void checkNfcTag() {
  Serial.println("Checking for NFC card...");

  // Check if there is an NFC card in range
  uint8_t success = nfc.inListPassiveTarget();

  if (success) {
    Serial.println("NFC card detected!");

    // If a card is detected, retrieve the UID
    uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the UID
    uint8_t uidLength;

    // Try to read the UID of the card
    success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

    if (success) {
      Serial.print("UID Length: ");
      Serial.print(uidLength, DEC);
      Serial.println(" bytes");

      Serial.print("UID Value: ");
      for (uint8_t i = 0; i < uidLength; i++) {
        Serial.print(" 0x");
        Serial.print(uid[i], HEX);
      }
      Serial.println("");

      delay(1000);
    } else {
      Serial.println("Error reading UID");
    }
  } else {
    Serial.println("No NFC card detected");
  }
}

Add up all the delay(...) calls in your various disney functions. Your button will not be detected until all those delays are finished.

cant be them can it? they only get called on successful card read. or should be anyway.

the button being slow is when no card is being used

Did you mention that the button was slow only when no card was being used? Then how was anyone to know that?

apologies

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.