NIT Fukui / Serial6050Yaw

Dependents:   R1Arobo_Maika_B 2021Arobo_UMAPYOI 2021Arobo_YUMIPYOI

Revision:
0:c3d09c97649b
Child:
1:97a3a91ce950
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Serial6050.cpp	Thu Sep 20 01:13:45 2018 +0000
@@ -0,0 +1,35 @@
+#include "Serial6050.h"
+
+Serial6050::Serial6050(PinName tx, PinName rx, PinName resetPin)
+    : serial(tx, rx, 38400), rst(resetPin)
+{
+}
+
+void Serial6050::init()
+{
+    rst = 0;
+    wait(0.2);
+    rst = 1;
+    while(1) {
+        serial.putc(100);
+        if(serial.readable()) {
+            if(serial.getc() == 0x80) break;
+        }
+    }
+    serial.attach(this, &Serial6050::intReceive, RawSerial::RxIrq);
+    wait(0.1);
+    reset();
+}
+
+void Serial6050::reset()
+{
+    resetValue = higher >> 7 + lower - 8192;
+}
+
+
+
+float Serial6050::read()
+{
+    int value = higher >> 7 + lower;
+    return (value - 8192 - resetValue) / 10.0;
+}
\ No newline at end of file