for high school

Files at this revision

API Documentation at this revision

Comitter:
Dennis_Yu
Date:
Sun Sep 09 13:44:05 2018 +0000
Commit message:
sensors librarie for high school kids

Changed in this revision

sensors.cpp Show annotated file Show diff for this revision Revisions of this file
sensors.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 6dca851b4779 sensors.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sensors.cpp	Sun Sep 09 13:44:05 2018 +0000
@@ -0,0 +1,29 @@
+#include "sensors.h"
+#include "mbed.h"
+
+//extern Serial usb;
+
+void sr501::triggered()
+{
+    //usb.printf("Triggered!\r\n");
+    status = true;
+}
+
+sr501::sr501(PinName pSignal)
+    : status(false), signal(pSignal)
+{
+    signal.rise(this, &sr501::triggered);
+}
+
+bool sr501::operator ==(const bool &target)
+{
+    if(status == target)
+        return true;
+    else
+        return false;
+}
+
+void sr501::reset()
+{
+    status = false;
+}
diff -r 000000000000 -r 6dca851b4779 sensors.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sensors.h	Sun Sep 09 13:44:05 2018 +0000
@@ -0,0 +1,24 @@
+#ifndef SENSORS_H
+#define SENSORS_H
+
+#include "mbed.h"
+//#include <stdlib.h>
+
+class sr501
+{
+/*****
+ * 红外热释电对象
+ * 感应输出高电平
+*****/
+  private:
+//    DigitalIn signal;
+    bool status;
+    InterruptIn signal;
+    void triggered();
+  public:
+    sr501(PinName pSignal);
+    bool operator ==(const bool &target);
+    void reset();
+};
+
+#endif