BTstack Bluetooth stack

Dependencies:   mbed USBHost

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers led_counter.cpp Source File

led_counter.cpp

00001 #if 0
00002 //*****************************************************************************
00003 //
00004 // led_counter demo - uses the BTstack run loop to blink an LED
00005 //
00006 //*****************************************************************************
00007 #include "mbed.h"
00008 #include <btstack/run_loop.h>
00009 
00010 Serial pc(USBTX, USBRX);
00011 DigitalOut led1(LED1), led2(LED2);
00012 
00013 #define HEARTBEAT_PERIOD_MS 1000
00014 
00015 static void  heartbeat_handler(struct timer *ts){
00016 
00017     // increment counter
00018     static int counter = 0;
00019     char lineBuffer[30];
00020     sprintf(lineBuffer, "BTstack counter %04u\n\r", ++counter);
00021     printf(lineBuffer);
00022     
00023     // toggle LED
00024     led2 = !led2;
00025     
00026     run_loop_set_timer(ts, HEARTBEAT_PERIOD_MS);
00027     run_loop_add_timer(ts);
00028 } 
00029 
00030 // main
00031 int main(void)
00032 {
00033     pc.baud(921600);
00034     printf("%s\n", __FILE__);
00035 
00036     // init LEDs
00037     led1 = led2 = 1;
00038     
00039     /// GET STARTED with BTstack ///
00040     run_loop_init(RUN_LOOP_EMBEDDED);
00041         
00042     // set one-shot timer
00043     timer_source_t heartbeat;
00044     heartbeat.process = &heartbeat_handler;
00045     run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS);
00046     run_loop_add_timer(&heartbeat);
00047     
00048     printf("Run...\n\r");
00049 
00050     // go!
00051     run_loop_execute();    
00052     
00053     // happy compiler!
00054     return 0;
00055 }
00056 #endif