Equipo 3 - Examen

Dependencies:   mbed

main.cpp

Committer:
isaacross99
Date:
2019-11-05
Revision:
32:b229ddfa279f
Parent:
31:6c36768769ea

File content as of revision 32:b229ddfa279f:

#include "mbed.h"
AnalogIn ruido(A2);
DigitalIn boton1(PTC6);
DigitalOut led0(PTC16);
DigitalOut led1(PTC17);
DigitalOut led2(PTB9);
DigitalOut led3(PTA1);
DigitalOut led4(PTB23);
DigitalOut led5(PTA2);
DigitalOut led6(PTC2);
DigitalOut led7(PTC3);
DigitalOut led8(PTC12);
DigitalOut led9(PTC4);
DigitalOut led10(PTD0);
DigitalOut led11(PTD2);
DigitalOut led12(PTD3);
DigitalOut led13(PTD1);
DigitalOut led14(PTE25);
DigitalOut led15(PTE24);
Ticker invocador;
Serial pc(USBTX,USBRX);
void secuencia(){
         pc.printf("Ejecutando...");
         int i = 0, num = 0, posicion = 0;
         num = rand() % 7 + 8;
         for(i = 0; i < num; i++){
                led0 = 0;
                led1 = 0;
                led2 = 0;
                led3 = 0;
                led4 = 0;
                led5 = 0;
                led6 = 0;
                led7 = 0;
                led8 = 0;
                led9 = 0;
                led10 = 0;
                led11 = 0;
                led12 = 0;
                led13 = 0;
                led14 = 0;
                led15 = 0;
                posicion = rand() % 15 ;
                switch(posicion){
                    case 0: led0 = 1;
                    break;
                    case 1: led1 = 1;
                    break;
                    case 2: led2 = 1;
                    break;
                    case 3: led3 = 1;
                    break;
                    case 4: led4 = 1;
                    break;
                    case 5: led5 = 1;
                    break;
                    case 6: led6 = 1;
                    break;
                    case 7: led7 = 1;
                    break;
                    case 8: led8 = 1;
                    break;
                    case 9: led9 = 1;
                    break;
                    case 10: led10 = 1;
                    break;
                    case 11: led11 = 1;
                    break;
                    case 12: led12 = 1;
                    break;
                    case 13: led13 = 1;
                    break;
                    case 14: led14= 1;
                    break;
                    case 15: led15= 1;
                    break;
                    default: led15 = 1; 
                }  
                wait(0.1);  
            }
            led0 = 0;
                led1 = 0;
                led2 = 0;
                led3 = 0;
                led4 = 0;
                led5 = 0;
                led6 = 0;
                led7 = 0;
                led8 = 0;
                led9 = 0;
                led10 = 0;
                led11 = 0;
                led12 = 0;
                led13 = 0;
                led14 = 0;
                led15 = 0;
    }
int main(){
     led0 = 0;
                led1 = 0;
                led2 = 0;
                led3 = 0;
                led4 = 0;
                led5 = 0;
                led6 = 0;
                led7 = 0;
                led8 = 0;
                led9 = 0;
                led10 = 0;
                led11 = 0;
                led12 = 0;
                led13 = 0;
                led14 = 0;
                led15 = 0;
    srand(ruido.read_u16());
    invocador.attach(&secuencia, 10);
    secuencia();
    while(1){
        if(!boton1){
           secuencia();
           
        }
        /*else{
            
            }*/
    }
}

//num = rand() % 100;