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.
main.cpp@2:06cd11fab16b, 2020-04-28 (annotated)
- Committer:
- akumagame
- Date:
- Tue Apr 28 02:08:37 2020 +0000
- Revision:
- 2:06cd11fab16b
- Parent:
- 1:a103588e2d87
- Child:
- 3:5c5fdb28cdc0
d
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| akumagame | 0:e091e85bb254 | 1 | #include "mbed.h" |
| akumagame | 0:e091e85bb254 | 2 | #include <stdio.h> |
| akumagame | 0:e091e85bb254 | 3 | #include <stdlib.h> //incluye srand() y rand() |
| akumagame | 0:e091e85bb254 | 4 | #include <time.h> //incluye time() |
| akumagame | 0:e091e85bb254 | 5 | |
| akumagame | 1:a103588e2d87 | 6 | |
| akumagame | 1:a103588e2d87 | 7 | Serial com1(USBTX, USBRX); |
| akumagame | 0:e091e85bb254 | 8 | char mat[5][5]; //tamaño de la matriz |
| akumagame | 0:e091e85bb254 | 9 | char letras[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
| akumagame | 0:e091e85bb254 | 10 | int numdeletras=sizeof(letras)/sizeof(letras[0])-1; |
| akumagame | 1:a103588e2d87 | 11 | DigitalOut Ledrojo(PTB22); |
| akumagame | 1:a103588e2d87 | 12 | DigitalOut Ledazul(PTB21); |
| akumagame | 1:a103588e2d87 | 13 | DigitalOut Ledverde(PTE26) |
| akumagame | 1:a103588e2d87 | 14 | InterruptIn bot(PTA4); |
| akumagame | 0:e091e85bb254 | 15 | void funcion (); |
| akumagame | 0:e091e85bb254 | 16 | |
| akumagame | 0:e091e85bb254 | 17 | void funcion(void){ |
| akumagame | 0:e091e85bb254 | 18 | for (int i=0;i<5;i++)//para desplazarse por las columnas |
| akumagame | 0:e091e85bb254 | 19 | { |
| akumagame | 0:e091e85bb254 | 20 | for (int j=0;j<5;j++)//para desplazarse por las filas |
| akumagame | 0:e091e85bb254 | 21 | { |
| akumagame | 0:e091e85bb254 | 22 | mat[i][j]=letras[rand()%numdeletras];//Agrega numero aleatorio a la posicion ij de la matriz |
| akumagame | 1:a103588e2d87 | 23 | com1.printf("|\t%c|",mat[i][j]);//imprime elemento de la matriz en pantalla |
| akumagame | 0:e091e85bb254 | 24 | } |
| akumagame | 1:a103588e2d87 | 25 | com1.printf("\n_______________\n");//para dejar espacios entre filas. |
| akumagame | 0:e091e85bb254 | 26 | } |
| akumagame | 0:e091e85bb254 | 27 | getchar(); |
| akumagame | 0:e091e85bb254 | 28 | if (mat[2][2] >= 'a' && mat[2][2] <= 'z'){ |
| akumagame | 1:a103588e2d87 | 29 | com1.printf("La letra en la posicion 2,2 es minuscula\n \n \n \n"); |
| akumagame | 1:a103588e2d87 | 30 | Ledrojo=0; |
| akumagame | 1:a103588e2d87 | 31 | Ledazul=1; |
| akumagame | 1:a103588e2d87 | 32 | Ledverde=1 |
| akumagame | 0:e091e85bb254 | 33 | } |
| akumagame | 0:e091e85bb254 | 34 | else{ |
| akumagame | 1:a103588e2d87 | 35 | com1.printf("La letra en la posicion 2,2 es mayuscula\n \n \n \n "); |
| akumagame | 2:06cd11fab16b | 36 | Ledazul=1; |
| akumagame | 1:a103588e2d87 | 37 | Ledrojo=1; |
| akumagame | 2:06cd11fab16b | 38 | Ledverde=0; |
| akumagame | 0:e091e85bb254 | 39 | } |
| akumagame | 0:e091e85bb254 | 40 | } |
| akumagame | 0:e091e85bb254 | 41 | int main() |
| akumagame | 0:e091e85bb254 | 42 | { |
| akumagame | 1:a103588e2d87 | 43 | com1.printf("Este programa genera una matriz de 5x5 \n con letras de manera aleatoria, \n determina en la posicion 2,2 si es una \n letra mayuscula encendiendo un led\n azul o minuscula encendiendo \n un led rojo. Presioando el boton vuelve a \n generar otra matriz el programa\n y cada 60 segundos se reinicia.\n \n \n \n \n"); |
| akumagame | 0:e091e85bb254 | 44 | |
| akumagame | 1:a103588e2d87 | 45 | bot.rise(&funcion); |
| akumagame | 0:e091e85bb254 | 46 | |
| akumagame | 0:e091e85bb254 | 47 | while(1){ |
| akumagame | 0:e091e85bb254 | 48 | |
| akumagame | 0:e091e85bb254 | 49 | funcion(); |
| akumagame | 0:e091e85bb254 | 50 | |
| akumagame | 0:e091e85bb254 | 51 | wait(20); |
| akumagame | 0:e091e85bb254 | 52 | |
| akumagame | 0:e091e85bb254 | 53 | } |
| akumagame | 0:e091e85bb254 | 54 | } |