Hello World
This walks through a very simple program to light the LED, print "Hello World" to the screen, and move it around a bit.
Getting started
To get started, create a new project with the Arduino IDE and include the Arduboy library (Sketch > Include Library > Arduboy). If there is no Arduboy library under the menu, then you need to install it.
After this you will have a default file that looks something like this:
#include <Arduboy.h>
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
Instantiating the library
The first thing we need to do is make an instance of the library and initialize it. We can do that by creating an Arduboy typed variable and calling its begin
function:
#include <Arduboy.h>
Arduboy arduboy;
void setup() {
// put your setup code here, to run once:
arduboy.begin();
}
void loop() {
// put your main code here, to run repeatedly:
}
Adding text
Next, we need to give the Arduboy instance something to print.
#include <Arduboy.h>
Arduboy arduboy;
void setup() {
// put your setup code here, to run once:
arduboy.begin();
arduboy.clear();
arduboy.print("Hello World");
arduboy.display();
}
void loop() {
// put your main code here, to run repeatedly:
}
The call to clear the screen is required because otherwise the boot logo will still be in the buffer when we add our text. The display function causes our changes to the software screen buffer to be reflected on the display.
Moving the text around
Static text is boring, however, so let's move it around a bit. The first thing we need to do in order to move the text is add a frame guard. By default the library tries to run at 60 frames per second. As the loop
function may be called more often, we need to ensure we're only running when we want to be:
void loop() {
// put your main code here, to run repeatedly:
if (!arduboy.nextFrame()) return;
}
In addition, the core library also offers a way to check if a certain number of frames has passed allowing us to, for example, run every 30 frames or twice per second:
uint8_t y = 0;
void loop() {
// put your main code here, to run repeatedly:
if (!arduboy.nextFrame()) return;
// Run twice per second.
if (arduboy.everyXFrames(30))
{
// Start over after the text moves off screen.
if (y > arduboy.height())
{
y = 0;
}
else
{
y++;
}
arduboy.clear();
arduboy.setCursor(0, y);
arduboy.print("Hello World");
arduboy.display();
}
}
Adding the LED
The LED is a bit like a cherry on top. It looks pretty, but it's not meant for eating. ;) The core library offers a function, setRGBled
, we can use to turn on the LED. It takes values 0 to 255 for the red, green, and blue components of the LED where 0 is off, and 255 is on.
uint8_t y = 0;
void loop() {
// put your main code here, to run repeatedly:
if (!arduboy.nextFrame()) return;
// Run twice every second.
if (arduboy.everyXFrames(30))
{
// Start over after the text moves off screen.
if (y > arduboy.height())
{
y = 0;
}
else
{
y++;
}
arduboy.clear();
arduboy.setCursor(0, y);
arduboy.print("Hello World");
arduboy.display();
// Party time!
arduboy.setRGBled(y, 0, 0);
}
}
Uploading to your Arduboy
If this isn't the first time you've uploaded anything to your Arduboy, you can just plug in your Arduboy and click the upload button from the toolbar or click "Sketch > Upload."
For first timers, you'll want to plug in your Arduboy and wait for the OS to recognize your device. After it does, click the "Tools > Boards > Arduino Leonardo" menu item. Next, open "Tools > Port" and select the first entry that says "(Arduino Leonardo)". Once you've done that, you can click the upload button from the toolbar.
If the Port menu is still disabled after plugging your Arduboy in, your OS may not have properly recognized your it yet. You may want to give it a bit longer, try unplugging it and plugging it back in, or carefully resetting it.
Learn more
This is a very simple program. If you want to learn more, check out the tutorial.