z hl
/
DISCO-F429ZI_LEDs_Button
DISCO-F429ZI
main.cpp@0:326cb4830328, 2017-06-15 (annotated)
- Committer:
- zhlyz2003
- Date:
- Thu Jun 15 16:47:33 2017 +0000
- Revision:
- 0:326cb4830328
STM32F429Discovery
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zhlyz2003 | 0:326cb4830328 | 1 | #include "mbed.h" |
zhlyz2003 | 0:326cb4830328 | 2 | |
zhlyz2003 | 0:326cb4830328 | 3 | DigitalOut led_green(LED1); |
zhlyz2003 | 0:326cb4830328 | 4 | DigitalOut led_red(LED2); |
zhlyz2003 | 0:326cb4830328 | 5 | |
zhlyz2003 | 0:326cb4830328 | 6 | InterruptIn user_button(USER_BUTTON); |
zhlyz2003 | 0:326cb4830328 | 7 | |
zhlyz2003 | 0:326cb4830328 | 8 | float delay_on = 0.2; |
zhlyz2003 | 0:326cb4830328 | 9 | float delay_off = 1.0; |
zhlyz2003 | 0:326cb4830328 | 10 | |
zhlyz2003 | 0:326cb4830328 | 11 | void button_pressed() |
zhlyz2003 | 0:326cb4830328 | 12 | { |
zhlyz2003 | 0:326cb4830328 | 13 | delay_on = 0.1; |
zhlyz2003 | 0:326cb4830328 | 14 | delay_off = 0.1; |
zhlyz2003 | 0:326cb4830328 | 15 | } |
zhlyz2003 | 0:326cb4830328 | 16 | |
zhlyz2003 | 0:326cb4830328 | 17 | void button_released() |
zhlyz2003 | 0:326cb4830328 | 18 | { |
zhlyz2003 | 0:326cb4830328 | 19 | delay_on = 0.2; |
zhlyz2003 | 0:326cb4830328 | 20 | delay_off = 1.0; |
zhlyz2003 | 0:326cb4830328 | 21 | } |
zhlyz2003 | 0:326cb4830328 | 22 | |
zhlyz2003 | 0:326cb4830328 | 23 | int main() |
zhlyz2003 | 0:326cb4830328 | 24 | { |
zhlyz2003 | 0:326cb4830328 | 25 | user_button.rise(&button_pressed); |
zhlyz2003 | 0:326cb4830328 | 26 | user_button.fall(&button_released); |
zhlyz2003 | 0:326cb4830328 | 27 | |
zhlyz2003 | 0:326cb4830328 | 28 | while(1) { |
zhlyz2003 | 0:326cb4830328 | 29 | // LEDs are ON |
zhlyz2003 | 0:326cb4830328 | 30 | led_green = 1; |
zhlyz2003 | 0:326cb4830328 | 31 | led_red = 1; |
zhlyz2003 | 0:326cb4830328 | 32 | wait(delay_on); |
zhlyz2003 | 0:326cb4830328 | 33 | // LEDs are OFF |
zhlyz2003 | 0:326cb4830328 | 34 | led_green = 0; |
zhlyz2003 | 0:326cb4830328 | 35 | led_red = 0; |
zhlyz2003 | 0:326cb4830328 | 36 | wait(delay_off); |
zhlyz2003 | 0:326cb4830328 | 37 | } |
zhlyz2003 | 0:326cb4830328 | 38 | } |