Isaac Cruz
/
Examen-Equipo03
Equipo 3 - Examen
Revision 32:b229ddfa279f, committed 2019-11-05
- Comitter:
- isaacross99
- Date:
- Tue Nov 05 20:44:35 2019 +0000
- Parent:
- 31:6c36768769ea
- Commit message:
- Examen Equipo 3
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 6c36768769ea -r b229ddfa279f main.cpp --- a/main.cpp Thu Oct 31 04:24:05 2019 +0000 +++ b/main.cpp Tue Nov 05 20:44:35 2019 +0000 @@ -1,39 +1,129 @@ #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); -DigitalOut led0(PTD0); //Octavo pin (a partir del botón de RESET). -DigitalOut led1(PTC4); //Noveno pin. -DigitalOut led2(PTC12); //Decimo pin. -DigitalOut led3(PTC3); //Onceavo pin (inicia en el nuevo carril). -Timer crono; - +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 = 1; - led1 = 1; - led2 = 1; - led3 = 1; - crono.start(); - for(int i; i < 50; i++){ // Dado que la resolución es de 1.8 grados, se necesitan 200 pasos para completar un giro. - led0 = 0; - led1 = 1; - led2 = 0; - led3 = 1; - wait(0.1); - led0 = 0; - led1 = 1; - led2 = 1; - led3 = 0; - wait(0.1); - led0 = 1; - led1 = 0; - led2 = 1; - led3 = 0; - wait(0.1); - led0 = 1; - led1 = 0; - led2 = 0; - led3 = 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; + srand(ruido.read_u16()); + invocador.attach(&secuencia, 10); + secuencia(); + while(1){ + if(!boton1){ + secuencia(); + + } + /*else{ + + }*/ } - crono.stop(); - pc.printf("Tiempo de giro: %f seg", crono.read()); -} \ No newline at end of file +} + +//num = rand() % 100; \ No newline at end of file