Updated OCE 360 Assignment 4
Dependencies: 4DGL-uLCD-SE MMA8452Q mbed physics_ball
Diff: main.cpp
- Revision:
- 0:2067ba6c5e74
- Child:
- 2:8085bd89612b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Oct 31 14:51:28 2017 +0000 @@ -0,0 +1,85 @@ +//Kaitlyn Barros +//OCE 360 Fall 2017 + +//Last Revised: Oct 30 2017 + +//Software Exercise: +//1. Update the software system by creating a new library, which includes +// a class that defines the behavior of a bouncing ball on the LCD screen. +//2. Demonstrate the system with two or more bouncing balls on the screen. +//3. Show that the system resets the ball locations when you hold the +// accelerometer upside down. + +#include "mbed.h" +#include "physics_ball.h" +#include "uLCD_4DGL.h" +#include "MMA8452Q.h" + +#define DEFAULT 64 +#define STEP 0.1 + +// Graphic LCD - TX, RX, and RES pins +uLCD_4DGL uLCD(p9,p10,p11); + +// Accelerometer - SDA, SCL, and I2C address +MMA8452Q accel(p28, p27, 0x1D); + +int main() { + + // Initialize uLCD + uLCD.baudrate(115200); + uLCD.background_color(BLACK); + uLCD.cls(); + + // Initialize accelerometer + accel.init(); + + // Call out classes (For Ball 1 & 2) + physics_ball ball1; + physics_ball ball2; + + //Intial Ball Conditions + ball1.posx = DEFAULT; + ball1.posy = DEFAULT; + + ball2.posx = DEFAULT /2; + ball2.posy = DEFAULT /2; + + ball1.define_space(ball1.width, ball1.height); + ball2.define_space(ball2.width, ball2.height); + + ball1.set_param(ball1.radius, BLUE); + ball2.set_param(ball2.radius, RED); + + // Make a ball "fall" in direction of accelerometer + while (1) { + + // Draw a circle (For Ball 1 & 2) + uLCD.filled_circle(ball1.posx, ball1.posy, ball1.radius, BLUE); + uLCD.filled_circle(ball2.posx, ball2.posy, ball2.radius, RED); + + // Wait before erasing old circle + wait(0.02); // In seconds + + // Erase old circle (For Ball 1 & 2) + uLCD.filled_circle(ball1.posx, ball1.posy, ball1.radius, BLACK); + uLCD.filled_circle(ball2.posx, ball2.posy, ball2.radius, BLACK); + + //Update Postions + ball1.update(STEP, accel); + ball2.update(STEP, accel); + + // Reset when sensor is flipped upside down (For Ball 1 & 2) + if (accel.readZ() < 0){ + uLCD.locate(5,6); + uLCD.color(RED); + uLCD.printf("GAME RESET"); + wait(2); + uLCD.cls(); + + ball1.set_state(DEFAULT, DEFAULT, 25, 25); + ball2.set_state(DEFAULT /2, DEFAULT /2, 25, 25); + wait (1); //Wait 1 second + } + } + } \ No newline at end of file