Skip to content

PORT_Arduino

DragonCoder01 edited this page Apr 27, 2020 · 2 revisions

Overview

Here I've got the Arduino version of a blinking LED. As you can see, it is much more readable than the C version. But this readability comes at a cost.

Code

#include <Arduino.h>

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

void loop() {
	digitalWrite(13, HIGH);
	delay(500);
	digitalWrite(13, LOW);
	delay(500);
}

If you want to know more about the code, look at the repository. I've documented most of the lines for you there! 😃

Flash and RAM

Flash RAM
1286 / 32256 Bytes (4.0%) 9 / 2048 Bytes (0.4%)

To be fair, this is the result with non standard Arduino compile options. Here, I am compiling with optimization level -O1 instead of -Os.

If you compile it with the Arduino standard options, you'll get something more like this:

Flash RAM
930 / 32256 Bytes (2.9%) 9 / 2048 Bytes (0.4%)

Conclusion

Still, compared to the C version this Arduino version is on the heavy side. Some might say that that's the price you have to pay for the gained abstraction. As we will see soon, we can do better than that. We will gain:

  • More functionality
  • The same amount of abstraction
  • Better Performance (No overhead compared to the C version)
  • And all of that using evil C++! With classes!
Clone this wiki locally