*

Dependencies:   mbed-STM32F103C8T6 mbed

Committer:
BaserK
Date:
Sat Apr 29 15:30:37 2017 +0000
Revision:
0:8a8ae179f49c
*

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BaserK 0:8a8ae179f49c 1 #include "stm32f103c8t6.h"
BaserK 0:8a8ae179f49c 2 #include "mbed.h"
BaserK 0:8a8ae179f49c 3
BaserK 0:8a8ae179f49c 4 // Interrupt example
BaserK 0:8a8ae179f49c 5 // Changes the state of the led when pushed a button
BaserK 0:8a8ae179f49c 6
BaserK 0:8a8ae179f49c 7 DigitalOut led(PB_12);
BaserK 0:8a8ae179f49c 8 InterruptIn button(PB_13);
BaserK 0:8a8ae179f49c 9 Timer debounce;
BaserK 0:8a8ae179f49c 10
BaserK 0:8a8ae179f49c 11 void toggle_led();
BaserK 0:8a8ae179f49c 12
BaserK 0:8a8ae179f49c 13 int main()
BaserK 0:8a8ae179f49c 14 {
BaserK 0:8a8ae179f49c 15 confSysClock(); //Configure system clock (72MHz HSE clock, 48MHz USB clock)
BaserK 0:8a8ae179f49c 16
BaserK 0:8a8ae179f49c 17 // calls the toggle_led function at the rising edge of the pin
BaserK 0:8a8ae179f49c 18 // when button is pressed the signal goes from low to high
BaserK 0:8a8ae179f49c 19 button.rise(&toggle_led);
BaserK 0:8a8ae179f49c 20 debounce.start();
BaserK 0:8a8ae179f49c 21
BaserK 0:8a8ae179f49c 22 /* while (1)
BaserK 0:8a8ae179f49c 23 {
BaserK 0:8a8ae179f49c 24
BaserK 0:8a8ae179f49c 25 } */
BaserK 0:8a8ae179f49c 26 }
BaserK 0:8a8ae179f49c 27
BaserK 0:8a8ae179f49c 28 void toggle_led()
BaserK 0:8a8ae179f49c 29 {
BaserK 0:8a8ae179f49c 30 if(debounce.read_ms() > 250) // only allow toggle after 50 ms
BaserK 0:8a8ae179f49c 31 {
BaserK 0:8a8ae179f49c 32 led = !led;
BaserK 0:8a8ae179f49c 33 debounce.reset(); // restart timer after toggle
BaserK 0:8a8ae179f49c 34 }
BaserK 0:8a8ae179f49c 35 }