Dependencies:   BNO055_fusion_tom FastPWM mbed

Fork of NucleoCube1 by Will Church

main.cpp

Committer:
wchurch
Date:
2017-04-09
Revision:
6:f2c930a90873
Parent:
5:9247f07a954a
Child:
7:1be7e6735fe2

File content as of revision 6:f2c930a90873:

#include "mbed.h"
#include "BNO055.h"


//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------

Serial pc(SERIAL_TX, SERIAL_RX);

Ticker pwmint; 
DigitalOut myled(LED1);
InterruptIn button(USER_BUTTON);

PwmOut P1(PE_9);
PwmOut P2(PE_11);
PwmOut P3(PE_13);

    I2C    i2c(PB_9, PB_8);         // SDA, SCL
    BNO055 imu(i2c, PA_8);          // Reset
 
    BNO055_ID_INF_TypeDef bno055_id_inf;
    BNO055_EULER_TypeDef  euler_angles;

int i = 180;
int isPressed;

void pwmupdate() {
    
    myled = !myled;
    
    
    P1 = (euler_angles.h/360.0);
    P2 = (euler_angles.r/360.0);
    P3 = (euler_angles.p/360.0);
    
    }
    
    void eventFunction() {
    if(!isPressed) {
        pwmint.attach(&pwmupdate, .005);   
        isPressed=1;
    } else {
        pwmint.detach();
        isPressed=0;   
    }
}

int main()
{
    
    pc.printf("Bosch Sensortec BNO055 test program on " __DATE__ "/" __TIME__ "\r\n");
    if (imu.chip_ready() == 0){
        pc.printf("Bosch BNO055 is NOT available!!\r\n");
    }
    
    imu.read_id_inf(&bno055_id_inf);
    
    pc.printf("CHIP:0x%02x, ACC:0x%02x, MAG:0x%02x, GYR:0x%02x, , SW:0x%04x, , BL:0x%02x\r\n",
               bno055_id_inf.chip_id, bno055_id_inf.acc_id, bno055_id_inf.mag_id,
               bno055_id_inf.gyr_id, bno055_id_inf.sw_rev_id, bno055_id_inf.bootldr_rev_id);
               
               
    isPressed=0;

    button.rise(&eventFunction);
    
    
    
    while(1) {

        
        pc.printf("Heading:%+6.4f [deg], Roll:%+6.4f [deg], Pitch:%+6.4f [deg]\r\n",
                    euler_angles.h, euler_angles.r, euler_angles.p);
        imu.get_Euler_Angles(&euler_angles);

        
        wait(0.2);
    }
}