NIT Fukui / Serial6050Yaw

Dependents:   R1Arobo_Maika_B 2021Arobo_UMAPYOI 2021Arobo_YUMIPYOI

Serial6050.cpp

Committer:
yopcyuuu
Date:
2018-09-26
Revision:
1:97a3a91ce950
Parent:
0:c3d09c97649b
Child:
2:00a8daf9203b

File content as of revision 1:97a3a91ce950:

#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()) break;
        }
    }
    serial.attach(this, &Serial6050::intReceive, RawSerial::RxIrq);
    wait(0.1);
    reset();
}

void Serial6050::reset()
{
    resetValue = lower - 127;
}



float Serial6050::read()
{
    int value = lower;
    return (value - 127 - resetValue) / 10.0;
}