Hsing-Hung Lai
/
Nucleo_LED
homework_1
Diff: main.cpp
- Revision:
- 0:5e39cd6c5291
diff -r 000000000000 -r 5e39cd6c5291 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 10 14:05:44 2016 +0000 @@ -0,0 +1,44 @@ +/*LAB_LED*/ +#include "mbed.h" + +//LED1 = D13 = PA_5 (LED on Nucleo board) + +DigitalOut led1(LED1); +Ticker timer1; + +int a; + +void init_IO(void) +{ + a = 0; + led1 = 0; +} + +void timer1_interrupt(void) +{ + a = a+1; +} + +void init_TIMER(void) +{ + timer1.attach_us(&timer1_interrupt, 1000.0);//1ms interrupt period (1 KHz) +} + +int main() +{ + + init_IO(); + init_TIMER(); + + while(1) { + + if (a==500) { + led1 = 1; + } + + if(a==1000) { + led1 = 0; + a = 0; + } + } +} \ No newline at end of file