Skip to main content

Value Types

Blokdots defines two custom value types that replace Arduino's standard types on memory-constrained boards.

#blokdots::Color

An RGB color value with channels for red, green, and blue.

C++
struct Color {
  uint8_t r;  // 0–255
  uint8_t g;  // 0–255
  uint8_t b;  // 0–255
};

Constructors:

C++
blokdots::Color()                              // black (0, 0, 0)
blokdots::Color(uint8_t r, uint8_t g, uint8_t b)

Example:

C++
blokdots::Color red(255, 0, 0);
blokdots::Color off;  // (0, 0, 0)

Color is the value type used by LED strip and matrix components.


#blokdots::String

A fixed-size, stack-allocated string that replaces Arduino's heap-based String class.

C++
struct String {
  static constexpr size_t MAX_LENGTH = 63;  // 64 bytes total
  char data[MAX_LENGTH + 1];
};

Why not Arduino's String?
Arduino's built-in String allocates memory on the heap, which causes fragmentation on boards with only 2 KB of RAM. blokdots::String has a fixed 64-byte footprint on the stack — no allocation, no fragmentation, no memory leaks.

Constructors:

C++
blokdots::String()                  // empty string
blokdots::String(const char* str)   // from C-string literal
blokdots::String(int value)         // "42"
blokdots::String(float value)       // "3.14"
blokdots::String(bool value)        // "true" or "false"
blokdots::String(blokdots::Color c) // "RGB(255,128,0)"

Usage:

blokdots::String converts implicitly to const char*, so it works anywhere Arduino expects a C-string:

C++
blokdots::String label("Hello!");
Serial.println(label);          // implicit conversion
lcd.print(label.c_str());       // explicit

Template substitution:

Display components (OLED, LCD) support a {{value}} placeholder that is replaced with the current sensor value at runtime:

C++
// Shows current potentiometer reading
oled.drawString("Level: {{value}}");