![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
tugboat project
Dependencies: TinyGPS HMC5883L MMA8451Q mbed PwmIn
main.cpp
- Committer:
- bclaus
- Date:
- 2013-07-31
- Revision:
- 2:db76adcdf799
- Parent:
- 0:ee158c8007b4
- Child:
- 4:7fb44cbc97a3
File content as of revision 2:db76adcdf799:
#include "mbed.h" #include "MMA8451Q.h" #include "TinyGPS.h" #include "HMC5883L.h" #define MMA8451_I2C_ADDRESS (0x1d<<1) I2C i2c_bus(PTE0, PTE1); MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); HMC5883L compass(i2c_bus); Serial pc(USBTX, USBRX); Serial radio(PTC4, PTC3); Timer t; TinyGPS gps; Serial gpsSerial(PTD3,PTD2); void gpsSerialRecvInterrupt (void); int main(void) { pc.baud(115200); radio.baud(57600); int16_t dCompass[3]; float dAcc[3]; compass.init(); pc.printf("inited\r\n"); gpsSerial.attach (&gpsSerialRecvInterrupt, gpsSerial.RxIrq); // Recv interrupt handler gps.reset_ready(); while (true) { if(gps.gga_ready()){ pc.printf("lat: %.8f, lon: %.8f\r\n", gps.f_lat(), gps.f_lon()); radio.printf("lat: %.8f, lon: %.8f\r\n", gps.f_lat(), gps.f_lon()); } acc.getAccAllAxis(dAcc); pc.printf("xA: %.4f, yA: %.4f, zA: %.4f\r\n", dAcc[0], dAcc[1], dAcc[2]); radio.printf("xA: %.4f, yA: %.4f, zA: %.4f\r\n", dAcc[0], dAcc[1], dAcc[2]); compass.getXYZ(dCompass); pc.printf("xC: %4d, yC: %4d, zC: %4d\r\n", dCompass[0], dCompass[1], dCompass[2]); radio.printf("xC: %4d, yC: %4d, zC: %4d\r\n", dCompass[0], dCompass[1], dCompass[2]); wait(0.5); } } //***************************************************************************** // serial receive interrupt handler //***************************************************************************** void gpsSerialRecvInterrupt (void) { // while(gpsSerial.readable()){ gps.encode(gpsSerial.getc()); //} }