ArduboyCore #

This is the base class, which the Arduboy class extends. Use the Arduboy class over this unless you want to build your own replacement Arduboy class.

#defines #

These are values for the pre-processor that runs prior to compilation. They get replaced in your code with the listed values. Items without a value are flags that other pre-processor directives can look for. These can be set by using #define NAME_HERE and removed with #undef NAME_HERE

Name Value Notes
SAFE_MODE Not defined by default; If defined, press up and left during boot to enter it
LEFT_BUTTON _BV(5) Use with buttonState, pressed, or notPressed
RIGHT_BUTTON _BV(6) Use with buttonState, pressed, or notPressed
UP_BUTTON _BV(7) Use with buttonState, pressed, or notPressed
DOWN_BUTTON _BV(4) Use with buttonState, pressed, or notPressed
A_BUTTON _BV(3) Use with buttonState, pressed, or notPressed
B_BUTTON _BV(2) Use with buttonState, pressed, or notPressed
WIDTH 128 Screen width in pixels
HEIGHT 64 Screen height in pixels
INVERT 2
WHITE 1 Use with any draw or fill functions
BLACK 0 Use with any draw or fill functions

Constructors #

Modifier Constructor and Description
public ArduboyCore()

Functions #

Modifier and Type Function and description
void static LCDDataode()
Put the display in data mode
void static LCDCommandMode()
Put the display in command mode
uint8_t static width()
Return display width
uint8_t static height()
Return display height
uint8_t static buttonsState()
Get current state of all buttons (bitmask)
void static paint8Pixels(uint8_t pixels)
Paint 8 pixels (vertically) from a single byte
void static paintScreen(const unsigned char *image)
Paints an entire image directly to hardware (from PROGMEM)
void static paintScreen(unsigned char image[])
Paints an entire image directly to hardware (from RAM)
void static blank()
Paints a blank (black) screen to hardware
void static invert(boolean inverse)
Invert display or set to normal; when inverted, pixels set to 0 will be on
void static allPixelsOn(boolean on)
Turn all the display's pixels on, or display the hardware buffer contents
void static flipVertical(boolean flipped)
Flip the display vertically or set to normal
void static flipHorizontal(boolean flipped)
Flip the display horizontally or set to normal
void static sendLCDCommand(uint8_t command)
Send a single byte command to the display
void setRGBled(uint8_t red, uint8_t green, uint8_t blue)
Set the light output of the RGB LED
void static boot()
Boots the hardware

void static LCDCommandMode() #

See SSD1306 documents for available commands and command sequences.

Links:

void static buttonsState() #

Get current state of all buttons (bitmask).

Bit mask that is returned:

    Hi   Low
    00000000
    URLDAB--

- reserved, D down, U up, L left, R right

Of course you shouldn't worry about bits (they may change with future hardware revisions) and should instead use the button defines: LEFT_BUTTON, A_BUTTON, UP_BUTTON, etc.

void static paint8Pixels(uint8_t pixels) #

Paints 8 pixels (vertically) from a single byte. 1 is lit, 0 is unlit.

NOTE: You probably wouldn't actually use this, you'd build something higher level that does it's own calls to SPI.transfer(). It's included for completeness since it seems there should be some very rudimentary low-level draw function in the core that supports the minimum unit that the hardware allows (which is a strip of 8 pixels).

This routine starts in the top left and then across the screen. After each "page" (row) of 8 pixels is drawn it will shift down to start drawing the next page. To paint the full screen you call this function 1,024 times.

Example:

X = painted pixels, . = unpainted

blank()                      paint8Pixels() 0xFF, 0, 0x0F, 0, 0xF0
v TOP LEFT corner (8x9)      v TOP LEFT corner
........ (page 1)            X...X... (page 1)
........                     X...X...
........                     X...X...
........                     X...X...
........                     X.X.....
........                     X.X.....
........                     X.X.....
........ (end of page 1)     X.X..... (end of page 1)
........ (page 2)            ........ (page 2)

void static paintScreen(const unsigned char image*) #

Paints an entire image directily to hardware (from PROGMEM). Each byte will be 8 vertical pixels, painted in the same order as explained above in paint8Pixels.

void static paintScreen(unsigned char image[]) #

Paints an entire image directly to hardware (from RAM). Each byte will be 8 vertical pixels, painted in the same order as explained above in paint8Pixels.

