Can not upload sketch, can someone check my code

everything worked fine for the first time i uploaded the code on friday, i tried to make some small changes to the code on saturday, just to find out he board want respond to uploading on a code.
not sure if it’s a problem with my code or the board itself, can someone please check this pretty basic code?
as for the button box i build, everything works!?!?! even if i connect the board to the pc it’ll be recognized as a keyboard and it will work without any problems!

#include <Keypad.h>
#include <Keyboard.h>

const byte ROWS = 5; // Four rows
const byte COLS = 5; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3','4','5'},
  {'6','7','8','9','0'},
  {'a','b','c','d','e'},
  {'f','g','h','i','j'},
  {'k','l','m','n','o'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 2, 3, 4, 5, 6 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 8, 9, 10, 11, 12 }; 

// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
    Serial.begin(9600);
    Keyboard.begin();
  
}

void loop()
{
  char key = kpd.getKey();
  if(key)  // Check for a valid key.
  {
    switch (key)
    {
      case '1':
        Keyboard.press('1');
        delay(100);
        Keyboard.releaseAll();
        break;
      
      case '2':
        Keyboard.press('2');
        delay(100);
        Keyboard.releaseAll();
        break;
       
      case '3':
        Keyboard.press('3');
        delay(100);
        Keyboard.releaseAll();
        break;
      
      case '4':
        Keyboard.press('4');
        delay(100);
        Keyboard.releaseAll();
        break;
       
      case '5':
        Keyboard.press('5');
        delay(100);
        Keyboard.releaseAll();
        break;
      
      case '6':
        Keyboard.press('6');
        delay(100);
        Keyboard.releaseAll();
        break;
      
      case '7':
        Keyboard.press('7');
        delay(100);
        Keyboard.releaseAll();
        break;
        
      case '8':
        Keyboard.press('8');
        delay(100);
        Keyboard.releaseAll();
        break;
      
      case '9':
        Keyboard.press('9');
        delay(100);
        Keyboard.releaseAll();
        break;
        
      case '0':
        Keyboard.press('0');
        delay(100);
        Keyboard.releaseAll();
        break;
        
      case 'a':
        Keyboard.press('a');
        delay(100);
        Keyboard.releaseAll();
        break;
        
      case 'b':
        Keyboard.press('b');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'c':
        Keyboard.press('c');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'd':
        Keyboard.press('d');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'e':
        Keyboard.press('e');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'f':
        Keyboard.press('f');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'g':
        Keyboard.press('g');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'h':
        Keyboard.press('h');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'i':
        Keyboard.press('i');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'j':
        Keyboard.press('j');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'k':
        Keyboard.press('k');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'l':
        Keyboard.press('l');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'm':
        Keyboard.press('m');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'n':
        Keyboard.press('n');
        delay(100);
        Keyboard.releaseAll();
        break;

        case 'o':
        Keyboard.press('o');
        delay(100);
        Keyboard.releaseAll();
        break;

        
        default:
        Serial.println(key);
    }
  }
}

When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here using code tags.

thx, i'll do later.....but as far as i remember it was unable to connect to com port, because it is busy (IIRC)

btw this code is only sending one keystroke (which is good for most of my buttons), but how to get a button hold function in there? millis?

You can’t upload any code while running keyboard emulation. Reset the Arduino using the reset button, right before uploading. This should launch the bootloader, giving you around 8 seconds to upload.

Pieter

just what i thought :frowning:

should i have insert keyboard.end at the bottom of the sketch?

i`m quiet confused with this keyboard.begin, .end statements.

No, if you reset it before uploading, it should be fine.

already tried to do the trick with the reset button hold and plug in the board and then upload the bareminimum sketch...but it doesn't work......is there a trick on how to or when u should press release the reset button.

i was just thinking about if it's possible to program a button to sent keyboard.end and stop the keyboard emulation!?!?

Press the reset button, release it: Arduino enters bootloader. New COM port shows up, select it in the tools > port menu (you have about 8 seconds). Then compile, press reset again, and upload.

Pieter

it always uses com port 10 no matter how often i press the reset button, but i'll try it later again! thx PieterP