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.
1 Answer 1
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.
-
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– Manu2020年06月25日 07:42:08 +00:00Commented Jun 25, 2020 at 7:42
-
1In 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– StarCat2020年06月25日 08:19:54 +00:00Commented Jun 25, 2020 at 8:19
Explore related questions
See similar questions with these tags.