did i break my arduino?

So I tested a circuit to use 5 buttons to trigger 5 different tones to be outputed by a piezo. worked great!

Soldered it up to make a home-made shield and I made a mistake. One pole of the switch was supposed to be wired to an Arduino pin and have a 10k resistor pulling down to ground. I swapped that wire on ALL the switches so instead I ran 5v to the same side of the switch that had the pull down resistor. Essentially shorting the circuit with only a 10k resistor slowing it down (x5 switches). Of course I had it plugged in several times while I tried to debug it thinking I had a solder short circuit.

After I found the problem I took my homemade shield off and set up a blinking led circuit to test each of the pin that could have been affected. They all worked fine. Any other simple sketch is working fine.

So now I am working on learning about "millis()" to try and make a Morse interpretation program. This is what I have so far. I know its not quality, yet.

 int keyPin = 8;
int ledPin = 10;
int startTime = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(keyPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop()
{
   
  if (digitalRead(keyPin) == HIGH ) 
  {
    startTime = millis();
    delay (10);
      if ((millis() - startTime > 500))
       {
        Serial.println("dash");
        digitalWrite(ledPin, HIGH);
       }
  }
  
  else if (digitalRead(keyPin) == LOW) 
  {
        Serial.println("waiting");
        digitalWrite(ledPin, LOW);
        delay(500);    
  }
 
}

The sketch works, but only after about 1 minute of waiting. I fire it up and it is slow as hell and I wait and then, WHAM! it starts working fine, after what I feel is a too long of a wait.

Is my Sketch flawed and causing the delay or did I mess something up on the board with the short?
Is there a diagnostic program I can run?

Change startTime to unsigned long, which is what millis() returns.

    startTime = millis();
    delay (10);
      if ((millis() - startTime > 500))    /// millis() - startTime will always be very close to 10 and therefore not > 500
       {
       }

So it sounds like my board is fine its just my code that flawed. Great!

I will change int to unsigned long

I borrowed this section of code from a similar sketch i was reading. If millis is the time the sketch has been running how come it will always be close to 10?

johnwasser:

    startTime = millis();

delay (10);
      if ((millis() - startTime > 500))    /// millis() - startTime will always be very close to 10 and therefore not > 500
       {
       }

Super-Nathan:
So it sounds like my board is fine its just my code that flawed. Great!

I will change int to unsigned long

I borrowed this section of code from a similar sketch i was reading. If millis is the time the sketch has been running how come it will always be close to 10?

johnwasser:

    startTime = millis();

delay (10);
      if ((millis() - startTime > 500))    /// millis() - startTime will always be very close to 10 and therefore not > 500
       {
       }

I would say your board is fine ... As already indicated, your timer logic is flawed.
The problem:

    startTime = millis();                // You save the Time ... (THIS is in the wrong place)
    delay (10);                            // You wait 10 millis
    if ((millis() - startTime > 500)) // then you compare against the saved time 10 millis previously ... It will be 10 millis or very close as stated.
       {
       }

I suspect this is more along the lines of your desires.

unsigned long ulLastRefreshTime = 0;
unsigned int iRefreshRate = 500;

  if (millis() - ulLastRefreshTime > iRefreshRate) {
    ulLastRefreshTime = millis();
    // Do  your thing ...
  }

And lose the delay, if at all possible delay() should be avoided, design your code just to loop and do nothing unless it's time (or by count) to do your thing.

-Enjoy
fh : )_~