Egyszerű LED villogtatás NUCLEO-F446RE kártyán (MBED2)

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
cspista
Date:
Tue Sep 21 13:37:25 2021 +0000
Parent:
0:bf9e6380ebf9
Commit message:
LED switching by button

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Sep 21 12:37:36 2021 +0000
+++ b/main.cpp	Tue Sep 21 13:37:25 2021 +0000
@@ -1,12 +1,23 @@
 #include "mbed.h"
 
-DigitalOut myled(LED1); // PA_5 alias LED1
-
-int main() {
+DigitalOut myled(LED1);                 // PA_5 alias LED1
+DigitalIn mybutton(BUTTON1,PullUp);     // PC13 alias BUTTON1
+int bState, waitforpress=1, led_state=0;
+int main()
+{
     while(1) {
-        myled = 1;      // LED is ON
-        wait(0.2);      // 200 ms
-        myled = 0;      // LED is OFF
-        wait(1.0);      // 1 sec
+        bState = mybutton;
+        if(waitforpress) {              //Ha lenyomásra várunk és
+            if(!bState) {               //Ha lenyomás történt...
+                led_state = !led_state; //LED állapotának átbillentése
+                myled = led_state;
+                waitforpress = false;   //Következő stáció: felengedésre várunk
+            }
+        } else {                        //Ha felengedésre vártunk és
+            if(bState) {                //Ha felengedést észlelünk...
+                waitforpress = true;    //Következő stáció: lenyomásra várunk
+            }
+        }
+        wait(0.02);                     // 20 ms pergésmentesítő késleltetés
     }
 }
\ No newline at end of file