void static allPixelsOn(bool on) #

Turn all the display's pixels on, or display the hardware buffer contents. When set to turn all pixels on, the hardare display buffer will be ignored but not altered.

void static setRGBled(uint8_t red, uint8_t green, uint8_t blue) #

Set the light output of the RGB LED. 255 or 0xFF will set a color to full brightness. 0 or 0x00 will turns a pixel off. Anywhere in between will dim the LED.

void static boot() #

Boots the hardware:

You do not need to call this directly. See Arduboy's begin().

Arduboy (extends ArduboyCore) #

This class extends the ArduboyCore class, provides a software-side screen buffer, and many utility to functions.

#defines #

These are values for the pre-processor that runs prior to compilation. They get replaced in your code with the listed values. In reality these defines exist in Print.h in the Arduino core, but like the print and println functions they are documented here for convenience and awareness.

Name Value Notes
DEC 10 Use with print (2) or println (2)
HEX 16 Use with print (2) or println (2)
OCT 8 Use with print (2) or println (2)
BIN 2 Use with print (2) or println (2)

Fields #

Modifier and Type Field and Description
ArduboyTunes tunes
ArduboyAudio audio

Constructors #

Modifier Constructor and Description
public Arduboy()

Functions #

Modifier and Type Function and description
boolean pressed(uint8_t buttons)
Returns true if the button mask passed in is pressed
boolean notPressed(uint8_t buttons)
Returns true if the button mask passed in is not pressed
void begin()
Initialize hardware, boot logo, boot utilities, etc.
void
void
void bootUtils()
Boot utils such as a flashlight, etc.
void clear()
Clears the display
void display()
Copies the contents of software screen buffer to hardware screen buffer
void drawPixel(int x, int y, uint8_t color)
Sets a single pixel in the software screen buffer to white or black
uint8_t getPixel(uint8_t x, uint8_t y)
void drawCircle(int16_t x0, int16_t y0, uint8_t r, uint8_t color)
Draw a circle of a defined radius
void drawCircleHelper(int16_t x0, int16_t y0, uint8_t r, uint8_t cornername, int16_t delta, uint8_t color)
Draws one or more "corners" of a circle
void fillCircle(int16_t x0, int16_t y0, uint8_t r, uint8_t color)
Draws one or both vertical halves of a filled-in circle
void fillCircleHelper(int16_t x0, int16_t y0, uint8_t r, uint8_t cornername, int16_t delta, uint8_t color)
Draws one or both vertical halves of a filled-in circle
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t color)
Draws a line between two points
void drawRect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t color)
Draws a rectangle of a width and height
void drawFastVLine(int16_t x, int16_t y, uint8_t h, uint8_t color)
Draws vertical line
void drawFastHLine(int16_t x, int16_t y, uint8_t w, uint8_t color)
Draws a horizontal line
void fillRect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t color)
Draws a filled-in rectangle
void fillScreen(uint8_t color)
Fills the software screen buffer with white or black
void drawRoundRect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t r, uint8_t color)
Draws a rectangle with rounded edges
void fillRoundRect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t r, uint8_t color)
Draws a filled-in rectangle with rounded edges
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color)
Draws the outline of a triangle
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color)
Draws a filled-in triangle
void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t w, uint8_t h, uint8_t color)
Draws a bitmap from program memory to a specific X/Y
void drawSlowXYBitmap(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t w, uint8_t h, uint8_t color)
Draws images that are bit-oriented horizontally
void drawChar(int16_t x, int16_t y, unsigned char c, uint8_t color, uint8_t bg, uint8_t size)
Draws an ASCII character at a point
size_t print([various character types] val)
Writes ASCII characters and strings of ASCII characters to the screen
size_t print([various] val, int base = DEC)
Writes numbers, ASCII characters, and strings of ASCII characters to the screen
size_t println([various character types] val)
Writes ASCII characters and strings of ASCII characters to the screen followed by a line break (\r\n)
size_t println([various] val, int base = DEC)
Writes numbers, ASCII characters, and strings of ASCII characters to the screen followed by a line break (\r\n)
virtual size_t write(uint8_t c)
Writes a single ASCII character to the screen
void setTextCursor(int16_t x, int8_t y)
Sets the location of the screen cursor
void setTextSize(uint8_t s)
Set the text size
void setTextWrap(boolean w)
Set whether text will wrap at screen edges
unsigned char* getBuffer()
Returns the internal software screen buffer
void initRandomSeed()
Seeds the random number generator with entropy from the temperature, voltage reading, and microseconds since boot
void swap(int16_t& a, int16_t& b)
Swap the references of two pointers
void setFrameRate(uint8_t rate)
Sets the frame rate in frames-per-second
bool nextFrame()
Returns whether it's time for the next frame based on the frame rate
bool everyXFrames(uint8_t frames)
Returns true if the current frame is the Xth frame indicated by the argument
int cpuLoad()
Returns the load on the CPU as a percentage

