OCE360 HW#4 Solution Example
Dependencies: 4DGL-uLCD-SE MMA8452Q bouncing_ball mbed
Fork of OCE360_4 by
main.cpp@1:6b99ffa62cc8, 2017-10-24 (annotated)
- Committer:
- slicht
- Date:
- Tue Oct 24 12:34:19 2017 +0000
- Revision:
- 1:6b99ffa62cc8
- Parent:
- 0:8d3812068c6c
- Child:
- 2:552e6feb8709
Compiles and runs with physics in ball. Creates unmoving 10 radius ball in center.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
slicht | 1:6b99ffa62cc8 | 1 | // Demo for the uLCD-144-G2 and MMA8452Q 3-axis accelerometer |
slicht | 1:6b99ffa62cc8 | 2 | |
slicht | 0:8d3812068c6c | 3 | #include "mbed.h" |
slicht | 1:6b99ffa62cc8 | 4 | #include "MMA8452Q.h" |
slicht | 1:6b99ffa62cc8 | 5 | #include "uLCD_4DGL.h" |
slicht | 1:6b99ffa62cc8 | 6 | #include "bouncing_ball.h" |
slicht | 1:6b99ffa62cc8 | 7 | |
slicht | 1:6b99ffa62cc8 | 8 | #define INIT_RADIUS 10 |
slicht | 1:6b99ffa62cc8 | 9 | #define INIT_COLOR 1 |
slicht | 0:8d3812068c6c | 10 | |
slicht | 1:6b99ffa62cc8 | 11 | //#include "bouncing_ball.h" |
slicht | 1:6b99ffa62cc8 | 12 | |
slicht | 1:6b99ffa62cc8 | 13 | // Graphic LCD - TX, RX, and RES pins |
slicht | 1:6b99ffa62cc8 | 14 | uLCD_4DGL uLCD(p9,p10,p11); |
slicht | 1:6b99ffa62cc8 | 15 | |
slicht | 1:6b99ffa62cc8 | 16 | // Accelerometer - SDA, SCL, and I2C address |
slicht | 1:6b99ffa62cc8 | 17 | MMA8452Q accel(p28, p27, 0x1D); |
slicht | 1:6b99ffa62cc8 | 18 | |
slicht | 1:6b99ffa62cc8 | 19 | physics_ball ball1(INIT_COLOR,INIT_RADIUS); |
slicht | 0:8d3812068c6c | 20 | |
slicht | 0:8d3812068c6c | 21 | int main() { |
slicht | 1:6b99ffa62cc8 | 22 | |
slicht | 1:6b99ffa62cc8 | 23 | // Initialize uLCD |
slicht | 1:6b99ffa62cc8 | 24 | uLCD.baudrate(115200); |
slicht | 1:6b99ffa62cc8 | 25 | uLCD.background_color(BLACK); |
slicht | 1:6b99ffa62cc8 | 26 | uLCD.cls(); |
slicht | 1:6b99ffa62cc8 | 27 | |
slicht | 1:6b99ffa62cc8 | 28 | // Initialize accelerometer |
slicht | 1:6b99ffa62cc8 | 29 | accel.init(); |
slicht | 1:6b99ffa62cc8 | 30 | |
slicht | 1:6b99ffa62cc8 | 31 | //Initiailize ball |
slicht | 1:6b99ffa62cc8 | 32 | |
slicht | 1:6b99ffa62cc8 | 33 | // Make a ball "fall" in direction of accelerometer |
slicht | 1:6b99ffa62cc8 | 34 | while (1) { |
slicht | 1:6b99ffa62cc8 | 35 | |
slicht | 1:6b99ffa62cc8 | 36 | // Draw a red circle |
slicht | 1:6b99ffa62cc8 | 37 | uLCD.filled_circle((int)ball1.posx, (int)ball1.posy, ball1.radius, RED); |
slicht | 1:6b99ffa62cc8 | 38 | |
slicht | 1:6b99ffa62cc8 | 39 | // Wait before erasing old circle |
slicht | 1:6b99ffa62cc8 | 40 | wait(0.02); // In seconds |
slicht | 1:6b99ffa62cc8 | 41 | |
slicht | 1:6b99ffa62cc8 | 42 | // Erase old circle |
slicht | 1:6b99ffa62cc8 | 43 | uLCD.filled_circle((int)ball1.posx, (int)ball1.posy, ball1.radius, BLACK); |
slicht | 0:8d3812068c6c | 44 | } |
slicht | 1:6b99ffa62cc8 | 45 | } |