Lights blink when a magnet is detected

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
m211002
Date:
Mon Apr 29 17:16:18 2019 +0000
Commit message:
Light blinks when a magnet is detected

Changed in this revision

main.cpp Show annotated file 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 000000000000 -r f556205c07a6 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Apr 29 17:16:18 2019 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+Serial pc(USBTX,USBRX);
+
+// Hall effect sensor
+DigitalIn hall(p21);
+DigitalOut hallpwr(p22);
+
+InterruptIn event(p21);
+DigitalOut led1(LED1);
+DigitalOut led4(LED4);
+
+int hallvalue;
+int hallstatus=0;
+void trigger()
+{
+    while (hallstatus!=0) {
+        led1=1;
+        wait(1);
+        led1=0;
+        hallstatus=0;
+    }
+}
+int main()
+{
+    hall.mode(PullUp);
+    hallpwr=0;
+    wait(0.2);
+    hallpwr =1;
+    wait(0.2);
+    event.rise(&trigger);
+    while(1) {
+        hallvalue=hall.read();
+        if (hallvalue==1) {
+            hallstatus=1;
+        }
+        pc.printf("hallvalues:%d\n\r",hallvalue);
+        wait(0.25);
+    }
+}
diff -r 000000000000 -r f556205c07a6 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Apr 29 17:16:18 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file