Cortex Challenge Team / Mbed 2 deprecated DiscoveryF0-LED_and_Button

Dependencies:   mbed

Revision:
1:9b85c92a1ace
Parent:
0:ec0b92e7f922
Child:
2:da8f8b14f387
--- a/main.cpp	Wed Mar 11 15:51:59 2015 +0000
+++ b/main.cpp	Wed Mar 11 16:31:03 2015 +0000
@@ -1,38 +1,78 @@
+/**********************************************************************************
+* @file    main.cpp
+* @author  Marta Krepelkova
+* @version V0.1
+* @date    11-March-2015
+* @brief   LED blinking with button for STM32F0 Discovery kit
+***********************************************************************************/
+ 
+/**********************************************************************************/
+/*   Table of used pins on STM32F0 Discovery kit with STM32F051R8 MCU (LQFP64)    */
+/**********************************************************************************/
+/*  LQFP64 pin   | Discovery pin  | ST Nucleo F030R8 pin  |      peripheral       */
+/*      14       |     PA_0       |         PC_13         |      User button      */
+/*      39       |     PC_8       |         PA_5          |      LED              */
+/*      40       |     PC_9       |                       |      LED              */
+/**********************************************************************************/
+ 
+/* Includes ----------------------------------------------------------------------*/
 #include "mbed.h"
  
-InterruptIn button(PA_0);       // definovani tlacitka s urcenim, na jaky pin procesoru je tlacitko pripojeno
-DigitalOut blue(PC_8);          // definovani modre LED diody s urcenim, na jaky pin procesoru je modra LED pripojena
-DigitalOut green(PC_9);         // definovani zelene LED diody s urcenim, na jaky pin procesoru je zelena LED pripojena
- 
-bool press = false;             // promenna typu boolean, kam se uklada, jestli bylo stisteno tlacitko
+//Handles the initialization of peripherals
+InterruptIn button(PA_0);       // inicialize button on STM32F0 discovery
+DigitalOut blue(PC_8);          // inicialize blue LED on STM32F0 discovery
+DigitalOut green(PC_9);         // inicialize green LED on STM32F0 discovery
+
+
+
+/* Variables ---------------------------------------------------------------------*/ 
+bool press = false;             // boolean value, where you can find if was the button pressed
+
+
+
+/* Functions----------------------------------------------------------------------*/
  
-void pressed()                  // metoda vykonana pri stisku tlacitka
+/*******************************************************************************
+* Function Name  : pressed.
+* Description    : Changes value press if someone pressed the button.
+* Input          : None.
+* Output         : None.
+* Return         : None.
+*******************************************************************************/ 
+void pressed()
 {
-    if (press == false){        // pokud byla promenna press false (tlacitko nebylo zmacknuto), vykona se nasledujici kod
-        press = true;           // zmena promenne press na true (rika, ze tlacitko bylo stisteno)
-    }else{                      // pokud promenna press nebyla false, vykona se nasledujici kod
-        press = false;          // zmena promenne press na false
+    if (press == false){        // variable prees was false (button wasn't pressed yet)
+        press = true;           // press is true (button was pressed)
+    }else{                      // variable press was true
+        press = false;          // press is false
     }
 }
- 
-int main()                      // hlavni metoda
+  
+/*******************************************************************************
+* Function Name  : main.
+* Description    : Main routine.
+* Input          : None.
+* Output         : None.
+* Return         : None.
+*******************************************************************************/
+int main()
 {
-    blue=1;                     // na zacatku behu programu je modra LED zhasnuta
-    green=0;                    // zelena LED rozsvicena
-    button.fall(&pressed);      // pokud bylo stisteno tlacitko, je vyvolano preruseni a vykonána metoda pressed
+    blue=1;                     // blue LED is off
+    green=0;                    // green LED is on
+    button.fall(&pressed);      // button was pressed, call function pressed
     
-    while (1) {                 // nekonecna smycka
-        green = !green;         // obraceni hodnoty zelene LED 
-        if (press == false){    // kdyz tlacitko neni stisteno, vykona se nasledujici kod
-            blue=!green;        // hodnota modre LED je opacna nez hodnota zelene LED
-            wait(0.4);          // ceka 400 ms
-        }else{                  // kdyz je tlacitko stisteno
-            blue=green;         // hodnota modre LED je stejna jako hodnota zelene LED
-            wait(0.2);          // ceka 200 ms
-            green = !green;     // obraceni hodnoty zelene LED 
-            wait(0.2);          // ceka 200 ms
-            green = !green;     // obraceni hodnoty zelene LED 
-            wait(0.2);          // ceka 200 ms
+    while (1) {                 // infinity loop
+        green = !green;         // inverse value of green LED
+        if (press == false){    // button wasn't pressed
+            blue=!green;        // value of blue LED is iverse to green LED
+            wait(0.4);          // wait 400 ms
+        }else{                  // button was pressed
+            blue=green;         // value of blue LED is same like value of green LED
+            wait(0.2);          // wait 200 ms
+            green = !green;     // inverse value of green LED
+            wait(0.2);          // wait 200 ms
+            green = !green;     // inverse value of green LED
+            wait(0.2);          // wait 200 ms
         }
     }
 }
\ No newline at end of file