Pierre Provent / Mbed 2 deprecated Read_Button_Nucleo_F429ZI

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
pierreprovent
Date:
Wed Sep 16 08:49:28 2020 +0000
Parent:
0:918fdb31e2ce
Commit message:
Programme de base pour cours Cnam ELE118

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 918fdb31e2ce -r e470129442d8 main.cpp
--- a/main.cpp	Tue Sep 15 11:24:56 2020 +0000
+++ b/main.cpp	Wed Sep 16 08:49:28 2020 +0000
@@ -1,12 +1,14 @@
 #include "mbed.h"
 
+DigitalIn mybutton(USER_BUTTON);
 DigitalOut myled(LED1);
 
-int main() {
+int main()
+{
     while(1) {
-        myled = 1; // LED is ON
-        wait(0.2); // 200 ms
-        myled = 0; // LED is OFF
-        wait(1.0); // 1 sec
+        if (mybutton == 0) { // Button is pressed
+            myled = !myled; // Toggle the LED state
+            wait(0.2); // 200 ms
+        }
     }
 }