LED flashing
Fork of Robotics_LED by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /*LAB_LED*/ 00002 #include "mbed.h" 00003 00004 #define LED_1 PA_5 00005 #define LED_2 D12 00006 00007 DigitalOut led_1(LED_1); 00008 DigitalOut led_2(LED_2); 00009 Ticker timer_1; 00010 00011 int timer_1_counter; 00012 00013 void init_IO(void) 00014 { 00015 led_1 = 0; 00016 led_2 = 0; 00017 00018 timer_1_counter = 0; 00019 } 00020 00021 void timer_1_interrupt() 00022 { 00023 timer_1_counter += 1; 00024 } 00025 00026 void init_TIMER(void) 00027 { 00028 timer_1.attach_us(&timer_1_interrupt, 1000.0);//1ms interrupt period (1 KHz) 00029 } 00030 00031 int main() 00032 { 00033 init_IO(); 00034 init_TIMER(); 00035 00036 while(1) 00037 { 00038 if(timer_1_counter == 1000) 00039 { 00040 // reset timer_1_counter to zero 00041 timer_1_counter = 0; 00042 00043 // led_1 flashes 00044 led_1 = 1; 00045 wait(0.2); 00046 led_1 = 0; 00047 } 00048 } 00049 }
Generated on Sun Jul 17 2022 14:09:40 by
1.7.2
