4-Axisと同じラインセンサのライブラリ

Dependents:   00_yotsuba 10_motor-test 00_yotsuba 200_yotsuba_21

Revision:
0:058a2a20c0d1
Child:
1:2d25db124969
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/line.cpp	Mon Jan 27 09:14:17 2020 +0000
@@ -0,0 +1,42 @@
+#include "line.h"
+
+Line::Line(PinName line_):linesensor(line_)
+{
+    lineborder = DEFAULT_LINESENSOR_JUDGVALUE;
+    thread.start(callback(this, &Line::lineassemble));
+}
+Line::Line(PinName line_, float border_):linesensor(line_)
+{
+    thread.start(callback(this, &Line::lineassemble));
+    lineborder = border_;
+}
+
+void Line::border(float border_)
+{
+    lineborder = border_;
+}
+
+
+void Line::lineassemble()
+{
+    while(true) {
+        linevalue = 3300 * linesensor.read();
+        if(linevalue > lineborder) judgvalue = true;
+        else judgvalue = false;
+        thread.wait(1.0);
+    }
+}
+
+Line::operator bool(){
+    return judgvalue;
+    }
+
+float Line::value()
+{
+    return linevalue;
+}
+
+bool Line::judg()
+{
+    return judgvalue;
+}
\ No newline at end of file