read acceleration and angler ratio from mpu6050 and estimate pitch and roll angle

Dependencies:   mbed

toString.cpp

Committer:
ojan
Date:
2015-05-13
Revision:
3:40559ebef0f1
Parent:
0:5e220b09d315

File content as of revision 3:40559ebef0f1:

#include "toString.h"

void ToBinaryString(char* dest, int destSize, const int integer, int byteNum) {
    memset(dest, 0, destSize*sizeof(char));
    strcat(dest, "0b");
    if(byteNum > 4) {
        strcat(dest, "########");
        return;
    }
    for(int i=1; i<=8*byteNum; i++) {
        if(integer & (1<<(8*byteNum-i))) {
            strcat(dest, "1");
        } else {
            strcat(dest, "0");
        }
    }
}