I am working on an inverted pendulum project and have gotten all of my electronics connected and working with the Teensy 4.1 EXCEPT (surprisingly) a simple limit switch. It is a CYT1073 micro limit switch (Link: https://a.co/d/2MxWryM). I tried to get it to work with all my other electronics connected to the Teensy but it wasn't working so I disconnected everything and left only the teensy itself and the limit switch. I have the limit switch COM connected to ground and NC connected to a digital pin (I have tried many pins and all didn't work). I have also tried INPUT, INPUT_PULLUP, and INPUT_PULLDOWN within my code (attached). I have also tried using a 10K ohm pullup resistor. NONE of it worked. When I test the same exact configuration on my Arduino UNO it works, but not on the Teensy. The crazy thing is that I've used this same exact limit switch with a different Teensy 4.1 with the same exact code and configuration and it worked just as I expected. And yes, I've tried using another CYT1073 limit switch thinking it was maybe faulty but it still did not work. Help would be VERY much appreciated. Also, if it helps, I have attached my very simple wiring diagram.
Code:
#include <Arduino.h>
int limitswitch = 6;
void setup() {
Serial.begin(9600);
pinMode(limitswitch, INPUT_PULLUP);
}
void loop() {
int val = digitalRead(limitswitch);
Serial.println(val);
}