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.
Revision 2:1c61db0b3207, committed 2019-03-07
- Comitter:
- stevencastro
- Date:
- Thu Mar 07 21:26:34 2019 +0000
- Parent:
- 1:334b40b47233
- Commit message:
- sensordecoloresfine
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Feb 28 22:33:57 2019 +0000 +++ b/main.cpp Thu Mar 07 21:26:34 2019 +0000 @@ -46,22 +46,34 @@ 1 | 1 | 100% | | 1 | 1 | Green | ******************************************************************************/ +#define INITCMD 0xFF // comando de sonido ff 01 3 +#define INITELE 0xFE // comando de sensor de colores fe 01 +#define CMD 0x01 // -#define INITELE 0xFE -#define CMD 0x01 +#define DO 104 +#define RE 153 +#define MI 166 +#define FA 184 +#define SO 205 Serial command(USBTX, USBRX); // S0, S1, S2, S3, OUT scolor_TCS3200 scolor(PA_8, PB_10, PB_4, PB_5, PB_3); +PwmOut mybuzzer(PB_9); // definición de las funciones -void setup_uart(); -void leer_datos(); -void leer_color(); + +void setup_uart(); // funcion conexion pc +void leer_datos(); // funcion de lectura de comandos HEX +void leer_color();// recepcion de la lectura de frecuencia del sensor + +void buzzer_on(uint8_t tono, uint8_t tiempo); uint8_t cmd; +uint8_t tono; // variable almacena la frecuencia del buzzer +uint8_t tiempo; // varable almacena los tiempos del buzzer leer_datos() int main() { @@ -70,20 +82,30 @@ leer_datos(); if (cmd==CMD){} leer_color(); + buzzer_on(tono, tiempo); } } void setup_uart(){ + command.baud(115200); + printf ("hola mundo sonido vicion"); + + } void leer_datos(){ + while(command.getc()!= INITELE); cmd=command.getc(); + while(command.getc()!= INITCMD); + tono=command.getc(); + tiempo=command.getc(); + } @@ -97,11 +119,46 @@ long blue = scolor.ReadBlue(); long clear = scolor.ReadClear(); - printf("RED: %5d GREEN: %5d BLUE: %5d CLEAR: %5d \n ", red, green, blue, clear); + //printf("RED: %5d GREEN: %5d BLUE: %5d CLEAR: %5d \n ", red, green, blue, clear); + + if (red < blue && green > blue && red < 35) + { + printf (" Rojo"); + } + else if (blue < red && blue < green && green < red) + { + printf (" Azul"); + } + else if (red > green && blue > green ) + { + printf(" Verde"); + } + else{ + printf(" "); + } + } - } + +void buzzer_on(uint8_t tono, uint8_t tiempo){ + +/* complementar el código necesario + */ - + mybuzzer.write(0); + switch(tono){ + case 1: mybuzzer.period_us(DO);break; + case 2: mybuzzer.period_us(RE);break; + case 3: mybuzzer.period_us(MI);break; + case 4: mybuzzer.period_us(FA);break; + default:mybuzzer.period_us(SO); break; + } + mybuzzer.write(0.5); + + wait(tiempo); + mybuzzer.write(0); + + +} \ No newline at end of file