Cylon like LED flashing sequence

The video showed a LED flashing sequence that reminded me of the pattern used the Battlestar Galactica Cylon robots.  I couldn't find a cookbook program for it, so I wrote one.  Since I really don't remember the exact sequence, I made it bidirectional single LED chaser with  timing controlled by define statements. This way you can easily change the shift time and total time for sequece.   The default is 40 ms flash per LED and ~ 1 second repeat rate.

Assuming the board is orientated with the LEDs at the bottom, the sequence is right to left and back again at shift time, with blanking for the remainder of the repeat time.

Now when you power up your board, it strikes fear in Battlestar fans.

This first mbed program, I would love to port the FORTH and LUA programming languages to the board, I'll try working on it after I finish some MSP430F2013 programs I have in the works.

Enjoy,

Tom Belpasso

Integrated-Vision.com

#include "mbed.h"

// time between shifting to next LED
#define SHIFT_TIME 0.04
// total time for sequence
#define REPEAT_TIME 1.0
// blank time between sequences
#define BLANK_TIME REPEAT_TIME - 9 * SHIFT_TIME

BusOut leds(LED1, LED2, LED3, LED4);
int main() 
  // i is used to turn on first LED in the sequence
  short i = 1;
  bool dir = 0 ; // 0 - shift left, 1 - shift right with LEDs on bottom
  leds = 0;
  while(1) {
    if (dir)
      leds = (leds >> 1) + i;  // shift right
    else
      leds = (leds << 1) + i;    // shift left
    wait(SHIFT_TIME);
    if (leds != 0)   // if any leds lit, don't turn any more on
      i = 0;
    // see if all LEDs are off
    if (leds == 0) {
      if (dir) {
        dir = 0 ;  // toggle directon
        i = 1;        // LSB LED on next shift
        wait(BLANK_TIME);
      } else {
        dir = 1;
        i = 8;        // MSB LED on next shift
        wait(SHIFT_TIME);
      }
    }
  }
}


0 comments

You need to log in to post a comment