boolean pressed(uint8_t buttons) #

Returns true if the button mask passed in is pressed.

if (pressed(LEFT_BUTTON + A_BUTTON))
{
  // Do stuff here
}

Returns true if the button mask passed in is not pressed #

if (notPressed(LEFT_BUTTON))
{
  // Do stuff here
}

void beginNoLogo() #

Initializes the hardware (but with no boot logo). This function should not be used, as it has been removed from the next version of the library.

void display() #

Copies the contents of software screen buffer to hardware screen buffer. X and Y positions on the display are from the top left corner, thus a Y of 64 is the bottom of the screen and an X of 128 is the right side of the screen. "Color" or "value" means choosing whether a pixel is lit or not - if color is 0, the pixel is off (black), if color is 1, the pixel is on (white).

void drawCircle() #

Draws a circle of a defined radius in white or black. X and Y are the center point of the circle.

void drawLine() #

Draws a line between two points. Uses Bresenham's algorithm.

void drawSlowXYBitmap() #

Draws images that are bit-oriented horizontally. This requires a lot of additional CPU power and will draw images slower than drawBitmap, where the images are stored in a format that allows them to be directly written to the screen. It is recommended you use drawBitmap when possible.

void print([various character types] val) #

Writes numbers, ASCII characters, and strings of ASCII characters to the screen. The argument can be one of

__FlashStringHelper * is the result of a string literal given to the F macro, which is an Arduino directive to store the data in flash memory.

arduboy.print(F("string literal"));

void print([various] val, int base = DEC) #

Writes numbers, ASCII characters, and strings of ASCII characters to the screen. The first argument can be one of

The second argument is the base in which to format the number and can be one of DEC (decimal), HEX, OCT (octal), BIN (binary). The default is DEC except for the double type which defaults to BIN.

void setSize(uint8_t s) #

Sets the text size. As mentioned in drawChar, individual ASCII characters are 6x8 pixels (5x7 with spacing on two edges). The size is a pixel multiplier, so a size of 2 means each character will be 12x16, etc. Values less than 1 are set to 1.

void initRandomSeed() #

Seeds the random number generator with entropy from the temperature, voltage reading, and microseconds since boot. This method is still most effective when called semi-randomly such as after a user hits a button to start a game or other semi-random events.

void cpuLoad() #

Returns the load on the CPU as a percentage. This is based on how much of the time your app is spends rendering frames. This number can be higher than 100 if your app is rendering really slowly.

ArduboyAudio #

Class to handle interfacing with the audio hardware.

Functions #

Modifier and Type Function and description
void static begin()
Initializes the audio hardware
void static on()
Turns on the audio hardware
void static off()
Turns off the audio hardware
void static saveOnOff()
Saves the enabled state of the audio hardware to the EEPROM
void static enabled()
Returns whether the audio hardware is on or off

void static begin(uint8_t s) #

Initializes the audio hardware. This is automatically called by Arduboy's begin() function and does not need to be called directly unless using your own boot sequence.

ArduboyTunes #

Class for playing sounds, tones, and tunes on the Arduboy.

Functions #

Modifier and Type Function and description
void initChannel(byte pin)
Assign a timer to an output pin
void playScore(const byte *score)
Start playing a polyphonic score
void stopScore()
Stop playing the score
void delay(unsigned msec)
Delay in milliseconds
void closeChannels()
Stop all timers
bool playing()
Return true if a score is currently playing
void tone(unsigned int frequency, unsigned long duration)
Play a tone
void static step()
Called via interrupt
void static step()
Called via interrupt

void initChannel(byte pin) #

Assign a timer to an output pin. Calling begin or beginNoLogo will automatically configure this to use both speaker pins.