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
00001 #include "mbed.h" 00002 #include "stdio.h" 00003 #include "string.h" 00004 #include "TextLCD.h" 00005 00006 DigitalOut rojo(LED1); // R 00007 DigitalOut verde(LED2); // G 00008 DigitalOut azul(LED3); // B 00009 00010 Serial usart(PTA2,PTA1); //puertos del FRDM para el modem 00011 Serial pc(USBTX,USBRX); 00012 00013 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 00014 00015 Timer tiempo; // Variable para contar 00016 00017 int selector; 00018 00019 char buffer[4]; 00020 00021 int readBuffer(char *buffer,int count); 00022 void cleanBuffer(char *buffer, int count); 00023 int reconocerColor(char *buffer); 00024 00025 //esta funcion lee un bufer de datos 00026 int readBuffer(char *buffer,int count){ 00027 00028 int i=0; 00029 tiempo.start(); //CUENTA EL TIEMPO DE CONEXION E INICIA 00030 while(1) { 00031 while (usart.readable()) { 00032 char c = usart.getc(); 00033 if (c == '\r' || c == '\n') c = '%';//si se envia fin de linea o de caracxter inserta $ 00034 buffer[i++] = c;//mete al bufer el caracter leido 00035 if(i > count)break;//sale del loop si ya detecto terminacion 00036 } 00037 if(i > count)break; 00038 if(tiempo.read() > 0.5) { //MAS DE UN SEGUNDO DE ESPERA SE SALE Y REINICA EL RELOJ Y SE SALE 00039 tiempo.stop(); 00040 tiempo.reset(); 00041 break; 00042 } 00043 } 00044 return 0; 00045 } 00046 00047 //esta funcion limpia el bufer 00048 void cleanBuffer(char *buffer, int count){ 00049 00050 for(int i=0; i < count; i++) { 00051 buffer[i] = '\0'; 00052 } 00053 00054 } 00055 00056 int reconocerColor (char *buffer){ 00057 00058 int opcion; 00059 switch(buffer[0]){ 00060 case 'R': opcion = 1; break; 00061 case 'G': opcion = 2; break; 00062 case 'B': opcion = 3; break; 00063 case 'A': opcion = 4; break; 00064 default : opcion = 0; break; 00065 } 00066 return opcion; 00067 00068 } 00069 00070 int main() { 00071 00072 usart.baud(9600); 00073 usart.format(8,Serial::None,1); 00074 rojo = 1; 00075 verde = 1; 00076 azul = 1; 00077 00078 while(1){ 00079 00080 while (usart.readable()){ 00081 00082 readBuffer(buffer, 7); 00083 pc.printf("buffer= %s \n\r ",buffer); 00084 selector = reconocerColor(buffer); 00085 pc.printf("opcion= %u \n\r ",selector); 00086 switch(selector){ 00087 case 1: 00088 rojo = 0; verde = 1; azul =1; 00089 lcd.cls(); 00090 lcd.printf("ROJO\n"); 00091 break; 00092 case 2: 00093 rojo = 1; verde = 0; azul =1; 00094 lcd.cls(); 00095 lcd.printf("VERDE\n"); 00096 break; 00097 case 3: 00098 rojo = 1; verde = 1; azul =0; 00099 lcd.cls(); 00100 lcd.printf("AZUL\n"); 00101 break; 00102 case 4: 00103 rojo = 0; verde = 0; azul =0; 00104 lcd.cls(); 00105 lcd.printf("BLANCO\n"); 00106 break; 00107 default: break; 00108 } 00109 00110 } 00111 00112 } 00113 00114 } 00115 00116
Generated on Thu Jul 14 2022 03:39:08 by
1.7.2