NUCLEO-F042K6 Simple demo with button interrupt input

Dependencies:   mbed

Committer:
vodsejak
Date:
Sat Feb 17 18:14:58 2018 +0000
Revision:
1:129f63c021d8
Parent:
0:32b38fc2ecec
v1.1; commentary update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vodsejak 0:32b38fc2ecec 1 #include "mbed.h"
vodsejak 1:129f63c021d8 2 /*******************************************************************************
vodsejak 0:32b38fc2ecec 3
vodsejak 1:129f63c021d8 4 EXAMPLE DESCRIPTION
vodsejak 1:129f63c021d8 5
vodsejak 1:129f63c021d8 6 Sets digital in on PA_0 with internal pull up. On falling edge (button press)
vodsejak 1:129f63c021d8 7 interrupt that toggles onboard LED is called.
vodsejak 1:129f63c021d8 8
vodsejak 1:129f63c021d8 9 *******************************************************************************/
vodsejak 0:32b38fc2ecec 10 InterruptIn button(PA_0); // deffition of interrupt
vodsejak 0:32b38fc2ecec 11
vodsejak 0:32b38fc2ecec 12 DigitalOut LED(LED1); // definition of digital out pin
vodsejak 0:32b38fc2ecec 13
vodsejak 0:32b38fc2ecec 14 // toggles LED
vodsejak 0:32b38fc2ecec 15 void pressed() {
vodsejak 0:32b38fc2ecec 16 LED=!LED;
vodsejak 0:32b38fc2ecec 17 }
vodsejak 0:32b38fc2ecec 18
vodsejak 0:32b38fc2ecec 19 int main()
vodsejak 0:32b38fc2ecec 20 {
vodsejak 0:32b38fc2ecec 21 button.fall(&pressed); // Set button interrupt
vodsejak 0:32b38fc2ecec 22 button.mode(PullUp); // set internal pull up
vodsejak 0:32b38fc2ecec 23 while(1) {
vodsejak 0:32b38fc2ecec 24 // can do other things
vodsejak 0:32b38fc2ecec 25 }
vodsejak 0:32b38fc2ecec 26
vodsejak 0:32b38fc2ecec 27 }