Built in and rx, tx leds

Hi! I uploaded to my mega 2560 the blink example and it made blink the BUILTIN led. But when I tried it slightly the same way it made blink the rx led and the delay function didn't work well.
I mean when I set the led HIGH and made a 1000 delay it didn't waited.
Why is that?

int num = 0;

void blink(int num) {
  int count = 1;
  for( ; ; ) {
    if(count == num) {
      Serial.println("END");
      digitalWrite(LED_BUILTIN, HIGH);
      delay(1000);
      digitalWrite(LED_BUILTIN, LOW);
      break;
    }
    else {
      Serial.println("ON GOING");
      digitalWrite(LED_BUILTIN, HIGH);
      delay(150);
      digitalWrite(LED_BUILTIN, LOW);
      count++;
    }
  }
}
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  blink(5);
}

If you look at a schematic for the Mega 2560, you'll see that while the LED_BUILTIN led is hooked up to the Mega, the Rx and Tx LEDs are not. They are connected to the 16u2.

The delay of 1000 works. Make it 10000 and count the 10 seconds.

@botond500
Are you sure the RX is blinking?
Wouldn't it be TX?
The TX will blink because you use the serial.

2 Likes

If you're talking about that code, try the following:

 for( ; ; ) {
    if(count == num) {
      Serial.println("END");
      digitalWrite(LED_BUILTIN, HIGH);
      delay(1000);
      digitalWrite(LED_BUILTIN, LOW);
      delay(1000);
      break;
    }
    else {
      Serial.println("ON GOING");
      digitalWrite(LED_BUILTIN, HIGH);
      delay(150);
      digitalWrite(LED_BUILTIN, LOW);
      delay(150);
      count++;
    }

​​

​​

I tried it first but it didn't work.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.