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.

asked Jun 25, 2020 at 5:23
0

1 Answer 1

4

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.

answered Jun 25, 2020 at 5:56
2
  • 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? Commented Jun 25, 2020 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. Commented Jun 25, 2020 at 8:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.