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
- Committer:
- Darstack
- Date:
- 2019-03-08
- Revision:
- 2:d168f964c331
- Parent:
- 1:334b40b47233
- Child:
- 3:3454cb7584e1
File content as of revision 2:d168f964c331:
#include "mbed.h" #include "scolor_TCS3200.h" /* ***************************************************************************** Programa que solicita telemetria al sistema embebido, por medio del comando 0xFe para preguntar por el color que detecta el sensor TCS3200 el sistema embebido recibe el inicio de trama FE y el número de comado: 01 | INITELE | CMD | | 0xfe | 0x01 | para enviar los comandos usar el programa Coolterm http://freeware.the-meiers.org/ @fabeltranm 2019 fbeltranm@ecci.edu.co ******************************************************************************** datasheet https://www.mouser.com/catalog/specsheets/TCS3200-E11.pdf S0 Frequency scaling S1 Frequency scaling S2 Photo diode selection S3 Photo diode selection OutFreq Frequency ----------------------------------- | ____________ ____________ | ----> | | | | | | ___ ___ Light | | Photodiode | | Current |--|---OUTPUT_FREQ | |___| |___ ----> | | Array |---| to | | | | | | Frequency | | | |____________| |____________| | | ^ ^ ^ ^ | -------|--|-------------|--|------- | | | | S2 S3 S0 S1 SO | S1 | OUTPUT FREQUENCY SCALING | | S2 | S3 | PHOTODIODE TYPE | 0 | 0 | power down | | 0 | 0 | Red | 0 | 1 | 2% | | 0 | 1 | Blue | 1 | 0 | 20% | | 1 | 0 | Clear (no filter) | 1 | 1 | 100% | | 1 | 1 | Green | ******************************************************************************/ #define INITELE 0xFE #define CMD 0x01 #define DO 1300 #define RE 1500 #define MI 1600 #define FA 1800 #define SO 2000 Serial command(USBTX, USBRX); // S0, S1, S2, S3, OUT scolor_TCS3200 scolor(PA_8, PB_10, PB_4, PB_5, PB_3); // definición de las funciones void setup_uart(); void leer_datos(); void leer_color(); uint8_t cmd; PwmOut mybuzzer(PA_10); int main() { setup_uart(); while(1){ leer_datos(); if (cmd==CMD){} leer_color(); } } void setup_uart(){ command.baud(115200); } void leer_datos(){ while(command.getc()!= INITELE); cmd=command.getc(); } void leer_color(){ mybuzzer.write(0); long red = scolor.ReadRed(); long green = scolor.ReadGreen(); long blue = scolor.ReadBlue(); long clear = scolor.ReadClear(); long frqred; long frqgreen; long frqblue; long frqclear; printf("RED: %5d GREEN: %5d BLUE: %5d CLEAR: %5d \n ", red, green, blue, clear); frqred = ( ( 1.0/red )* 1000.0 ); frqgreen = ( ( 1.0/green ) * 1000.0); frqblue = ( (1.0/blue) *1000.0 ); frqclear = ( (1.0/clear) *1000.0 ); printf("RED: %5d GREEN: %5d BLUE: %5d CLEAR: %5d \n ", frqred, frqgreen, frqblue); /////////////////////////////////////////////////////////////////////////////// /*||||||||||||||||Seleccionando los diferentes colores.||||||||||||||||||||||*/ /*||||||||||||||||||||||||||||||Color rojo|||||||||||||||||||||||||||||||||||*/ /////////////////////////////////////////////////////////////////////////////// if ( frqred >= 84.0 and frqred <= 105.0) { printf ( "entro al 1" ); if( frqgreen >= 0.0 and frqgreen <= 12.0 ) { printf ( "entro al 2" ); if ( 5.0 >= frqblue <= 21.0 ) { mybuzzer.period_us(DO); mybuzzer.write(0.5); wait(5); mybuzzer.write(0); printf ( "tiende a rojo" ); } } } //////////////////////////////////////////////////////////////////////////////// /*°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°Color verde°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°*/ /////////////////////////////////////////////////////////////////////////////// if ( frqgreen >= 57.0 and frqgreen <= 80.0) { printf ( "entro al 1" ); if( frqred >= 9.0 and frqred <= 27.0 ) { printf ( "entro al 2" ); if ( 8.0 >= frqblue <= 28.0 ) { mybuzzer.period_us(RE); mybuzzer.write(0.5); wait(5); mybuzzer.write(0); printf ( "tiende a verde" ); } } } //////////////////////////////////////////////////////////////////////////////// /*°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°Color azul°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°*/ /////////////////////////////////////////////////////////////////////////////// if ( frqblue >= 61.0 and frqblue <= 84.0) { printf ( "entro al 1" ); if( frqgreen >= 22.0 and frqgreen <= 43.0 ) { printf ( "entro al 2" ); if ( 0.0 >= frqred <= 6.0 ) { mybuzzer.period_us(MI); mybuzzer.write(0.5); wait(5); mybuzzer.write(0); printf ( "tiende a azul" ); } } } ///////////////////////////////////////////////////////////////////////////////// /*°°°°°°°°°°°°°°°°°°°°°°°°°°°°°Color amarillo°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°*/ //////////////////////////////////////////////////////////////////////////////// if ( frqblue >= 0.0 and frqblue <= 12.0 ) { printf ( "entro al 1" ); if( frqgreen >= 20.0 and frqgreen <= 60.0 ) { printf ( "entro al 2" ); if ( 0.0 >= frqred <= 6.0 ) { mybuzzer.period_us(FA); mybuzzer.write(0.5); wait(5); mybuzzer.write(0); printf ( "tiende a amarillo" ); } } } ///////////////////////////////////////////////////////////////////////////////// /*°°°°°°°°°°°°°°°°°°°°°°°°°°°°°Color no found°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°*/ //////////////////////////////////////////////////////////////////////////////// if ( frqclear >= 12.5 and frqclear <= 19.7 ) {} else { mybuzzer.period_us(DO); mybuzzer.write(0.5); wait(5); mybuzzer.write(0); printf( "Color no found" ); } }