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:
- 8:2617100c441d
- Parent:
- 7:614b40b85579
- Child:
- 9:7a577d790538
diff -r 614b40b85579 -r 2617100c441d main.cpp --- a/main.cpp Thu Nov 09 16:01:24 2017 +0000 +++ b/main.cpp Tue Nov 14 14:20:06 2017 +0000 @@ -7,6 +7,7 @@ #include "MMA8452Q.h" //acceleromater library #include "uLCD_4DGL.h" //LCD library #include "bouncing_ball.h" //new ball phyics library +#include "SDFileSystem.h" #define UPDATE_TIME_S 0.02 #define START_X_1 10 @@ -24,6 +25,9 @@ //Initialize Serial communication Serial pc(USBTX, USBRX); +// SD card (SPI pins) +SDFileSystem sd(p5, p6, p7, p8, "sd"); + //Led Initialization DigitalOut led1(LED1); //update leds DigitalOut led2(LED2); @@ -33,13 +37,20 @@ InterruptIn button(p13); //Interrupt on the button on pin 13 Timer debounce; //defines debounce timer for proper switching +int recorder = 0; + void toggle(){ if(debounce.read_ms()>175){ led3=!led3; + recorder = !recorder; debounce.reset(); //restart timer after toggle occurs } } +//Position recorder +Timer logtime; + + //Function prototype for color selection function: int get_LCD_color(int color_integer); @@ -52,20 +63,6 @@ physics_ball ball1; //initialize two balls for bouncing physics_ball ball2; //the default states from the library will be used initially -//Ticker for logging -Ticker logger1; //ball 1 ticker (position log) -Ticker logger2; //ball 2 ticker (position log) - -void pos_log1(){ - pc.printf("Ball 1 (x): %i Ball 1 (y): %i \n\r",ball1.posx,ball1.posy); - //prints ball 1 position to terminal - } - -void pos_log2(){ - pc.printf("Ball 2 (x): %i Ball 2 (y): %i \n\r",ball2.posx,ball2.posy); - //prints ball 2 position to terminal - } - //Ticker for update Ticker update1; //ball 1 ticker for update position Ticker update2; //ball 2 ticker for update position @@ -89,7 +86,7 @@ uLCD.filled_circle(ball2.posx, ball2.posy, ball2.radius, get_LCD_color(ball2.color)); // Wait before erasing old circles: - wait(DRAW_UPDATE); // In seconds + 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); @@ -98,9 +95,6 @@ int main(){ - debounce.start(); //starts debounce timer - button.rise(&toggle); //toggles on button press - /* logger1.attach(&pos_log1, LCD_UPDATE); logger2.attach(&pos_log2, LCD_UPDATE); @@ -110,7 +104,7 @@ uLCD.baudrate(115200); uLCD.background_color(BLACK); uLCD.cls(); - + // Initialize accelerometer accel.init(); @@ -127,6 +121,10 @@ displayup.attach(&display,LCD_UPDATE); //ticker force lcd update + debounce.start(); //starts debounce timer + button.rise(&toggle); //toggles on button press + + while (1) { //execute 'forever' if (DEBUG_MODE) {