Skip to main content

Code Export C++

The C++ Code Export feature allows you to export your blokdots project as Arduino-compatible C++ code that runs directly on your board without requiring a computer connection.

cmd ⌘shift ⇧E

You can also export using the Arduino icon button in the toolbar.

#Standalone Operation

Unlike the JavaScript export which requires a computer to remain connected to your Arduino, the C++ export generates code that can be uploaded directly to your board. Once uploaded, your project runs independently on the Arduino itself - perfect for creating standalone installations or battery-powered projects.

#Exporting the Project

To export your project as C++ code, go to File › Export Code C++… and select a location. It's helpful to give your project components and cards descriptive names before exporting, as these names will be used for variables and functions in the generated code.

blokdots will create a folder containing:

  • An Arduino sketch file (.ino) with your project code
  • A header file (blokdots.h) with pin definitions and component declarations
  • A README.md with setup and upload instructions
  • Automatic library dependencies listed for easy installation

#Arduino Sketch Structure

The generated .ino file follows standard Arduino conventions with a setup() and loop() function. Here's an example of a simple button and LED toggle project:

C++
/* -------------------------------------------------------
Led Toggle
Generated by blokdots (2.6.1) · 1/18/2026, 10:05:05 PM
---

---------------------------------------------------- \*/

// --- Libraries ---
#include <Arduino.h>
#include "blokdots.h"

// -------- Event IDs (generated) --------
enum : uint8_t {
EVT_BUTTON_DOWN = 1,
EVT_BUTTON_UP = 2,
EVT_LED_CHANGED = 3
};

// -------- Runtime --------
EventBus bus;

// -------- Components --------
Button button(bus, 2, EVT_BUTTON_DOWN, EVT_BUTTON_UP, false, 30);
DigitalActor led(bus, 4, EVT_LED_CHANGED);

// -------- Trigger state (generated outsideVars) --------
int card0_button_counter = 0;

// -------- Actions (generated) --------
void none_card0_Action() {
led.stop().toggle();
}

// -------- Setup --------
void setup() {
// initialize all components
blokdots::beginAll();

// -------- Trigger wiring --------
bus.on(EVT_BUTTON_DOWN, []() {
card0_button_counter++;
if (card0_button_counter >= 1) {
card0_button_counter = 0;
none_card0_Action();
}
});
}

// -------- Loop --------
void loop() {
// Check if we need to trigger stop actions (once)
static bool stopActionsTriggered = false;
if (!blokdots::isRunning() && !stopActionsTriggered) {
// No project stop actions
stopActionsTriggered = true;
}

if (!blokdots::isRunning()) {
return; // Project is stopped, skip all processing
}

bus.tick();
blokdots::tickAll();
}

#Header File

The generated header file (blokdots.h) contains all pin definitions and component configurations for your project, keeping your main sketch clean and organized. This makes it easy to adjust pin numbers or component settings without modifying the core logic.

#Automatic Library Installation

When you export your project, blokdots automatically installs all required Arduino libraries. You don't need to manually install anything - the export process handles all dependencies for you.

In case this did not work, you can find all libraries needed in the README.md file and you can install them manually in the Arduino IDE.

#Current Limitations

The C++ export currently has some limitations compared to the full blokdots environment:

  • Integration components (Figma, ProtoPie, Socket.IO) are not yet supported
  • Advanced timing and scheduling features may have limited support

For projects using Integration components, use the JavaScript code export instead, which provides full feature support but requires a computer connection.

#Uploading to Your Board

After exporting, you can upload the code to your Arduino using the Arduino IDE. Download and install the Arduino IDE if you don't have it already.

Alternatively, use the Upload Project to Board feature in blokdots for one-click uploading directly from the app.

#Next Steps

After exporting your C++ code, you can:

  • Upload it to your board and run it standalone
  • Modify the generated code to add custom functionality
  • Share your project without requiring the blokdots software