anthrolume

Experiments in wearable electronic art.

Getting started on the software

Leave a comment

I’m getting pretty close to done with the fabrication of the final physical harness and mechanisms by which the harness is to be affixed to my body. Now that the hardware’s under control, it’s time to start building the real software. All along I’ve been building little programs to test the rig and to try out different animations, displays, and controllers. But these were little one-off programs. I’ve been designing the internal architecture for the real software in my notes for a month, and I started working on some of it this weekend.

The first library I carved off was a mechanism to do scheduled tasks. There are no threads on the Arduino, so I need to carry out my animations on the one and only loop() thread. The plan is to make that loop as fast as possible, and to have it call a TimedTaskManager “tick” function each time through the loop that will fire off any tasks that are scheduled to happen at the current time. That class, the public interface for which is shown below, is now implemented and tested:

class TimedTaskManager
{
  public:
    // Constants
    static const int kMaxTasks = 32;

    // Constructor/destructor
    TimedTaskManager();
		
    // Task management
    bool addTask(ulong whenTaskProc proculong cookie);
    void removeAllTasks();
		
    // Call this from your loop() function as often as possible
    void tick();
		
    // Debugging
    void dump();
};

All my programs have a “heartbeat” that blinks the on-board LED on the Arduino periodically so I know it’s alive. Using TimedTaskManager, that turns into the following:

const ulong kBlinkMs = 200;
TimedTaskManager gTasks;
byte gBlinkState = LOW;

void _HeartbeatTask(ulong cookieulong scheduledulong fired)
{
  bytepBlinkState = (byte*)cookie;
  *pBlinkState = (*pBlinkState == HIGH) ?  LOW : HIGH;
  digitalWrite(13, *pBlinkState);
  gTasks.addTask(fired + kBlinkMs_HeartbeatTaskcookie);
}

void setup()
{
  pinMode(13, OUTPUT);
  gTasks.addTask(millis() + kBlinkMs_HeartbeatTask,
    (ulong)&gBlinkState);
}

void loop()
{
  gTasks.tick();

  ...
}
Advertisements

Author: anthrolume

I'm a Seattle musician and experimental electronic artist.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s