José Claudio / Mbed 2 deprecated ReadingGyro_ITG3205

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "ITG3205.h"
00003 #include "Gyroscope.h"
00004 
00005 #define SDA      p9
00006 #define SCL      p10
00007 
00008 ITG3205 *itg3205;
00009 Gyroscope *gyroscope;
00010 Serial pc(USBTX, USBRX);
00011 
00012 float gyroX, gyroY, AngleX, AngleY;
00013 Ticker updater;
00014 
00015 void update()
00016 {
00017     pc.printf("x: %f \t\t y: %f \t\t angle x: %f \t\t angle y: %f  \r\n", gyroX, gyroY, AngleX, AngleY);
00018 }
00019 int main()
00020 {
00021     itg3205 = new ITG3205(SDA, SCL);
00022     gyroscope = new Gyroscope(itg3205, 14.375, 0.005);
00023     wait(1);
00024     gyroscope->updateZeroRates();
00025     pc.baud(115200);
00026     updater.attach(&update, 0.2);
00027     while(1) 
00028     {
00029 
00030         wait_ms(5);
00031         gyroscope->update();
00032         
00033         gyroX = gyroscope->getDegreesX();
00034         gyroY = gyroscope->getDegreesY() * -1;
00035         AngleX = gyroscope->getAngleX();
00036         AngleY = gyroscope->getAngleY();
00037 
00038         //printf("x: %f \t\t y: %f \t\t angle x: %f \t\t angle y: %f  \r\n", gyroX, gyroY, AngleX, AngleY);
00039         //printf("%f,%f,%f,%f\n", gyroX, gyroY, AngleX, AngleY);
00040         
00041     }
00042 
00043 }