pins getting stuck HIGH after some time, then going LOW on their own

I just wrote a simple app that that controls pins 12 and 13 in a loop while a pin is low (connected to ground to save having to have a resistor inline). The code goes as follows:

int buttonState = 0;

// the setup function runs once when you press reset or power the board
void setup() {
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  
  Serial.begin(9600);
      
  // initialize the pushbutton pin as an input:
  pinMode(6, INPUT); 
   
  //initialize the buttonPin as output
  digitalWrite(6, HIGH);   
}

// the loop function runs over and over again forever
void loop() {

  buttonState = digitalRead(6);

  if (buttonState == HIGH) {
    digitalWrite(13, LOW);
    digitalWrite(12, LOW);                                                                                                                                            
  } else {
    for (int i=0; i<8; i++){
      digitalWrite(13, HIGH);
      delay(50);
      digitalWrite(13, LOW);
      delay(50);
      digitalWrite(12, HIGH);
      delay(50);
      digitalWrite(12, LOW);
      delay(50);
    }
    delay(1500);
  }
}

Now, when I power up the nano, it goes through its sequence then goes silent until either I short the ground to pin 6 or until it decides to short itself I'm guessing based on other posts I have read (internal short in the IC). What I cant figure out is why after some time the short vanishes and the ciruit is HIGH again causing the program to stop. In other words, pins 12 and 13 stop triggering my relays.

Could the NANO be fried? I tried this with pin 7 also.

There is not an "internal short"

Do you have a pullup resistor on pin 6? If not, pin 6 is floating and will transition randomly when the button is not pressed, because you are setting it to be INPUT, not INPUT_PULLUP.

Also, are you switching relays on and off 20 times a second? Very few relays are okay with that.

Also, for future reference, you should post questions regarding your project in the appropriate subforum (maybe project guidance when the issue is unclear). This section is for problems with the arduino itself.

Sorry, should I continue this thread on that subforum?

Use "Report to moderator " and request to be moved if you need to continue this thread. If answered don't move as nothing gained.

Weedpharma