Cubelets API Documentation 2.0
C API
Loading...
Searching...
No Matches
Cubelets C API

Introduction

Welcome to the Cubelets C API. This API can be used with Console. To flash new code onto your cubelets, they must be running OS4.

Code Structure

The basic structure of your custom program should start with:

#include "cubelet.h"
void setup()
{
//Your run-once initialization code goes here
}
void loop()
{
//The code you wish to run over and over goes here
}
void setup()
Function ran just a single time. Used for setting up variables or timers.
Definition bargraph.c:3
void loop()
The loop() function gets called repeatedly while a Cubelet is powered on.
Definition bargraph.c:8

Example Cubelet Program

An example using some of the most useful API calls:

#include "cubelet.h"
//A simple program for a flashlight block demonstrating some API calls
//The amount of delay (in milliseconds) between toggling block_value
#define TOGGLE_DELAY_MS 500
//Simple function to toggle the block_value between 255 and 0.
//It will be called after TOGGLE_DELAY_MS milliseconds.
void toggle_block_value(void)
{
//inverse will toggle block_value between 0 and 255. (inverse(255) == 0, inverse(0) == 255)
block_value = inverse(block_value);
}
void setup()
{
//block_value starts at 0
block_value = 0;
//Start the timer that will call toggle_block_value() continuously every TOGGLE_DELAY_MS milliseconds
set_interval(TOGGLE_DELAY_MS, toggle_block_value);
}
void loop()
{
set_flashlight(block_value);
}
uint8_t inverse(uint8_t bv)
Returns the inverse of the supplied block value.
void set_interval(uint16_t delay, timer_callback_t callback)
Allows a function callback to be fired continuously after the specified amount of time.

List All Cubelets

Where to find the API calls you're looking for

You can always browse the full API to find what you need, but here are some starting points: