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 0:adf05e1e08f1, committed 2018-10-06
- Comitter:
- sebasmartinez
- Date:
- Sat Oct 06 17:43:16 2018 +0000
- Commit message:
- Programa Sensor Color SCM
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r adf05e1e08f1 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sat Oct 06 17:43:16 2018 +0000
@@ -0,0 +1,142 @@
+#include "mbed.h"
+#include <Timer.h>
+#define COLOR_SIZE 5
+Serial command(USBTX, USBRX);
+DigitalIn button(USER_BUTTON);
+DigitalOut led(LED1);
+DigitalIn OUT(PC_0);//A5 BC1
+DigitalOut S0(PA_1);//A1 VD1
+DigitalOut S1(PC_3);//A2 NG
+DigitalOut S2(PC_1);//A4 BC2
+DigitalOut S3(PC_2);//A3 VD2
+unsigned int lectura(void);
+void borrar(void);
+Timer tiempo;
+
+ //Variables de Trabajo Colores identificados
+ int Rojo = 0;
+ int Azul = 0;
+ int Verde = 0;
+ int Amarillo = 0;
+ int Negro = 0;
+ int Blanco = 0;
+
+
+int main()
+{
+
+ //int time = 0;
+ //Variables de Lectura
+ unsigned int Red = 0;
+ unsigned int Blue = 0;
+ unsigned int Green = 0;
+
+ while(1){
+ S0 = 1;
+ S1 = 1;
+ //Leer Rojo
+ S2 = 0;
+ S3 = 0;
+ Red = lectura();
+ //Leer Azul
+ S2 = 0;
+ S3 = 1;
+ Blue = lectura();
+ //Leer Verde
+ S2 = 1;
+ S3 = 1;
+ Green = lectura();
+
+ command.printf("Red: %d, Green: %d, Blue: %d ",Red,Green,Blue);
+ wait(0.5);
+
+ if( Red <= 8 && Red >= 4 && Green <= 36 && Green >= 27 && Blue <= 21 && Blue >= 17 ){ // Limite Inferior && Limite Superior por R G B
+ //ROJO
+ Rojo++;
+ command.printf("R++ %i ",Rojo);
+
+ }else if( Red <= 46 && Red >= 35 && Green <= 25 && Green >= 18 && Blue <= 11 && Blue >= 5 ){
+ //AZUL
+ Azul++;
+ command.printf("Az++ %i ",Azul);
+
+ }else if( Red <= 27 && Red >= 20 && Green <= 12 && Green >= 8 && Blue <= 15 && Blue >= 10 ){
+ //VERDE
+ Verde++;
+ command.printf("V++ %i ",Verde);
+
+ }else if( Red <= 10 && Red >= 3 && Green <= 10 && Green >= 4 && Blue <= 13 && Blue >= 10 ){
+ //AMARILLO
+ Amarillo++;
+ command.printf("Am++ %i ",Amarillo);
+
+ }else if( Red <= 66 && Red >= 50 && Green <= 65 && Green >= 60 && Blue <= 45 && Blue >= 40 ){
+ //NEGRO
+ Negro++;
+ command.printf("N++ %i ",Negro);
+
+ }else if( Red <= 6 && Red >= 3 && Green <= 6 && Green >= 3 && Blue <= 6 && Blue >= 3 ){
+ //BLANCO
+ Blanco++;
+ command.printf("B++ %i ",Blanco);
+
+ }else{
+ //INDEFINIDO
+ command.printf("Nada ");
+
+ }
+ if( Rojo > COLOR_SIZE ){ //
+ //ROJO
+ command.printf("Rojo\n");
+ borrar();
+ }else if( Azul > COLOR_SIZE ){
+ //AZUL
+ command.printf("Azul\n");
+ borrar();
+ }else if( Verde > COLOR_SIZE ){
+ //VERDE
+ command.printf("Verde\n");
+ borrar();
+ }else if( Amarillo > COLOR_SIZE ){
+ //AMARILLO
+ command.printf("Amarillo\n");
+ borrar();
+ }else if( Negro > COLOR_SIZE ){
+ //NEGRO
+ command.printf("Negro\n");
+ borrar();
+ }else if( Blanco > COLOR_SIZE ){
+ //BLANCO
+ command.printf("Blanco\n");
+ borrar();
+ }else{
+ //INDEFINIDO
+ command.printf("Contando \n");
+ }
+ }
+}
+
+unsigned int lectura(void){
+ unsigned int Resultado = 0;
+ while(OUT){}
+ while(!OUT){}
+ while(OUT){}
+ tiempo.start();
+ while(!OUT){}
+ tiempo.stop();
+ Resultado = tiempo.read_us();
+ tiempo.reset();
+ return(Resultado);
+}
+void borrar(void){
+
+ Rojo = 0;
+ Azul = 0;
+ Verde = 0;
+ Amarillo = 0;
+ Negro = 0;
+ Blanco = 0;
+
+ return;
+ }
+
\ No newline at end of file
diff -r 000000000000 -r adf05e1e08f1 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Oct 06 17:43:16 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/a7c7b631e539 \ No newline at end of file