Revision 0:b2eb0dabd8e4, committed 2009-12-09
- Comitter:
- Kaikestu
- Date:
- Wed Dec 09 13:36:09 2009 +0000
- Commit message:
Changed in this revision
diff -r 000000000000 -r b2eb0dabd8e4 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Dec 09 13:36:09 2009 +0000
@@ -0,0 +1,97 @@
+#include "mbed.h"
+#include "MobileLCD.h"
+
+MobileLCD lcd (5,6,7,12,13);
+AnalogIn left (20);
+AnalogIn right (19);
+
+int r;
+int le;
+
+int ball_x = 64;
+int ball_y = 64;
+int ball_tempX = 64;
+int ball_tempY = 64;
+int dir = 1 ;
+
+
+void moveBall(void);
+
+int main() {
+
+lcd.background(0x000000);
+ while(1) {
+lcd.cls();
+
+le = left * 100 + 8;
+r = right * 100 + 8;
+
+//center line
+lcd.fill(65,0,1,130,0xffffff);
+
+//left paddle
+lcd.fill(4,le,4,16,0xffffff);
+
+//right paddle
+lcd.fill(120,r,4,16,0xffffff);
+
+//ball
+moveBall();
+lcd.locate(3,5);
+lcd.printf("%.0f",dir);
+lcd.locate(3,7);
+lcd.printf("%.0f",le);
+ //wait(0.3);
+ }
+}
+
+void moveBall(){
+
+ ball_tempX = ball_x;
+ ball_tempY = ball_y;
+
+ if (dir == 1 && ball_x > 5 && ball_y > 5){
+
+ if( ball_x == 5 && ball_y >= le && ball_y <= le + 8){
+ dir = rand() % 2 + 3;
+ }else{
+ ball_x--;
+ ball_y--;
+ }
+
+ } else if (dir == 2 && ball_x > 30 && ball_y < 5){
+
+ if( ball_x == 6 && ball_y >= le && ball_y <= le + 8){
+ dir = rand() % 2 + 3;
+ }else{
+ ball_x--;
+ ball_y++;
+ }
+
+ } else if (dir == 3 && ball_x < 130 && ball_y > 5){
+
+ if( ball_x + 5 == 120 && ball_y >= r && ball_y <= r + 20){
+ dir = rand() % 1 + 2;
+ }else{
+ ball_x++;
+ ball_y--;
+ }
+
+ } else if (dir == 4 && ball_x < 130 && ball_y < 475){
+
+ if( ball_x + 5 == 120 && ball_y >= r && ball_y <= r + 20){
+ dir = rand() % 1 + 2;
+ }else{
+ ball_x++;
+ ball_y++;
+ }
+
+ } else {
+
+ if (dir == 1 || dir == 3) dir++;
+ else if (dir == 2 || dir == 4) dir--;
+
+ }
+
+lcd.fill (ball_x,ball_y,4,4,0xffffff);
+}
\ No newline at end of file
diff -r 000000000000 -r b2eb0dabd8e4 mbed.bld
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld Wed Dec 09 13:36:09 2009 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/cf0d45ce28a6