Search code examples
arduinoatmega

Problems with simplest Arduino program


Today I started what is supposed to become a great Arduino career, but I'm already stumped. I may be going crazy, but shouldn't this code blink the LED on the Mega 2560?

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

unsigned int count = 0; 

void loop() {
  if(count%2) digitalWrite(LED_BUILTIN, LOW);
  else digitalWrite(LED_BUILTIN, HIGH);
  delay(1);
  count++;
}

I know this is not elegant for a blinking LED, but this is a stripped down example for something else, where I need a counter and modulo operations on it. The 'Blink' program works, but this here doesn't.


Solution

  • delay()'s argument is measured in milliseconds (not seconds), so you probably want 1000 rather than 1 to observe the blinking!

      delay(1000);
    

    Official Documentation