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.
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 |
Modifier | Constructor and Description |
---|---|
public | ArduboyCore() |
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(bool inverse)
Invert display or set to normal; when inverted, pixels set to 0 will be on
|
void static |
allPixelsOn(bool on)
Turn all the display's pixels on, or display the hardware buffer contents
|
void static |
flipVertical(bool flipped)
Flip the display vertically or set to normal
|
void static |
flipHorizontal(bool 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
|
See SSD1306 documents for available commands and command sequences.
Links:
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.
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)
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.
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.
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.
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.
Boots the hardware:
You do not need to call this directly. See Arduboy's begin().
This class extends the ArduboyCore class, provides a software-side screen buffer, and many utility to functions.
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 |
---|---|---|
INVERT | 2 | |
WHITE | 1 | Use with any draw or fill functions |
BLACK | 0 | Use with any draw or fill functions |
Modifier and Type | Field and Description |
---|---|
ArduboyAudio | audio |
Modifier | Constructor and Description |
---|---|
public | Arduboy() |
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 |
bootLogo()
Scrolls in the Arduboy logo
|
void |
flashlight()
Flashlight mode
|
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
|
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
|
Returns true if the button mask passed in is pressed.
if (pressed(LEFT_BUTTON + A_BUTTON))
{
// Do stuff here
}
if (notPressed(LEFT_BUTTON))
{
// Do stuff here
}
Flashlight mode. Hold up key when booting to enable, press down key to exit or simply turn off your Arduboy. Your sketches can also call this at any time. It goes into a tight loop until the down buttn is pressed.
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).
Draws a circle of a defined radius in white or black. X and Y are the center point of the circle.
Draws a line between two points. Uses Bresenham's algorithm.
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.
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.
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.
Class to handle interfacing with the audio hardware.
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
|
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.
Separate class to break out Print subclassing.
This is necessary because C++ keeps a virtual function lookup table around for the virtual function "write" that the Print subclass requires. That single reference to the "write" function in the vtable means "write" will always be compiled and including in the final ouput (even if it's never actually used in your sketch) - which means it's dependencies are also #included
:
drawChar
font
(256 bytes!)drawRect
(for large font 'pixels')cursor_x
, cursor_y
, wrap_mode
, etc.This quickly adds up to 1 to 2kb of wasted space that many graphics based games never take advantage of. By breaking printing out into a separate class we prevent this. If you need it use it, if not then it will get dropped by the compiler during building.
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) |
Modifier | Constructor and Description |
---|---|
public | AbPrinter(Arduboy) |
Usage:
Arduboy arduboy;
AbPrinter text(arduboy);
Modifier and Type | Function and description |
---|---|
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 |
setCursor(int16_t x, int8_t y)
Sets the location of the screen cursor
|
void |
setSize(uint8_t s)
Set the text size
|
void |
setWrap(boolean w)
Set whether text will wrap at screen edges
|
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.
printer.print(F("string literal"));
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
.
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.