Assignment 5 for OCE360, timers, tickers, and interrupts.
Dependencies: 4DGL-uLCD-SE MMA8452Q SDFileSystem bouncing_ball mbed
Fork of OCE360_4 by
Diff: main.cpp
- Revision:
- 10:1fe988d4e61e
- Parent:
- 9:7a577d790538
- Child:
- 11:abfb94de3a41
diff -r 7a577d790538 -r 1fe988d4e61e main.cpp --- a/main.cpp Wed Nov 15 20:59:21 2017 +0000 +++ b/main.cpp Wed Nov 15 21:53:17 2017 +0000 @@ -21,6 +21,9 @@ #define LCD_UPDATE .091 //11 Hz +// Accelerometer - SDA, SCL, and I2C address +MMA8452Q accel(p28, p27, 0x1D); //initialize a driver object for an accelerometer connected on pins 27-28. + // Analog input (pin 15) AnalogIn tempin(p15); @@ -59,12 +62,11 @@ Timer logtimer; Ticker logticker; -void datarecord(){ - logtimer.start(); - fprintf(file, "Ball 1: %.3g X Position Y Position X Accleration Y Acceleration Temperature\n\r",logtimer.read(), - ball1.posx,ball1.posy,ball1.speedx,ball1.speedy,); - logtimer.reset(); - } +float voltage_in; +float degrees_c; + +FILE *file; +void datarecord(); //Function prototype for color selection function: int get_LCD_color(int color_integer); @@ -72,9 +74,6 @@ // Graphic LCD - TX, RX, and RES pins uLCD_4DGL uLCD(p9,p10,p11); //initialize a driver object for an LCD connected on pins 9-11 -// Accelerometer - SDA, SCL, and I2C address -MMA8452Q accel(p28, p27, 0x1D); //initialize a driver object for an accelerometer connected on pins 27-28. - physics_ball ball1; //initialize two balls for bouncing physics_ball ball2; //the default states from the library will be used initially @@ -142,7 +141,7 @@ if (recorder == 1){ //File Writing - FILE *file; + //FILE *file; file = fopen("/sd/ball_data.txt", "w"); if ( file == NULL ) { error("ERROR: Could not open file for writing!\n\r"); @@ -185,4 +184,30 @@ default: return(WHITE); } -} \ No newline at end of file +} + +void datarecord(){ + float time = 1*logtimer.read(); + float pos1x = 1*ball1.posx; + float pos1y = 1*ball1.posy; + float spe1x = 1*ball1.speedx; + float spe1y = 1*ball1.speedy; + float accx = 1*accel.readX(); + float accy = 1*accel.readY(); + + float pos2x = 1*ball2.posx; + float pos2y = 1*ball2.posy; + float spe2x = 1*ball2.speedx; + float spe2y = 1*ball2.speedy; + + + logtimer.start(); + voltage_in = tempin * 3.3; + degrees_c = (voltage_in - 0.5) * 100.0; + + fprintf(file, "Ball 1: %.3g %.3g %.3g %.3g %.3g %.3g %.3g %.3g\n\r",time,pos1x,pos1y,spe1x,spe1y,accx,accy,degrees_c); + + fprintf(file, "Ball 2: %.3g %.3g %.3g %.3g \n\r",pos2x,pos2y,spe2x,spe2y); + + logtimer.reset(); + } \ No newline at end of file