4180 IMU parts (I2C, uLCD, RS232, USB Serial, SD)
Dependencies: 4DGL-uLCD-SE LSM9DS1_Library_cal SDFileSystem mbed
Revision 2:f17a67920767, committed 2016-02-12
- Comitter:
- mikeb
- Date:
- Fri Feb 12 16:25:04 2016 +0000
- Parent:
- 1:6c4ba07e0c77
- Commit message:
- Added SDFile System, all untested
Changed in this revision
diff -r 6c4ba07e0c77 -r f17a67920767 SDFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Fri Feb 12 16:25:04 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/neilt6/code/SDFileSystem/#d10a519c0910
diff -r 6c4ba07e0c77 -r f17a67920767 main.cpp --- a/main.cpp Thu Feb 11 22:46:43 2016 +0000 +++ b/main.cpp Fri Feb 12 16:25:04 2016 +0000 @@ -1,6 +1,7 @@ #include "mbed.h" #include "LSM9DS1.h" #include "uLCD_4DGL.h" +#include "SDFileSystem.h" #define PI 3.14159 // Earth's magnetic field varies by location. Add or subtract // a declination to get a more accurate heading. Calculate @@ -13,6 +14,10 @@ Serial pc(USBTX, USBRX); Serial device(p13, p14); uLCD_4DGL uLCD(p27,p28,p30); // serial tx, serial rx, reset pin; +SDFileSystem sd(p5, p6, p7, p8, "sd"); +//Global variables. Whatever. Sue me. +float oldx = 0; +float oldy = 0; // Calculate pitch, roll, and heading. @@ -54,10 +59,10 @@ } void bubLev(float ax, float ay, float az, float oldx, float oldy){ - - uLCD.filled_circle(63, 63, 40, 0x0000FF); - uLCD.filled_circle(ax/az*40+63, ay/az*40+63, 5, 0xFF00FF); - + uLCD.filled_circle(oldx, oldy, 5, BLACK); + uLCD.filled_circle(floor(-ax/az*40.0)+63, floor(-ay/az*40.0)+63, 5, 0xFF00FF); + oldx = floor(ax/az*40)+63; + oldy = floor(ay/az*40)+63; } @@ -67,6 +72,24 @@ { //device.baud(19200); //device.format(8N1); + + mkdir("/sd/mydir", 0777); + FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); + if(fp == NULL) { + error("Could not open file for write\n"); + } + fprintf(fp, "Hello SD File World!\n Mike and Gedeon Lab 2.\n"); + fclose(fp); + + char myString [100]; + + FILE *fr = fopen("/sd/mydir/sdtest.txt", "r"); + if (fgets(myString, 100, fr) != NULL){ + pc.printf("%s\n", myString); + } + fclose(fr); + wait(2); + LSM9DS1 IMU(p9, p10, 0xD6, 0x3C); sel.mode(PullUp); uLCD.baudrate(3000000); @@ -76,6 +99,7 @@ } IMU.calibrate(1); IMU.calibrateMag(0); + uLCD.filled_circle(63, 63, 40, 0x0000FF); while(1) { while(!IMU.tempAvailable()); IMU.readTemp(); @@ -103,6 +127,8 @@ printAttitude(IMU.calcAccel(IMU.ax), IMU.calcAccel(IMU.ay), IMU.calcAccel(IMU.az), IMU.calcMag(IMU.mx), IMU.calcMag(IMU.my), IMU.calcMag(IMU.mz)); } + + bubLev(IMU.calcAccel(IMU.ax), IMU.calcAccel(IMU.ay), IMU.calcAccel(IMU.az), oldx, oldy); myled = 1; wait(0.5); myled = 0;
diff -r 6c4ba07e0c77 -r f17a67920767 part2.cpp