I keep breaking my Leonardo

Hi my first post. just trying to make a simple code for my Leonardo.

I'm trying the read button pushs for digital pin 0,1,2,3,4 and have them read back from the serial monitor.

I have the current resistor installed on the switches and set to pull down.

Now I cannot even upload a blinky sketch to the leonardo after I have uploaded my code it was working with blinky and a number of test sketches before I sent my death code.

what have I done? this is second leonardo that this has happened to.

Is it possible to do a complete reset of the board? without having to get another?

This is the code I uploaded

int nbts = 5;
int startpin = 0;
int bts[5];
boolean bgts [5];

void setup() {
Serial.begin(9600);
for (int i = 0; i, nbts; i++)bts = i + startpin ;
_ for (int i = 0; i, nbts; i++) bgts = false;_
}
void loop() {
* // put your main code here, to run repeatedly:*
* for (int i = 0; i < nbts; i++) {*
_ if (!bgts*) {
if (digitalRead( bts == LOW )) {
Serial.print("bt:" + String(i) + ":");
Serial.println(1);
bgts = true;
}
}
else {
if (digitalRead (bgts == HIGH )) {
Serial.print("bt:" + String(i) + ":");
Serial.println(0);
bgts = false;
}
}
}
delay(100);
}*_

Is this the same one? https://www.arduino.cc/en/Main/Arduino_BoardLeonardo

I took a look at the specs and it says that the max current for the 3.3v pin is 50mA. 50mA is a pretty low limit. Are you using resistors?Throw some 1k ohm resistors on them thangs homie.

It is a clone leonardo buttons have been working on example sketches in the ide with only single button reads. The sketch was trying to read multiple buttons.

MathewBrennan:

int nbts = 5;

int startpin = 0;
int bts[5];
boolean bgts [5];

void setup() {
  Serial.begin(9600);
  for (int i = 0; i, nbts; i++)bts [i] = i + startpin ;
  for (int i = 0; i, nbts; i++) bgts[i] = false;

}

void loop() {
  // put your main code here, to run repeatedly:
  for (int i = 0; i < nbts; i++) {
    if (!bgts[i]) {
      if (digitalRead( bts[i] == LOW )) {
        Serial.print("bt:" + String(i) + ":");
        Serial.println(1);
        bgts[i] = true;
      }
    }
    else {
      if (digitalRead (bgts[i] == HIGH )) {
        Serial.print("bt:" + String(i) + ":");
        Serial.println(0);
        bgts[i] = false;

}
    }
  }
  delay(100);
}

Problem is the test in your for loops. You probably meant i < nbts. Instead you have a comma - outside the context of separating arguments to a function, that's the comma operator - x,y = y. So i,nbts will be nbts, which is 5, which is true, so the test will always be true. So it will sit in the first for loop, incrementing i and writing off the end of the bts array.

writing off the end of an array will crash the microcontroller (c has no bounds checking, so once you pass the end of the array, you're scribbling over memory that isn't part of the bts array), so it will no longer be able to service USB requests, so the computer can't tell it to reset into the bootloader to upload a new sketch.

You'll notice that after plugging it in, or pressing the reset button, it will briefly be accessible. Supposedly if you double-tap reset, it will stay in the bootloader (but other people say this doesn't work), and you can then upload a clean sketch. Otherwise, if you hold down reset while trying to upload, and release reset right as it says the size of the compiled sketch, you'll be able to catch it while it's running the bootloader right after reset (before your bad sketch has started running), and upload a clean sketch to it.

(if you have another Arduino, or an ISP programmer, you can also use that to re-bootload the leonardo, which will also fix the issue)

This is the problem with chips that have native USB - you get to make them pretend to be a keyboard or mouse, which is cool and all, but if you upload a sketch that's broken enough that it hoses the USB functionality, it's annoying to get it to work again.

Use code tags </> button, not quote, to put your sketch - as you can see in your original post, the forums parsed the

[i]

as the start of italics tag.

Is this correct?

int nbts = 5;
int startpin = 0;
int bts[5];
boolean bgts [5];

void setup() {
Serial.begin(9600);
for (int i = 0; i, nbts; i++)bts = i + startpin ;
_ for (int i = 0; i, nbts; i++) bgts = false;_
}
void loop() {
* // put your main code here, to run repeatedly:*
* for (int i = 0; i < nbts i++) {*
_ if (!bgts*) {
if (digitalRead( bts == LOW )) {
Serial.print("bt:" + String(i) + ":");
Serial.println(1);
bgts = true;
}
}
else {
if (digitalRead (bgts == HIGH )) {
Serial.print("bt:" + String(i) + ":");
Serial.println(0);
bgts = false;
}
}
}
delay(100);
}*

it would compile as it said this
exit status 1
expected ';' before 'i'_

As DrAzzy already requested, please use code tags when you post code or warning/error messages. To do this, click the </> button on the forum toolbar, then paste the text you want to be in the code tags. Finally, move the cursor out of the code tags before adding any additional text you don't want to be in the code tags. If your browser doesn't show the posting toolbar, then you can manually add the code tags like this:
[code]``[color=blue]// your code is here[/color]``[/code]

The reason for doing this is that, without code tags, the forum software can interpret parts of your code as markup (the italics in your code above, for example), leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier for us to read your code and to copy it to the IDE or editor.

Using code tags and other important information is explained in the "How to use this forum" post. Please read it.

 Serial.begin(9600);
  for (int i = 0; i, nbts; i++)bts [i] = i + startpin ;
  for (int i = 0; i, nbts; i++) bgts[i] = false;

}

void loop() {
  // put your main code here, to run repeatedly:
  for (int i = 0; i < nbts;  i++) {
    if (!bgts[i]) {
      if (digitalRead( bts[i] == LOW )) {
        Serial.print("bt:" + String(i) + ":");
        Serial.println(1);
        bgts[i] = true;
      }
    }
    else {
      if (digitalRead (bgts[i] == HIGH )) {
        Serial.print("bt:" + String(i) + ":");
        Serial.println(0);
        bgts[i] = false;

      }
    }
  }
  delay(100);
}

is this correct sorry learner driver here, also the double click reset fixed the issue with coms

No. You still have the problem in the for loops in your setup(). Please take some time to study the documentation of for and learn to use it properly:

It's a good idea to write a simple sketch to verify you understand the concept. Something that prints the numbers 0 through 10 to the Serial Monitor would work.