main cool image for example

Flashing My User LED Using Reflexes

Overview

A common example in embedded system programming illustrates how to flash an LED. BrainStem modules have a built-in blue colored LED called the User LED. The User LED is designated on the PCB with a stick figure "man" icon.

BrainStem application examples require the BrainStem Support package. Acroname provides simulated BrainStem modules within this distribution that can be used instead 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 Software Support Package

-OR-

  • aSymonym Software Package

Example Setup

Synchronous LED Flashing using Reflex API

The LED flashing can be handled entirely through Reflex code.  The LED is flashed using two entities of the System class.  The first entity is the LED entity which turns the User LED on when the value is nonzero or off when the value is zero.  The Sleep entity is then used to adjust the length of time that the LED is on or off.  The Sleep entity  waits in microseconds, providing the user with precise timing capabilities.

flowchart synchronous program

Synchronous Reflex Program Flowchart

LED Flashing Using Reflex Synchronously

#include <a40PinModule.reflex>

a40PinModule stem;

// macro for 1 second delay
#define DELAY 1000000

reflex mapEnable()
{

  char i = 0;

  for (i = 0; i < 10; i++) {
    stem.system.setLED(true);
    stem.system.sleep(DELAY);
    stem.system.setLED(false);
    stem.system.sleep(DELAY);
  } // end of for loop

} // end of mapEnable
  • Line 3 - Creates an a40PinModule stem object.
  • Line 14 - Turns the User LED on.
  • Line 15 - Sleeps wait in microsecond increments.
  • Line 16 - Turns the User LED off.