CodeShare
Dependencies: 4DGL-uLCD-SE LSM9DS1_Library_cal mbed
Fork of LSM9DS1_Demo_wCal by
Revision 1:736628381fb9, committed 2016-09-25
- Comitter:
- jeremycai3721
- Date:
- Sun Sep 25 19:00:05 2016 +0000
- Parent:
- 0:e693d5bf0a25
- Commit message:
- CodeShare
Changed in this revision
4DGL-uLCD-SE.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL-uLCD-SE.lib Sun Sep 25 19:00:05 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
--- a/main.cpp Wed Feb 03 18:47:07 2016 +0000 +++ b/main.cpp Sun Sep 25 19:00:05 2016 +0000 @@ -1,6 +1,11 @@ #include "mbed.h" #include "LSM9DS1.h" #define PI 3.14159 + +#include "uLCD_4DGL.h" + +uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin; + // Earth's magnetic field varies by location. Add or subtract // a declination to get a more accurate heading. Calculate // your's here: @@ -9,6 +14,13 @@ DigitalOut myled(LED1); Serial pc(USBTX, USBRX); + + +float accel_x, accel_y, accel_z; +int outer_radius = 30; +int radius = 3; +int x,y; +//Serial pc(p13, p14); // Calculate pitch, roll, and heading. // Pitch/roll calculations taken from this app note: // http://cache.freescale.com/files/sensors/doc/app_note/AN3461.pdf?fpsp=1 @@ -46,14 +58,21 @@ int main() { + set_time(1474451138); // Set RTC time to Wed, 21 Sep 2016 9:46am + //time_t seconds = time(NULL); + //printf("Time as seconds since January 1, 1970 = %d\n\r", seconds); + + + //LSM9DS1 lol(p9, p10, 0x6B, 0x1E); - LSM9DS1 IMU(p28, p27, 0xD6, 0x3C); + LSM9DS1 IMU(p9, p10, 0xD6, 0x3C); IMU.begin(); if (!IMU.begin()) { pc.printf("Failed to communicate with LSM9DS1.\n"); } IMU.calibrate(1); IMU.calibrateMag(0); + while(1) { while(!IMU.tempAvailable()); IMU.readTemp(); @@ -74,6 +93,46 @@ wait(0.5); myled = 0; wait(0.5); + + while(1) { + + // 4180 Bubble Level + while(!IMU.accelAvailable()); + IMU.readAccel(); + accel_x = IMU.calcAccel(IMU.ax); + accel_y = IMU.calcAccel(IMU.ay); + accel_z = IMU.calcAccel(IMU.az); + pc.printf("accel: %9f %9f %9f in Gs\n\r", IMU.calcAccel(IMU.ax), IMU.calcAccel(IMU.ay), IMU.calcAccel(IMU.az)); + pc.printf("mag: %9f %9f %9f in gauss\n\r", IMU.calcMag(IMU.mx), IMU.calcMag(IMU.my), IMU.calcMag(IMU.mz)); + pc.printf("gyro: %9f %9f %9f in deg/s\n\r", IMU.calcGyro(IMU.gx), IMU.calcGyro(IMU.gy), IMU.calcGyro(IMU.gz)); + + //draw ball + x = 64 + 64*accel_x; + y = 64 + 64*accel_y; + uLCD.circle(64, 64, outer_radius, RED); + uLCD.filled_circle(x,y, radius, BLUE); + + time_t seconds = time(NULL); + + printf("Time as a basic string = %s", ctime(&seconds)); + + char buffer[32]; + strftime(buffer, 32, "%I:%M %p", localtime(&seconds)); + printf("\rTime as a custom formatted string = %s\n\r", buffer); + + + uLCD.locate(0,0); + uLCD.color(RED); + uLCD.printf("%s", ctime(&seconds)); + wait(0.2); + uLCD.color(BLACK); + uLCD.printf("%s", ctime(&seconds)); + //wait(0.1); + + uLCD.filled_circle(x,y, radius, BLACK); + + } + } }