I-O DATA DEV2 / Mbed 2 deprecated game01

Dependencies:   mbed

Revision:
0:380869d1fc31
Child:
1:6e40bb2ed99c
diff -r 000000000000 -r 380869d1fc31 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Nov 08 12:15:44 2020 +0000
@@ -0,0 +1,117 @@
+#include "mbed.h"
+
+DigitalOut led(LED1);
+//InterruptIn event(USER_BUTTON);
+DigitalIn button(USER_BUTTON);
+RawSerial pc(PA_2, PA_3,115200 );
+
+
+
+char bdata[20][20]={
+ 2,2,2,2,2 ,2,2,2,2,2, 2,2,2,2,2 ,2,2,2,2,2,  
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,1, 1,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
+ 2,2,2,2,2 ,2,2,2,2,2, 2,2,2,2,2 ,2,2,2,2,2,  
+};
+  
+
+
+void cur_down()
+{
+        pc.printf("\033B");
+}
+
+void cur_up()
+{
+        pc.printf("\033A");
+}
+
+
+
+void cur_left()
+{
+        pc.printf("\033D");
+}
+
+void cur_right()
+{
+        pc.printf("\033C");
+}
+
+void cur_xy(int x,int y)
+{
+    pc.printf("\033[%d;%dH",y,x);
+}
+
+void clear_all()
+{
+    pc.printf("\033[2J\033[6m");//clear , under line
+    cur_xy(0,0);
+}
+
+void init_bd()
+{
+    int x;
+    int  y;
+    pc.printf("\033[2J");//clear 
+    for(y=0;y<20;y++) {
+        cur_xy(1,y+1);
+        for(x=0;x<20;x++) {
+            if (bdata[y][x]==2) pc.printf("H"); 
+            else if (bdata[y][x]==1) pc.printf("@"); 
+            else pc.printf(" ");
+        }
+    }
+}
+
+
+int main()
+{
+    int    i;
+    int    x;
+    int    y;
+    int    dx=1;
+    int    dy=1;
+
+    clear_all();
+    
+    pc.printf("\nStart example\n");
+    init_bd();
+    x=2;
+    y=0;
+    while(1) {  
+        if (y>=19) dy=-1;
+        if (x>=19) dx=-1;
+        if (y<=0) dy=1;
+        if (x<=0) dx=1;
+        x=x+dx;
+        y=y+dy;
+        cur_xy(x+1,y+1);
+        if (bdata[y][x]==1) {
+             bdata[y][x]=0;
+             pc.printf(" ");
+             pc.printf("\007");
+        }
+        wait(0.1f);
+        if (button==0) dx = -dx;
+
+    }  
+}
+
+