Pi Pico code doesn't/work after unplugged

Hello,
I'm programming a MAX7219 8x8 LED matrix on a raspberry pi pico where letters display one after another when a button is pressed. It works perfectly when uploaded onto the pico but when I unplug it and plug it in nothing happens no leds light up at all. I've tried to look at other similar issues online but to no avail.
The following sketch

//MAX7219 - using Led Control library to display 8x8   bitmap
#include <LedControl.h>

int DIN = 28;
int CS = 21;
int CLK   = 20;
int button = 18;
int buttonState = 0;
LedControl lc=LedControl(DIN, CLK, CS,0);
boolean buttonVal = false;

int Cat[8] ={0b10001000,0b11111000,0b10101000,0b01110001,0b00100001,0b01111001,0b01111101,0b10111110};
int Heart [8] = {0b00011000, 0b00111100, 0b01111110, 0b11111111, 0b11111111, 0b11111111, 0b01100110, 0b00000000};
int lLetter [8] = {0b00000000, 0b00111100, 0b00111100, 0b00110000, 0b00110000, 0b00110000, 0b00110000, 0b00000000};
int iLetter [8] = {0b00000000, 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00000000};
int oLetter [8] = {0b00000000, 0b00111100, 0b01111110, 0b01100110, 0b01100110, 0b01111110, 0b00111100, 0b00000000};
int vLetter [8] = {0b00000000, 0b00011000, 0b00111100, 0b01100110, 0b01100110, 0b01100110, 0b01100110, 0b00000000};
int eLetter [8] = {0b00000000, 0b00111100, 0b00110000, 0b00111100, 0b00111100, 0b00110000, 0b00111100, 0b00000000};
int yLetter [8] = {0b00000000, 0b00011000, 0b00011000, 0b00111100, 0b01100110, 0b01100110, 0b01100110, 0b00000000};
int uLetter [8] = {0b00000000, 0b00111100, 0b01111110, 0b01100110, 0b01100110, 0b01100110, 0b01100110, 0b00000000};

void setup() {
  lc.shutdown(0,false);
  lc.setIntensity(0,0);
  lc.clearDisplay(0);
  pinMode(button, INPUT);
}
   
void loop(){
  
  buttonState = digitalRead(button); //reads button
  if (buttonState == LOW) { // if buttons pressed runs this sequence on the matrix
    for(int i=0;i<8;i++) lc.setColumn(0,i,Heart[i]);
    delay(1000);
    //lc.clearDisplay(0); potentially thought these were the issue but works without it... same issue
    for(int i=0;i<8;i++) lc.setColumn(0,i,iLetter[i]);
    delay(1000);
    //lc.clearDisplay(0);
    for(int i=0;i<8;i++) lc.setColumn(0,i,lLetter[i]);
    delay(1000);
    //lc.clearDisplay(0);
    for(int i=0;i<8;i++) lc.setColumn(0,i,oLetter[i]);
    delay(1000);
    //lc.clearDisplay(0);
    for(int i=0;i<8;i++) lc.setColumn(0,i,vLetter[i]);
    delay(1000);
    //lc.clearDisplay(0);
    for(int i=0;i<8;i++) lc.setColumn(0,i,eLetter[i]);
    delay(1000);
    //lc.clearDisplay(0);
    for(int i=0;i<8;i++) lc.setColumn(0,i,yLetter[i]);
    delay(1000);
    //lc.clearDisplay(0);
    for(int i=0;i<8;i++) lc.setColumn(0,i,oLetter[i]);
    delay(1000);
    //lc.clearDisplay(0);
    for(int i=0;i<8;i++) lc.setColumn(0,i,uLetter[i]);
    delay(1000);
    lc.clearDisplay(0);
  }
}

I'm really not sure what could be the issue as I run the Blink example code and it works before and after unplugging and plugging in again.

Is this plugging and unplugging happening while the rest of the circuit is wired up? If so I am not surprised. What I would be surprised at is why you have not permanently damaged anything yet. You probably actually have already, although it hasn't showed up yet.

Yes the rest of the circuit is wired up when I plug in the usb. What did I do wrong exactly?

If what you are doing is unplugging the USB cable between your Pico and PC then plugging it back in, pressing the RESET button should restart the sketch. I can't imagine why it wouldn't but since we can't see where all the wires go nor the Tools/Auto Formatted code in code tags and also any Serial output it's a guess.
You are not new, so you have already read the pinned post re 'How to get the mist from the forum' Why didn't you follow it?

The official Pi Pico doesn't have a reset button. You have to connect pin 30 to ground with a momentary jumper. I find it annoying.

I forgot. Unplugging and pluggin in should also work.
Maybe you are in DFU mode, when plugged in do you see an extra USB drive?
Otherwise ask ChatGPT how to get out of DFU mode and into normal mode.

Exactly you disconnected a lot of pins at once. You can only safely do this if your connections are designed to be what is known as "hot plugable", or "hot swapable"

If the connections are not designed to be like this then the act of plugging in will create, for a very short time, a situation where an unpowered pin is connected to a powered output. This can cause a lot of problems like latch up where very large currents can flow due to parasitic powering through the static protection diodes.

This is why you should never change the components of a powered up circuit. A lesson a lot of beginners learn the hard way. What you are doing is like changing the circuit while powered up on acid!.

This link explains the requirements a hot pluggable device needs:-
Hot plug devices

The resulting damage is not immediately apparent, but will show up as a shortening of life of the components involved :-

Exceeding Limits for current
Undoubtedly they can be pushed, in electronics there is no such thing as a point where below is safe and above will destroy the chip. It is a continuum, there is a point where the chip or wires inside the chip will melt, however before you get to that point you enter the region where the chip deteriorates faster than it otherwise would. Where that point is you can't say because no absolute values are given in the data sheet. This can result in early failure or life shortening. It is just like smoking, damage is being done to you lungs all the time but you don't immediately drop dead, it is just that you don't live as long. Do you know that smokers have a much lower chance of getting Alzheimer's disease, it's not because of any protective effect of smoking but simply smokers tend to die before they can develop it. The same with exceeding recommended values in electronics.

As I explained this is what happens when you hot pug a device not designed to connect and disconnect the power ground and signals in the correct order.

Sorry but I think the others who replied before me are missing this point.

Yes the forum can be a very misty place at times, it is not always immediately transparent :wink:
:rofl:

Sorry but as a dyslexic, I can never resist a spelling error pun when I spot one.