Arduino, C++, arrays and templates
Let’s assume that you’ve picked up your Arduino, and you’ve run the standard examples, and are wondering, now what? If you’re already experienced with C++ you’re probably ready to jump in and be productive. If you’re transitioning from a different language, things might not be so straight forward.
I’ve been messing around with this simple example, primarily to keep refactoring the already short code that cycles the leds, pressing the button changes the rate at which the leds cycle, trying to find elegant solutions to common patterns.
The core examples are minimal by design, easy to understand first, elegant and useful last. The first thing to know about Arduino .ino files is that they’re a code fragments that are merged into a standard C++ file. The two standard methods setup()
and loop()
are run from the main function (the entry point of your application). setup()
is run first, then loop()
is run in an endless for(;;) {}
loop.
Before we go into any specifics, let’s talk about some easy debugging practices. Unless you’ve got an LCD hooked up to your Arduino, the easiest way to get info out is via the Serial monitor.