Robotics LAB LED
Dependencies: mbed
實驗二
使開發板上之LED以每秒一次的頻率閃爍
Hint
- 將Ticker頻率設為100 Hz (週期10ms)
- 以計數器方式計算一秒
Due Date:2018/03/16
main.cpp@0:9249cba27176, 2018-02-28 (annotated)
- Committer:
- roger5641
- Date:
- Wed Feb 28 11:23:48 2018 +0000
- Revision:
- 0:9249cba27176
Robotics LAB LED
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
roger5641 | 0:9249cba27176 | 1 | /*LAB_LED*/ |
roger5641 | 0:9249cba27176 | 2 | #include "mbed.h" |
roger5641 | 0:9249cba27176 | 3 | |
roger5641 | 0:9249cba27176 | 4 | //LED1 = D13 = PA_5 (LED on Nucleo board) |
roger5641 | 0:9249cba27176 | 5 | DigitalOut led1(LED1); |
roger5641 | 0:9249cba27176 | 6 | Ticker timer1; |
roger5641 | 0:9249cba27176 | 7 | |
roger5641 | 0:9249cba27176 | 8 | //Function declaration |
roger5641 | 0:9249cba27176 | 9 | void init_IO(); |
roger5641 | 0:9249cba27176 | 10 | void timer1_interrupt(); |
roger5641 | 0:9249cba27176 | 11 | void init_TIMER(); |
roger5641 | 0:9249cba27176 | 12 | |
roger5641 | 0:9249cba27176 | 13 | int main() |
roger5641 | 0:9249cba27176 | 14 | { |
roger5641 | 0:9249cba27176 | 15 | init_IO(); |
roger5641 | 0:9249cba27176 | 16 | init_TIMER(); |
roger5641 | 0:9249cba27176 | 17 | |
roger5641 | 0:9249cba27176 | 18 | while(1) |
roger5641 | 0:9249cba27176 | 19 | { |
roger5641 | 0:9249cba27176 | 20 | ; |
roger5641 | 0:9249cba27176 | 21 | } |
roger5641 | 0:9249cba27176 | 22 | } |
roger5641 | 0:9249cba27176 | 23 | |
roger5641 | 0:9249cba27176 | 24 | void timer1_interrupt() |
roger5641 | 0:9249cba27176 | 25 | { |
roger5641 | 0:9249cba27176 | 26 | ///YOUR CODE HERE/// |
roger5641 | 0:9249cba27176 | 27 | } |
roger5641 | 0:9249cba27176 | 28 | |
roger5641 | 0:9249cba27176 | 29 | void init_IO() |
roger5641 | 0:9249cba27176 | 30 | { |
roger5641 | 0:9249cba27176 | 31 | led1 = 0; |
roger5641 | 0:9249cba27176 | 32 | } |
roger5641 | 0:9249cba27176 | 33 | |
roger5641 | 0:9249cba27176 | 34 | void init_TIMER(void) |
roger5641 | 0:9249cba27176 | 35 | { |
roger5641 | 0:9249cba27176 | 36 | ///Setup timer1/// |
roger5641 | 0:9249cba27176 | 37 | // the address of the function is to be attached (timer1_interrupt) and the interval (10000 micro-seconds) |
roger5641 | 0:9249cba27176 | 38 | timer1.attach_us(&timer1_interrupt, 10000.0);//10ms interrupt period (100 Hz) |
roger5641 | 0:9249cba27176 | 39 | } |