Kaitlyn Barros / Mbed 2 deprecated Barros_Assignment4

Dependencies:   4DGL-uLCD-SE MMA8452Q mbed physics_ball

Revision:
4:241bf0f0e626
Parent:
2:8085bd89612b
Child:
5:5b888a1a3b98
diff -r 8d36f5a81c0b -r 241bf0f0e626 main.cpp
--- a/main.cpp	Fri Nov 17 18:30:35 2017 +0000
+++ b/main.cpp	Thu Dec 07 23:20:55 2017 +0000
@@ -18,19 +18,15 @@
 #include "physics_ball.h"  // Physics Ball Behavior Header
 #include "uLCD_4DGL.h"     // LCD Header
 #include "MMA8452Q.h"      // Accelerometer Header
-#include "SDFileSystem.h"  // SD Card Header
-
-AnalogIn ain(p15);                     // Analog Input (pin 15) For Temp Sensor 
 
 Serial pc(USBTX, USBRX);               // USB Serial (tx, rx)
 
-SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD card (SPI pins)
-
 DigitalOut led1(LED1);                 //Onboard LED 1
 DigitalOut led2(LED2);                 //Onboard LED 2
 
 
-DigitalIn  switchinput(p12);            //Digital switch set in Pin 12
+DigitalIn  switchinput(p18);            //Digital switch set in Pin 18
+DigitalIn  AccelInter(p17);            //Digital switch caused by accelerometer INT1 pin
 
 // Call out classes (For Ball 1 & 2)
 physics_ball ball1;
@@ -42,21 +38,9 @@
 // Accelerometer - SDA, SCL, and I2C address
 MMA8452Q accel(p28, p27, 0x1D);
 
-
-// Call Out Variables
-int status = 0;    //"Logging" Status, i.e. 1 = Logging 0 - Not Logging
-float voltage_in;  //Temp Sensor 
-float degrees_c;   //Temp Sensor 
-int i;             //Temp Sensor 
-int c;             //Temp Sensor 
-
-// Timestamp Timer 
-Timer timer;
-
 // Call out Tickers 
 Ticker BallUpdate;
 Ticker LCDUpdate;
-Ticker Record;
 
 //Ticker Function 1: Ball_Update_Pos
 void BUP(){
@@ -67,6 +51,7 @@
 
 //Ticker Function 2: LCD_Update_Pos
 void LCDUP(){
+     if (switchinput == 0 || AccelInter == 1){
      // Draw new circle 
         uLCD.filled_circle(ball1.posx, ball1.posy, ball1.radius, BLUE); 
         uLCD.filled_circle(ball2.posx, ball2.posy, ball2.radius, RED); 
@@ -75,76 +60,21 @@
         uLCD.filled_circle(ball1.old_posx, ball1.old_posy, ball1.radius, BLACK);
         uLCD.filled_circle(ball2.old_posx, ball2.old_posy, ball2.radius, BLACK);
         led1= 0;
-
         }
-
-// Ticker Function 3: Record 
-void REC (){
-    
-//If the switch is pressed and the logging status is not logging, set the status to logging and turn the indicating LED on
-     if ((switchinput == 1) && (status == 0)) {
-        status = 1;
-        led2 = 1;
-        }
-        
-//If the switch is pressed and the logging status is logging, set the status to not logging and turn the indicating LED off    
-     if ((switchinput == 1) && (status == 1)) {
-        status = 0;
-        led2 = 0;
-        }
-   
-    if (status == 1){     
-    FILE *file;  //file descriptor
-
-    // Start our timer
-    timer.start();
-
-    // Open file for writing, if there is not a file with such a name, create one
-    file = fopen("/sd/BallData.txt", "w"); 
-    if ( file == NULL ) {
-        error("ERROR: Could not open file for writing!\n\r");
-    }
-
-    // Tell the user we need to wait while we collect some data
-    pc.printf("\nCollecting data (Do not remove SD Card!) ...\n\r");
-
-    // Collect Temperature
-        voltage_in = ain * 3.3;
-        degrees_c = (voltage_in - 0.5) * 100.0;
-        fprintf(file, "%2.2fs: %3.1f deg C\n\r", timer.read(), degrees_c);        
-    
-    // Collect Ball Data
-
-    
-    if (status == 0){
-    // Close file and re-open it for reading
-    fclose(file);
-    file = fopen("/sd/BallData.txt", "r");
-    if ( file == NULL ) {
-        error("ERROR: Could not open file for reading!\n\r");
-    }
-
-    // Print results to console
-    pc.printf("Temperature data:\n\r");
-    while(1) {
-       c = fgetc(file);
-       if ( c == EOF ) {
-           break;
-       }
-       pc.putc(c);
-    }
-
-    // Close the file and finish
-    fclose(file);
-    pc.printf("Done! Safe to remove SD card\n\r");
-    }
+    else if (switchinput ==1 || AccelInter == 0){
+        // Draw new circle 
+        uLCD.filled_circle(ball1.posx, ball1.posy, ball1.radius, BLUE); 
+        uLCD.filled_circle(ball2.posx, ball2.posy, ball2.radius, RED); 
+        led1 = 1;
+        wait(2);
+        // Erase old circle (For Ball 1 & 2)
+        uLCD.filled_circle(ball1.old_posx, ball1.old_posy, ball1.radius, BLACK);
+        uLCD.filled_circle(ball2.old_posx, ball2.old_posy, ball2.radius, BLACK);
+        led1= 0;
         }
             }
 
 int main() {
-   // pc.printf("I Print");     //Test: Make sure I can print to PC
-   // led1 = 1;                 //Test: Make sure led can turn on
-     
     // Initialize uLCD
     uLCD.baudrate(115200);
     uLCD.background_color(BLACK);
@@ -153,7 +83,7 @@
     // Initialize accelerometer
     accel.init();
      
-   //Intial Ball Conditions & Reset Conditiosn
+    //Intial Ball Conditions & Reset Conditiosn
     ball1.define_space(ball1.width, ball1.height);
     ball2.define_space(ball2.width, ball2.height);
     
@@ -161,9 +91,8 @@
     ball2.set_param(ball2.radius, RED);    
     
     //Tickers
-    Record.attach(&REC, 0.1);
     BallUpdate.attach(&BUP, 0.02); //50 Hz
-    LCDUpdate.attach(&LCDUP, 0.0909);//11 Hz 
-
-    while (1) { }
-      }
\ No newline at end of file
+    LCDUpdate.attach(&LCDUP, 0.09);//11 Hz 
+ 
+ while (1) { }
+ }
\ No newline at end of file