4180 Lab 2

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

Revision:
1:6d8f645530b8
Parent:
0:90df82d4732d
Child:
2:de355b6fbd87
--- a/part3.h	Sun Feb 02 21:36:14 2020 +0000
+++ b/part3.h	Mon Feb 03 13:22:28 2020 +0000
@@ -1,14 +1,13 @@
 #include "mbed.h"
+#include "LSM9DS1.h"
 #include "uLCD_4DGL.h"
+#include <stdio.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;
@@ -20,13 +19,13 @@
     int curr_x = center;
     int curr_y = center;
     
+    uLCD.background_color(BLACK);
+    
     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);
         
@@ -37,5 +36,70 @@
         curr_y -= y_diff;
         
         uLCD.filled_circle(curr_x, curr_y, inner_radius, WHITE);
+        wait(0.001);
+    }
+}
+
+class Line {
+    public:
+    int start_x;
+    int start_y;
+    int end_x;
+    int end_y;
+};
+
+int run_part3_EC() {
+    lol.begin();
+    lol.calibrate();
+    
+    uLCD.background_color(BLACK);
+    
+    int center = (int)floor(127.0 / 2.0);
+    int radius = 10;
+    int line_length = 15;
+    
+    int prev_x = 0;
+    int prev_y = 0;
+    
+    Line curr_line;
+    curr_line.start_x = center;
+    curr_line.start_y = center - (radius/2);
+    curr_line.end_x = center;
+    curr_line.end_y = center - (radius / 2) + line_length;
+    
+    while (1) {
+        uLCD.circle(center, center, radius, BLACK);
+        uLCD.line(curr_line.start_x, curr_line.start_y, curr_line.end_x, curr_line.end_y, WHITE);
+        
+        uLCD.circle(center, center, radius, WHITE);
+        
+        int y_diff = lol.my - prev_y;
+        int x_diff = lol.mx - prev_x;
+        
+//        uLCD.drawLine();
+        
+        lol.readMag();
+        
+        char buffer[50];
+        sprintf(buffer, "Heading: %d, %d, %d", lol.mx, lol.my, lol.mz);
+        
+        uLCD.text_string(buffer, 100, 10, 12, WHITE);
+        
+        wait(0.001);
+    }
+}
+
+int run_time_EC() {
+    set_time(1580736096);
+    
+    int center = (int)floor(127.0 / 2.0);
+    
+    while (1) {
+        time_t seconds = time(NULL);
+        
+        char buffer[50];
+        sprintf(buffer, "Time: %s", ctime(&seconds));
+        
+        uLCD.text_string(buffer, center, center, 24, RED);
     }
 }
\ No newline at end of file