IMU for lab 2 part 2, part 3 and part 4.

Dependencies:   4DGL-uLCD-SE LSM9DS0 mbed

Fork of 4180_lab2_part2_LSM9DS0 by ECE4180

Revision:
7:8c458123a665
Parent:
6:87468d3886ea
Child:
8:4927aa0ab07a
diff -r 87468d3886ea -r 8c458123a665 main.cpp
--- a/main.cpp	Sat Sep 05 13:48:58 2015 +0000
+++ b/main.cpp	Sat Sep 05 19:38:13 2015 +0000
@@ -13,14 +13,14 @@
 #define LSM9DS0_G_ADDR   0x6B // Would be 0x6A if SDO_G is LOW
 
 // refresh time. set to 500 for part 2 and 50 for part 4
-#define REFRESH_TIME_MS 500
+#define REFRESH_TIME_MS 50
 
 // Verify that the pin assignments below match your breadboard
 LSM9DS0 imu(p9, p10, LSM9DS0_G_ADDR, LSM9DS0_XM_ADDR);
 Serial pc(USBTX, USBRX);
 
 #ifdef PART_4
-uLCD_4DGL lcd(p28, p27, p30);X
+uLCD_4DGL lcd(p28, p27, p30);
 #endif
 
 //Init Serial port and LSM9DS0 chip
@@ -30,7 +30,6 @@
 	lcd.baudrate(3000000);
 	lcd.background_color(0);
 	lcd.cls();
-	
 	lcd.printf("Initializing...");
 #endif
 
@@ -47,7 +46,12 @@
 {
     setup();  //Setup sensor and Serial
     pc.printf("------ LSM0DS0 Demo -----------\n");
-
+    lcd.cls();
+    lcd.circle(64, 64, 63, WHITE);
+    float fx = 64.0, fy = 64.0;
+    int x = 64, y = 64, radius = 4;
+	float vx, vy;
+	
     while (true)
     {
     	// Compass Trigonometry tip: you can retrieve the compass heading (in degrees) directly from
@@ -65,14 +69,28 @@
 	    float heading = imu.calcHeading(); //calculate compass heading
 	    imu.readTemp();
 	    //pc.printf("Compass heading: %2f\n", heading);
-//	    pc.printf("Accelerometer data: %2f, %2f, %2f\n", imu.ax, imu.ay, imu.az);
-//	    pc.printf("Temperature in Fahr: %3.2f\n", imu.temperature_f);
+	    //pc.printf("Accelerometer data: %2f, %2f, %2f\n", imu.ax, imu.ay, imu.az);
+	    //pc.printf("Temperature in Fahr: %3.2f\n", imu.temperature_f);
 	    
-	    //Part3 display it on the uLCD
-	    pc.printf("C: %2f\n", heading);
-	    pc.printf("A: %2f, %2f, %2f\n", imu.ax, imu.ay, imu.az);
-	    pc.printf("T: %3.2f\n", imu.temperature_f);
+	    //Part3 display through real serial COM
+	   //pc.printf("C: %2f\n", heading);
+	   //pc.printf("A: %2f, %2f, %2f\n", imu.ax, imu.ay, imu.az);
+	   //pc.printf("T: %3.2f\n", imu.temperature_f);
+	
+		//Part4 display bubble level on the uLCD
 		
+		lcd.filled_circle(x, y, radius, RED);
+		wait(0.5);
+		vx = imu.ax * 58;
+		vy = imu.ay * 58;
+		lcd.filled_circle(x, y, radius, BLACK);
+		fx = 64 - vx;
+		fy = 64 + vy;
+		x = int(fx);
+		y = int(fy);
+		
+		//
+	
 		wait_ms(REFRESH_TIME_MS);
 	}
 }