4180 Lab 2

Dependencies:   mbed wave_player Servo 4DGL-uLCD-SE Motor SDFileSystem LSM9DS1_Library_cal PinDetect X_NUCLEO_53L0A1

Revision:
0:90df82d4732d
Child:
1:6d8f645530b8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/part3.h	Sun Feb 02 21:36:14 2020 +0000
@@ -0,0 +1,41 @@
+#include "mbed.h"
+#include "uLCD_4DGL.h"
+
+uLCD_4DGL uLCD(p27,p28,p30);
+LSM9DS1 lol(p9, p10, 0xD6, 0x3C);
+
+int run_part3() {
+    lol.begin();
+    if (!lol.begin()) {
+        pc.printf("Failed to communicate with LSM9DS1.\n");
+    }
+    
+    lol.calibrate();
+    int outer_radius = 15;
+    int inner_radius = 10;
+    
+    int center = (int)floor(127.0 / 2.0);
+    int max_diff = 66536;
+    
+    int curr_x = center;
+    int curr_y = center;
+    
+    while(1) {
+        lol.readTemp();
+        //lol.readMag();
+//        lol.readGyro();
+        
+        pc.printf("accel: %d %d %d\n\r", lol.ax, lol.ay, lol.az);
+        
+        uLCD.filled_circle(curr_x, curr_y, inner_radius, BLACK);
+        uLCD.circle(center, center, outer_radius, WHITE);
+        
+        int y_diff = ((lol.ay / max_diff) * 3.0);
+        int x_diff = ((lol.ax / max_diff) * 3.0);
+        
+        curr_x -= x_diff;
+        curr_y -= y_diff;
+        
+        uLCD.filled_circle(curr_x, curr_y, inner_radius, WHITE);
+    }
+}
\ No newline at end of file