Polling to switch ON/OFF LED depending on Button Status

Dependencies:   mbed

Fork of Nucleo_read_button by youssef boksmati

Files at this revision

API Documentation at this revision

Comitter:
pinofal
Date:
Mon May 07 07:11:49 2018 +0000
Parent:
0:7f1c12137729
Commit message:
Amaldi 3 Exercise

Changed in this revision

LED-Button-Polling.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 7f1c12137729 -r 832dfb4ba1af LED-Button-Polling.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LED-Button-Polling.cpp	Mon May 07 07:11:49 2018 +0000
@@ -0,0 +1,37 @@
+// Tested: NUCLE-L476RG
+
+#include "mbed.h"
+
+// crea oggetti Button, LED e serialPC  
+DigitalIn myButton(USER_BUTTON);
+DigitalOut myLed(LED1);
+Serial pc(USBTX, USBRX); 
+
+
+/********/
+/* MAIN */
+/********/
+int main() 
+{
+  // imposta velocità della comunicazione con il PC
+  pc.baud(921600);
+  
+  //imposta il funzionamento del pulsante come "PullDown": Aperto = '0'. L'altra modalità di funzinamento è PullUp
+  myButton.mode(PullDown);
+  
+  // POLLING: replica sul LED myLED lo stato del pulsante myButton
+  while(true) 
+  {
+    if (myButton == 1) 
+    { 
+        // Button is pressed
+        myLed = 1; // Accendi LED
+    }
+    else 
+    {
+        // Button i released
+        myLed = 0; // Spegni LED
+    }
+  }
+}
+ 
\ No newline at end of file
diff -r 7f1c12137729 -r 832dfb4ba1af main.cpp
--- a/main.cpp	Wed May 14 13:31:32 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-#include "mbed.h"
- 
-DigitalIn mybutton(USER_BUTTON);
-DigitalOut myled(LED2);
- 
-int main() {
-  while(1) {
-    if (mybutton == 0) { // Button is pressed
-      myled = 1; // Toggle the LED state
-    }
-    else {
-     myled = 0; // Toggle the LED state
-    }
-  }
-}
- 
\ No newline at end of file
diff -r 7f1c12137729 -r 832dfb4ba1af mbed.bld
--- a/mbed.bld	Wed May 14 13:31:32 2014 +0000
+++ b/mbed.bld	Mon May 07 07:11:49 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/ed8466a608b4
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/5aab5a7997ee
\ No newline at end of file