Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 3:8a8ff76e84bc, committed 2018-11-18
- Comitter:
- sanchezzbrahian
- Date:
- Sun Nov 18 04:56:35 2018 +0000
- Parent:
- 2:15facba8b8b4
- Commit message:
- tetri y pinpo;
Changed in this revision
--- a/funcion_comun.h Sat Nov 17 04:44:57 2018 +0000 +++ b/funcion_comun.h Sun Nov 18 04:56:35 2018 +0000 @@ -9,6 +9,7 @@ double mx;//variable donde se guarda los voltajes leidos double my;//variable donde se guarda los voltajes leidos +double mx_old; void sendSPI(uint8_t d1, uint8_t d2)//envia datos a la tarjeta, cierra y abre puertos { @@ -25,7 +26,7 @@ sendSPI(0x09,0); //No decodificacion sendSPI(0x0B,0x07); //Usa 8 leds sendSPI(0x0C,1); //No se apaga - sendSPI(0x0A,0xe); + sendSPI(0x0A,0x3); for (int i=0;i<2;i++) { sendSPI(0x0F,1);
--- a/funcion_matriz.h Sat Nov 17 04:44:57 2018 +0000 +++ b/funcion_matriz.h Sun Nov 18 04:56:35 2018 +0000 @@ -43,11 +43,6 @@ mat_tmp1[i]= mat_tmp[i]; } } -void d_ale() - { - num=rand()%5+1; - mcol=4; - } void ingred_d() //Tipo de figuras { uint8_t tf=dat[0]; @@ -76,13 +71,41 @@ void mover_fig()//mueve la figura por medio de botones { analogo(); - - if(my>0.8) + + + if(mx<0.1) + { + int temp1 = mat_tmp[i+1]&(0x01); + if(temp1==0) + { + for(int i=0;i<7;i++) + { + mat_tmp[i]=mat_tmp[i]>>1; + } + } + } //mover figura a la derecha + + if(mx>0.9) + { + int temp2 = mat_tmp[i+2]&(0x80); + if(temp2==0) + { + for(int i=0;i<7;i++) + { + mat_tmp[i]=mat_tmp[i]<<1; + } + }//mover figura a la izquierda + } + } + +void rotar_fig() +{ + analogo(); + if(my>0.6) { grad++; if(grad<5) { - switch (grad) { case 1: @@ -111,45 +134,25 @@ { grad=0; } - } - if(mx<0.3) - { - int temp1 = mat_tmp[i+1]&(0x01); - if(temp1==0) - { - for(int i=0;i<7;i++) - { - mat_tmp[i]=mat_tmp[i]>>1; - } - } - } //mover figura a la derecha - - if(mx>0.8) - { - int temp2 = mat_tmp[i+2]&(0x80); - if(temp2==0) + } +} + +void act_matrix(uint8_t*temp)//Evalua figura guardada y su espacio +{ + for (int i=0;i<9;i++) + { + save=*(temp+2)& mat_act[i]; + if (save==0 ) { - for(int i=0;i<7;i++) - { - mat_tmp[i]=mat_tmp[i]<<1; //mover izquierda - } - }//mover figura a la izquierda - } -} -void act_matrix(uint8_t* temp)//Evalua figura guardada y su espacio -{ - for (int i=0;i<9;i++){ - save=*(temp+2)& mat_act[i]; - if (save==0 ) - { - fila=i+1; - } - if (save!=0) - { - fila=i; - i=9; - } - } + fila=i+1; + } + if (save!=0) + { + fila=i; + i=9; + } + } + } void guardar_mat(uint8_t *temp)//guarda la matriz @@ -157,10 +160,20 @@ mat_act[fila-3]=(*(temp+0))| mat_act[fila-3]; mat_act[fila-2]=(*(temp+1))| mat_act[fila-2]; mat_act[fila-1]=(*(temp+2))| mat_act[fila-1]; + }; +void most_fail() +{ + + if(j+1==7){ + mat_act[i] = 0x00; + mat_act[i+1] = 0x00;} + + +} void elim_lin() { - for(int i=0;i<9;i++){ + for(i=0;i<9;i++){ if(mat_act[i]==255){ for(uint8_t a=i;a>=1;a--){ sendSPI(a,mat_act[a-1]);
--- a/main.cpp Sat Nov 17 04:44:57 2018 +0000 +++ b/main.cpp Sun Nov 18 04:56:35 2018 +0000 @@ -4,7 +4,7 @@ #include "funcion_pinpon.h" #include "funcion_matriz.h" -//Ticker inter(); +Ticker inter; int main() { @@ -52,6 +52,7 @@ case 2://contenido del juego de tetris borrar(); + inter.attach(&mover_fig,0.18); while(1) { while(read_command()==0); @@ -60,13 +61,14 @@ for (cont=0;cont<fila;cont++) { analogo(); - //inter.attach(&mover_fig, 5); + rotar_fig(); mover_fig(); act_matrix(mat_tmp); imp_mat(mat_tmp); wait_ms(500); } guardar_mat(mat_tmp); + most_fail(); elim_lin(); } }