![](/media/cache/profiles/1225293648e26d9c5e54e22e92197cb4.jpg.50x50_q85.jpg)
Pong program with multiple dependencies to test pgen
Dependencies: Beep C12832 LM75B MMA7660 mbed
Revision 0:3bf62dd01ca9, committed 2015-08-14
- Comitter:
- sarahmarshy
- Date:
- Fri Aug 14 14:52:33 2015 +0000
- Commit message:
- Example of program with multiple dependencies to test pgen
Changed in this revision
diff -r 000000000000 -r 3bf62dd01ca9 Beep.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Beep.lib Fri Aug 14 14:52:33 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/shimniok/code/Beep/#3eb39e374fc3
diff -r 000000000000 -r 3bf62dd01ca9 C12832.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832.lib Fri Aug 14 14:52:33 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/askksa12543/code/C12832/#990d5eec2ef6
diff -r 000000000000 -r 3bf62dd01ca9 LM75B.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LM75B.lib Fri Aug 14 14:52:33 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/neilt6/code/LM75B/#7ac462ba84ac
diff -r 000000000000 -r 3bf62dd01ca9 MMA7660.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MMA7660.lib Fri Aug 14 14:52:33 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/MMA7660/#36a163511e34
diff -r 000000000000 -r 3bf62dd01ca9 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Aug 14 14:52:33 2015 +0000 @@ -0,0 +1,106 @@ +#include "mbed.h" +#include "LM75B.h" +#include "C12832.h" +#include "MMA7660.h" +#include "Beep.h" + + +// Using Arduino pin notation +C12832 lcd(D11, D13, D12, D7, D10); +//Accelerometer +MMA7660 MMA(D14,D15); +//Temp Sensor +LM75B sensor(D14,D15); +//Speaker +Beep beeper(D6); +//Red LED +PwmOut r (D5); +//Green LED +PwmOut g (D9); + +void pong(int ball_x, int y_pos){ + //bottom of the paddle + int bottom_y = y_pos+10; + //ball's y_location + int ball_y = 15; + //ball moving right + bool right = true; + //ball moving down + bool ball_down = true; + while(true) { + //refresh the position of ball and paddle + lcd.line(120, y_pos, 120, bottom_y, 1); + lcd.fillcircle(ball_x, ball_y, 3, 1); + wait(.03); + lcd.fillcircle(ball_x, ball_y, 3, 0); + lcd.line(120, y_pos, 120, bottom_y, 0); + + //check if the ball has hit the paddle + if(ball_x+3 == 120 && ball_y>y_pos && ball_y<bottom_y && right){ + right = false;//now it is moving left + beeper.beep(500, 0.25);//beep + r = 1.0;//turn off the red LED + g = 0.0;//turn on green + } + //check if the ball is behind the paddle + if(ball_x >= 124){ + right = false;//now it is moving left + beeper.beep(500, 0.25);//beep + g = 1.0;//turn off green LED + r = 0.0;//turn on red + } + //if it hits the left wall + if(ball_x<=3){ + right = true; + } + //if it hits the top or bottom + if(ball_y<=3 || ball_y >= 29){ + ball_down = not(ball_down);//reverse y direction + } + if(right){ + ball_x+=2;//increase ball's x pos by 2 if moving right + } + else{ + ball_x-=2;//decrease vy 2 if left + } + if(ball_down){ + ball_y++;//move ball's y pos down 1(higher y value's toward bottom of LCD) if the ball is moving down + } + else{ + ball_y--;//ball's y up 1 if ball moving up + } + //Check if accelerometer is tilted away and the paddle hasn't hit the top + if(MMA.x() > 0 && y_pos > 0){ + y_pos-=3;//top of paddle moved up by 3 + bottom_y = y_pos+10;//set the bottom of the paddle to 10 below top + } + else if(MMA.x() < 0 && y_pos < 21){//Check if accelerometer is tilted toward and the paddle hasn't hit the bottom + y_pos+=3;//top of paddle moves down 3 + bottom_y = y_pos+10;//bottom of the paddle is 10 pixels below top + } + } +} +int main() +{ + //Turn LEDs off + r = 1.0; + g = 1.0; + //clear the screen + lcd.cls(); + lcd.locate(0,3); + //Display the temp and countfown + lcd.printf("Temp = %.1f C\nPong will begin in: 3...\n",sensor.temp()); + wait(1); + lcd.cls(); + lcd.locate(0,3); + lcd.printf("Temp = %.1f C\nPong will begin in: 2...\n",sensor.temp()); + wait(1); + lcd.cls(); + lcd.locate(0,3); + lcd.printf("Temp = %.1f C\nPong will begin in: 1...\n",sensor.temp()); + wait(1); + lcd.cls(); + //start pong + pong(3,0); + +}
diff -r 000000000000 -r 3bf62dd01ca9 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Aug 14 14:52:33 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/cbbeb26dbd92 \ No newline at end of file