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 "scolor_TCS3200.h" 00003 00004 Serial command(USBTX, USBRX); 00005 PwmOut mybuzzer(D9); 00006 // S0, S1, S2, S3, OUT 00007 scolor_TCS3200 scolor(PA_8, PB_10, PB_4, PB_5, PB_3); 00008 00009 #define INITCMD 0xFE 00010 #define INITELE 0xFE 00011 #define CMD 0x01 00012 #define DO 100 00013 #define RE 150 00014 #define MI 200 00015 #define FA 250 00016 #define SO 300 00017 00018 uint8_t tono; // variable almacena la frecuencia del buzzer 00019 uint8_t tiempo; // varable almacena los tiempos del buzzer leer_datos() 00020 uint8_t cmd; 00021 00022 // definición de las funciones 00023 void setup_uart(); 00024 void buzzer_on(uint8_t tono); 00025 void leer_datos(); 00026 void leer_color(); 00027 00028 00029 00030 int main() { 00031 00032 setup_uart(); 00033 00034 while(1){ 00035 leer_datos(); 00036 if (cmd==CMD){ 00037 leer_color(); 00038 } 00039 } 00040 } 00041 00042 void setup_uart(){ 00043 command.baud(115200); 00044 } 00045 00046 00047 void leer_datos(){ 00048 cmd=command.getc(); 00049 } 00050 00051 00052 void leer_color(){ 00053 00054 long red = scolor.ReadRed(); 00055 long green = scolor.ReadGreen(); 00056 long blue = scolor.ReadBlue(); 00057 long clear = scolor.ReadClear(); 00058 long freqrojo; 00059 long freqverde; 00060 long freqazul; 00061 mybuzzer.write(0); 00062 freqrojo=((1.0/(2*red))*1000); 00063 freqverde=((1.0/(2*green))*1000); 00064 freqazul=((1.0/(2*blue))*1000); 00065 00066 if ( freqrojo>=0 and freqrojo <=7) // lee rojo 00067 { 00068 if (freqverde>=1200 and freqverde<=1500) 00069 { 00070 if ( freqazul>=1200 and freqazul <=1500) 00071 { 00072 00073 printf("|FE 01|\n"); 00074 mybuzzer.period_ms(DO); 00075 mybuzzer.write(0.5); 00076 wait_ms(4000); 00077 mybuzzer.write(0); 00078 00079 } 00080 } 00081 } 00082 00083 if ( freqrojo <=2700) // lee verde 00084 { 00085 if (freqverde>=900 and freqverde <=1500) 00086 { 00087 if ( freqazul>=1400 and freqazul <=2000) 00088 { 00089 00090 printf("|FE 03|\n"); 00091 mybuzzer.period_ms(RE); 00092 mybuzzer.write(0.5); 00093 wait_ms(4000); 00094 mybuzzer.write(0); 00095 00096 } 00097 } 00098 } 00099 00100 if ( freqrojo<=2400) // lee azul 00101 { 00102 if (freqverde>=800 and freqverde <=1000) 00103 { 00104 if ( freqazul>=600 and freqazul <=800) 00105 { 00106 00107 printf("|FE 02|\n"); 00108 mybuzzer.period_ms(MI); 00109 mybuzzer.write(0.5); 00110 wait_ms(4000); 00111 mybuzzer.write(0); 00112 00113 } 00114 } 00115 } 00116 if ( freqrojo <=700) // lee amarillo 00117 { 00118 if (freqverde>=500 and freqverde <=700) 00119 { 00120 if ( freqazul>=500 and freqazul<=1500) 00121 { 00122 00123 printf("|FE 04|\n"); 00124 mybuzzer.period_ms(FA); 00125 mybuzzer.write(0.5); 00126 wait_ms(4000); 00127 mybuzzer.write(0); 00128 00129 } 00130 } 00131 } 00132 00133 if ( freqrojo <=200) //No lee nada 00134 { 00135 if (freqverde <=300) 00136 { 00137 if ( freqazul <=300) 00138 { 00139 00140 printf("|FE 00|\n"); 00141 mybuzzer.period_ms(SO); 00142 mybuzzer.write(0.5); 00143 wait_ms(4000); 00144 mybuzzer.write(0); 00145 00146 } 00147 } 00148 } 00149 00150 // printf("RED: %5d GREEN: %5d BLUE: %5d CLEAR: %5d \n ", red, green, blue, clear); 00151 }
Generated on Tue Aug 2 2022 10:12:38 by
1.7.2