
Assignment 5 for OCE360, timers, tickers, and interrupts.
Dependencies: 4DGL-uLCD-SE MMA8452Q SDFileSystem bouncing_ball mbed
Fork of OCE360_4 by
Revision 9:7a577d790538, committed 2017-11-15
- Comitter:
- rsean10
- Date:
- Wed Nov 15 20:59:21 2017 +0000
- Parent:
- 8:2617100c441d
- Child:
- 10:1fe988d4e61e
- Commit message:
- SD Write partially working on interupt
Changed in this revision
--- a/SDFileSystem.lib Tue Nov 14 14:20:06 2017 +0000 +++ b/SDFileSystem.lib Wed Nov 15 20:59:21 2017 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/neilt6/code/SDFileSystem/#ecd09d0ed262 +https://os.mbed.com/users/neilt6/code/SDFileSystem/#5208d569cd5b
--- a/bouncing_ball.lib Tue Nov 14 14:20:06 2017 +0000 +++ b/bouncing_ball.lib Wed Nov 15 20:59:21 2017 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/slicht/code/bouncing_ball/#2c97532a9aa7 +https://os.mbed.com/users/slicht/code/bouncing_ball/#1e5cd98fc2aa
--- a/main.cpp Tue Nov 14 14:20:06 2017 +0000 +++ b/main.cpp Wed Nov 15 20:59:21 2017 +0000 @@ -20,7 +20,9 @@ #define DEBUG_MODE 0 #define LCD_UPDATE .091 //11 Hz -#define DRAW_UPDATE 0.075 + +// Analog input (pin 15) +AnalogIn tempin(p15); //Initialize Serial communication Serial pc(USBTX, USBRX); @@ -28,6 +30,12 @@ // SD card (SPI pins) SDFileSystem sd(p5, p6, p7, p8, "sd"); +//Drawing positions +int lastx1; +int lasty1; +int lastx2; +int lasty2; + //Led Initialization DigitalOut led1(LED1); //update leds DigitalOut led2(LED2); @@ -41,15 +49,22 @@ void toggle(){ if(debounce.read_ms()>175){ - led3=!led3; + led3= !led3; recorder = !recorder; debounce.reset(); //restart timer after toggle occurs } } //Position recorder -Timer logtime; +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(); + } //Function prototype for color selection function: int get_LCD_color(int color_integer); @@ -81,25 +96,24 @@ Ticker displayup; //ticker for displaying ball on lcd void display(){ + + // Erase old circles by writing over there locations using the screen color: + uLCD.filled_circle(lastx1, lasty1, ball1.radius, BLACK); + uLCD.filled_circle(lastx2, lasty2, ball2.radius, BLACK); + // Draw circles in the x and y positions stored by the ball objects: uLCD.filled_circle(ball1.posx, ball1.posy, ball1.radius, get_LCD_color(ball1.color)); uLCD.filled_circle(ball2.posx, ball2.posy, ball2.radius, get_LCD_color(ball2.color)); - - // Wait before erasing old circles: - wait(UPDATE_TIME_S); // In seconds - - // Erase old circles by writing over there locations using the screen color: - uLCD.filled_circle(ball1.posx, ball1.posy, ball1.radius, BLACK); - uLCD.filled_circle(ball2.posx, ball2.posy, ball2.radius, BLACK); + + //Sets previous ball position to be erased in next iteration + lastx1 = ball1.posx; + lasty1 = ball1.posy; + lastx2 = ball2.posx; + lasty2 = ball2.posy; } int main(){ - - /* - logger1.attach(&pos_log1, LCD_UPDATE); - logger2.attach(&pos_log2, LCD_UPDATE); - */ - + // Initialize uLCD uLCD.baudrate(115200); uLCD.background_color(BLACK); @@ -124,17 +138,34 @@ debounce.start(); //starts debounce timer button.rise(&toggle); //toggles on button press + while (1) { //execute 'forever' - while (1) { //execute 'forever' + if (recorder == 1){ + //File Writing + FILE *file; + file = fopen("/sd/ball_data.txt", "w"); + if ( file == NULL ) { + error("ERROR: Could not open file for writing!\n\r"); + return -1; + } + // Tell the user we need to wait while we collect some data + pc.printf("\nCollecting data (Do not remove SD Card!) ...\n\r"); + fprintf(file, " Time X Position Y Position X Accleration Y Acceleration Temperature\n\r"); + + pc.printf("\nData Recorded Sucessfully! \n\r"); + + // Close file + fclose(file); + } if (DEBUG_MODE) { //If compiled with DEBUG_MODE flag raised, print values to screen. uLCD.locate(0,4); uLCD.printf("X: %d.1\nY: %.1d",ball1.posx,ball1.posy); - + uLCD.locate(0,6); uLCD.printf("VX: %f.1\nVY: %.1f",ball1.speedx,ball1.speedy); - + uLCD.locate(0,10); uLCD.printf("AX: %f.1\nAY: %.1f\nAZ: %0.1f",accel.readX(),accel.readY(),accel.readZ()); }
--- a/mbed.bld Tue Nov 14 14:20:06 2017 +0000 +++ b/mbed.bld Wed Nov 15 20:59:21 2017 +0000 @@ -1,1 +1,1 @@ -https://mbed.org/users/mbed_official/code/mbed/builds/b484a57bc302 \ No newline at end of file +https://mbed.org/users/mbed_official/code/mbed/builds/a330f0fddbec \ No newline at end of file