Digiti II
/
Guayabita
Proyecto_1 Digitales_II_Guayabita_3_Botones
Revision 13:c336fe797c5e, committed 2020-06-02
- Comitter:
- afroid
- Date:
- Tue Jun 02 05:32:28 2020 +0000
- Parent:
- 12:7fed07519f61
- Commit message:
- V3 sin auto-reset
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Jun 01 14:08:41 2020 +0000 +++ b/main.cpp Tue Jun 02 05:32:28 2020 +0000 @@ -3,48 +3,60 @@ #include <Serial.h> #include "mbed.h" #include "time.h" -BusOut segmen(D11, D10, PC_3, D15,D14,D12,PC_2);//En caso de usar un siete segmentos de 1 digito -DigitalIn Button(USER_BUTTON); // Boton de reset placa STM32F103 +BusOut segmen(D11, D10, PC_3, D15,D14,D12,PB_3); +DigitalIn random(PC_13); // 0 - presionado / 1 - Out +DigitalIn equal(D7); // 1 - presionado / 0 - Out +DigitalIn bet(D6) ; // 1 - presionado / 0 - Out DigitalOut myled(LED1); +DigitalOut win(PB_5); +DigitalOut lost(PB_4); const char seg[6]={ 0X30, 0X6D, 0X79, 0X33, 0X5B, 0X5F}; //Display 7segmentos con codigo Hexadecimal -int i = 0; int ran = 0; +int aux = 0; +int comparePrev = 0; +int comparePost = 0; + //0 = Down + //1 = Up - Equal int main() { -while (1){ - if(Button == 1){ - ran = rand() % 6; + while (1){ + if(random == 1 and equal == 0 and bet == 0){ + ran = rand() % 6; + segmen=seg[ran]; + myled = !myled; // Toggle the LED state + wait(0.1); // 200 ms + win = 0; + lost = 0; + + } + else if (random == 0 and equal == 0 and bet == 0 ){ + segmen=seg[ran]; - myled = !myled; // Toggle the LED state - wait(0.1); // 200 ms - - } else segmen=seg[ran]; - - - } + comparePrev = ran; + } + + else if (equal == 1 and random ==1 and bet == 0){ + aux = 1; + win = 1; + lost = 1; + myled = 1; + } + else if (bet == 1 and random == 1 and equal == 0){ + segmen = seg[ran]; + comparePost = ran; + if (aux == 1 and comparePost >= comparePrev ){ + win = 1; + } + else if(aux == 1 and comparePost < comparePrev) {//+ + lost = 1; + } + else if(aux == 0 and comparePost < comparePrev) {//+ + win = 1; + } + else if(aux == 0 and comparePost > comparePrev) { + lost = 1; + myled = 1; + } else lost = 1; + + } + } } -//BusOut segmen(D11, D13, PC_3, D15,D14,D12,PC_2);//En caso de usar un siete segmentos de 1 digito-PINES BLUE PILL -//BusOut myleds(); -- Pines de salida para el siete segmentos -//DigitalIn Button(PC_13); // Boton de reset placa STM32F103 - Nucleo-401RE -//DigitalOut Led1(LED1); -//Serial com(PA_9,PC_7);//Tx/Rx -->nucleo-401RE -- los mismos pines para la blue pill PA_10 y PB_10 -//const char seg[16]={0X7E, 0X30, 0X6D, 0X79, 0X33, 0X5B, 0X5F, 0X71, 0X7F, 0X73, 0X77, 0X1F, 0X4E, 0X3D, 0X4F, 0X47}; //Display 7segmentos con codigo Hexadecimal -//char numero=0; -//int main() { - //myleds=seg[numero]; - // segmen=seg[numero]; - // com.printf("Hola mundo\n\r"); - // wait_us(1000000); - // while (true){ - // if (!Button){ - // //for(numero=0;numero<16;numero++){ - // numero = rand()%6+1; - //myleds=seg[numero] ; - // segmen = seg [numero]; - // com.printf("numero: %d, 0X%02X \n\r",numero,seg[numero]); - // wait_us(50000); - // Led1=!Led1; - // //} - // } - // else segmen = seg[numero]; - // } -//} \ No newline at end of file