weird buggy code problem

This function works fine, as long as the if statement in the middle is commented out. If I uncomment it the code breaks. It's such a simple piece that I don't know if I'm not looking at it closely enough or if there's a bug involved. Does anyone else see what I'm missing?

The code in its entirety (sp?) is here:
http://grace.evergreen.edu/~hergab13/metro_counter.cpp

(If anyone has comments/critiques on my code in general I'm listening. This style of programming is completely new to me)

Gabe

// blink the metro light at the rate specified
void metroBlink() {
if (millis() - previousMillisBlink > tempo) {
previousMillisBlink = millis(); // remember the last time we blinked the LED

// events to be triggered
counter++;
//Serial.println(counter);
/* if (counter > counterMax) {
counter = counterMin;
eventDebounceCounter = true;
}*/

// blink led at specified interval w/o delay()
digitalWrite(ledPinClock, HIGH); //blink red led on

// secondary delay
} else if (millis() - previousMillisBlink > 100) { //100 ms flash on time
//events
digitalWrite(ledPinClock, LOW); //blink red led off
}
}

What is the function supposed to do? When when you uncomment the if-statement, what does it do (i.e. what do you mean by "breaks")?

The function is a blinking metronome. When working properly it turns a led on every [tempo] ms, and off again after 100 ms. (see http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay) The commented-out code is trying to add a counter to the metronome (I'm working towards a simple midi sequencer).

Every time the first if statement allows the processor to get to the code inside, where the blink is, the counter increments. The simple if statement after it is just to keep the counter within a specific range.

So this is the part where it breaks:
When I uncomment the if statement, the code never gets to the blink (digitalWrite(ledPinClock, HIGH):wink: that follows the if! It just stops executing somehow! This makes no sense!

To me it sounds like a bug in the hardware or compiler. Or, like I said above, something so obvious that I can't see it.

Gabe

Figgered it out!

I had a function that wasn't called anywhere. I commented it and its function declaration out and the whole thing came back to life.

Believe it or not I've tripped over that one already.

So:

Don't leave unused functions in your code!

Can someone offer a suggestion as to why this breaks code?

Gabe

It's possible that the code is too big for the Arduino board - what size gets printed when you upload your sketch? Unfortunately, we don't get error messages when this happens. Arduino 0004 has a check if the sketch is too big, but it assumes the most recent bootloader version (which is 1 KB). If you have an older (2 KB) version of the bootloader, the environment might not realize that the code is too big, attempt to upload it, and not realize that it failed.

When did you get your board? If it's an old version, and you have access to an AVR-ISP or parallel port programmer, you might try burning the latest version of the bootloader (using the Tools | Burn Bootloader option). Otherwise, you can tell the Arduino environment the amount of space available for sketches by editing the upload.maximum_size variable in your preferences file (see: Arduino - Home for instructions on finding the file). Change 7168 to 6144, and the environment should correctly warn you when your sketch is too big.

I've only had my arduino for a month or so, and the size of my code is 616X, so unfortunately I don't think that's related to my problem.

Gabe

Can you post a copy of the broken code somewhere so I can try to figure out the problem? Or, if it's the same as the code you posted earlier, which function did you need to comment out for it to start working?