Flashing My User LED Using C++


BrainStem modules have a dedicated blue colored LED available for user manipulation. The User LED is designated on the module  with a stick figure "man" icon.  A host machine can manipulate the User LED using the BrainStem C++ API.  The API can discover and create a link to an attached BrainStem module. After the  the link is created, the host can use the System class in the API to toggle the LED.

BrainStem application examples require the BrainStem Support package. Acroname provides simulated BrainStem modules within this distribution that can be used in the absence of hardware using the Symonym application.

The Setup

There are several hardware components needed for this example:

  • 40-Pin EtherStem 1.0 Module
  • 40-Pin Breakout Board
  • Ethernet Cable
  • Computer
  • Power Supply
  • BrainStem Support Package


  • aSymonym Software Package

Example Setup

Synchronous LED enable using the C++ API

The BrainStem C++ API enables a host machine to interact with a BrainStem module.  A link must be established before any interaction occurs.  The aLink class can discover and create a link to a BrainStem module.  Once a link is established the code then uses the LED entity of the System class to toggle the User LED.  The Sleep entity is then used to adjust the length of time the LED is on or off.  The Sleep entity delays code execution in millisecond increments for the C++ API.

LED Flashing using C++ API

#include "a40PinModule.h"

main(const int argc,
     const char* argv[])
  // Create a link to the first BrainStem found on the specified
  // transport linktype
  aLink link(aLink::specifier::IP4);
  printf("connecting to stem...");
  if (!link.isConnected(3000)) {
    printf("timed out\n");
    return aErrTimeout;

  // Need a link and I2C module address to create a BrainStem object
  a40PinModule stem(link, a40PINSTEM_MODULE);

  uint8_t bLEDState = 0;
  for (uint8_t i = 0; i < 10; i++) {
    bLEDState = !bLEDState;
  } // end of for loop
  // Turn the LED off before exiting

  return 0;
} // main

Line 7 -  This constructor creates a link to the first discovered BrainStem on the specified transport linktype
Line 16 - Creation of a BrainStem object requires a link and I2C module address