0

I am trying to store data in ATmega328 (Arduino Uno) using the following code using tinkercad:

#include <EEPROM.h>

void setup() {
  int addr, data=1;
  Serial.begin(9600);
  for (addr=0; addr<1023; addr++) {
    EEPROM.write(addr, data);
  }
  for (addr=0; addr<1023 ; addr++) {
    Serial.print(EEPROM.read(addr), DEC);
  }
}

When I simulate the code in the tinkercad, then i get the following error:

In function `main':
43: undefined reference to `loop'
 error: ld returned 1 exit status

Please help me where is the error in my code. I am not able to understand the error source.

3

Have you looked at any Arduino IDE example programs?

They all have a setup() and loop() function.

Apparently, Tinkercad is missing the loop() function in your code.

You can solve the issue by adding an empty void loop() { } after your void setup() { ... } code.

| improve this answer | |
  • Thank you, now the code works. But I have a question in this code why there is use of the empty void loop() because it executes infinitely. It may be a silly question, I am a beginner to Arduino programming. But please tell what is the significance of empty void loop() in this code? – Manu Jun 25 at 7:42
  • 1
    In most projects, Arduino code does not just execute once, but runs in a continuous loop, for example to service button presses, display data, take sensor measurements and act on them. The creators of the Arduino IDE have made the loop() function a standard part of every Arduino program to facilitate this. It's not part of standard C++. In your case your program just executes once and the loop() function does not have any significance. It's just doing nothing in a "controlled" way (continuous loop) and waiting for a reset. – StarCat Jun 25 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.