I-O DATA DEV2 / Mbed 2 deprecated game_tearm

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 DigitalOut led(LED1);
00004 //InterruptIn event(USER_BUTTON);
00005 DigitalIn button(USER_BUTTON);
00006 RawSerial pc(PA_2, PA_3,115200 );
00007 
00008 
00009 
00010 char bdata[20][20]={
00011  2,2,2,2,2 ,2,2,2,2,2, 2,2,2,2,2 ,2,2,2,2,2,  
00012  2,1,1,1,1 ,1,1,1,1,1, 1,1,1,1,1 ,1,1,1,1,2,  
00013  2,1,1,1,1 ,1,1,1,1,1, 1,1,1,1,1 ,1,1,1,1,2,  
00014  2,1,1,1,1 ,1,1,1,1,1, 1,1,1,1,1 ,1,1,1,1,2,  
00015  2,1,1,1,1 ,1,1,1,1,1, 1,1,1,1,1 ,1,1,1,1,2,  
00016  2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
00017  2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
00018  2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
00019  2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
00020  2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
00021  2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
00022  2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
00023  2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
00024  2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
00025  2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
00026  2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
00027  2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
00028  2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
00029  2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2, 
00030  2,2,2,2,2 ,2,2,2,2,2, 2,2,2,2,2 ,2,2,2,2,2,  
00031 };
00032   
00033 
00034 
00035 void cur_down()
00036 {
00037         pc.printf("\033B");
00038 }
00039 
00040 void cur_up()
00041 {
00042         pc.printf("\033A");
00043 }
00044 
00045 
00046 
00047 void cur_left()
00048 {
00049         pc.printf("\033D");
00050 }
00051 
00052 void cur_right()
00053 {
00054         pc.printf("\033C");
00055 }
00056 
00057 void cur_xy(int x,int y)
00058 {
00059     pc.printf("\033[%d;%dH",y,x);
00060 }
00061 
00062 void clear_all()
00063 {
00064     pc.printf("\033[2J\033[6m");//clear , under line
00065     cur_xy(0,0);
00066 }
00067 
00068 void init_bd()
00069 {
00070     int x;
00071     int  y;
00072     pc.printf("\033[2J");//clear 
00073     for(y=0;y<20;y++) {
00074         cur_xy(1,y+1);
00075         for(x=0;x<20;x++) {
00076             if (bdata[y][x]==2) pc.printf("H"); 
00077             else if (bdata[y][x]==1) pc.printf("@"); 
00078             else pc.printf(" ");
00079         }
00080     }
00081 }
00082 
00083 
00084 int main()
00085 {
00086     int    i;
00087     int    x;
00088     int    y;
00089     int    dx=1;
00090     int    dy=1;
00091 
00092     clear_all();
00093     
00094     pc.printf("\nStart example\n");
00095     init_bd();
00096     x=2;
00097     y=0;
00098     while(1) {  
00099         if (y>=20) dy=-1;
00100         if (x>=20) dx=-1;
00101         if (y<=1) dy=1;
00102         if (x<=1) dx=1;
00103         x=x+dx;
00104         y=y+dy;
00105         cur_xy(x,y);
00106 
00107         wait(0.1f);
00108         if (button==0) dx = -dx;
00109 
00110     }  
00111 }
00112 
00113