This is the end gate portion of a pinewood derby timer that uses an mbed. It communicates via HTTP to a web server that is doing the racer control and race management. Still need to put all that code together into a package on the net.

Dependencies:   EthernetNetIf mbed HTTPServer Servo

blinkm.cpp

Committer:
dminear
Date:
2011-03-09
Revision:
0:74139f5b6180

File content as of revision 0:74139f5b6180:

#include "mbed.h"
#include "Servo.h"
#include "share.h"

//Serial pc(USBTX, USBRX); // tx, rx

//prototypes
void FadeToColor(char r,char g, char b);
void FastColorChg(char r,char g, char b);
void PlayScript(char s);
void BlinkInit(void);
//DEFINES
#define BLINKADR    0x12

//I2C blink(p9,p10);
I2C blink(p28,p27);

#ifdef test

int main() {
    BlinkInit();
    FadeToColor(0x00,0x00,0x00);
    wait(2);
    FadeToColor(0xff,0xff,0xff);
    wait(2);
    int i = 0;
    while(1) {
       
        for(i = 0; i < 18; i++) {
        //pc.printf("script %d\n\r", i );
        PlayScript(i); //virtual candle
        wait(60);   // 10 sec script play
        }
    }
}
#endif

void BlinkInit(void)
{
    char data[1] = {'o'};
    blink.frequency(100000);
    blink.write(0x00, data, 1);  // will stop it at whatever address  
}
void FadeToColor(char r,char g, char b)
{
    char data[4] = {'c',r,g,b};
    blink.write(BLINKADR, data, 4);
}
void FastColorChg(char r,char g, char b)
{
    char data[4] = {'n',r,g,b};
    blink.write(BLINKADR, data, 4);
}
void PlayScript(char s)
{
    FadeToColor(0x00,0x00,0x00); // fade to black
    wait(0.25); //100 ms to make sure fade is complete
    if(s < 19) //only 19 scripts onboard
    {
        char data[4] = {'p',s,0,0}; //play script from start indefinetly
        blink.write(BLINKADR, data, 4);
    }
}

void FadeToRandomColor(void) {
    char data[4] = {'C',0xff,0xff,0xff};
       
        blink.write(BLINKADR, data, 4); // Send command string
        wait(0.07);              // Could also poll, 65ms is typical
}