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.
Color.cpp@0:17f865015626, 2018-11-20 (annotated)
- Committer:
- Mario_Galeano
- Date:
- Tue Nov 20 01:45:51 2018 +0000
- Revision:
- 0:17f865015626
Programaci?n proyecto ara?a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mario_Galeano | 0:17f865015626 | 1 | #include "mbed.h" |
Mario_Galeano | 0:17f865015626 | 2 | |
Mario_Galeano | 0:17f865015626 | 3 | //*****************************************************************************// |
Mario_Galeano | 0:17f865015626 | 4 | // Distribucion pines sensor de color |
Mario_Galeano | 0:17f865015626 | 5 | |
Mario_Galeano | 0:17f865015626 | 6 | //DigitalOut S0(PA_12); // D2 | 0 0 POWER DOWN | 0 1 2% | 1 0 20% | 1 1 100% |
Mario_Galeano | 0:17f865015626 | 7 | //DigitalOut S1(PB_3); // D3 | 0 1 20% |
Mario_Galeano | 0:17f865015626 | 8 | DigitalIn Out(PA_7); // D11 | SALIDA SENSOR |
Mario_Galeano | 0:17f865015626 | 9 | DigitalOut S2(PA_6); // D12 | 0 0 RED | 0 1 BLUE | 1 0 ALL | 1 1 GREEN |
Mario_Galeano | 0:17f865015626 | 10 | DigitalOut S3(PA_5); // D13 | 0 0 RED | 0 1 BLUE | 1 0 ALL | 1 1 GREEN |
Mario_Galeano | 0:17f865015626 | 11 | |
Mario_Galeano | 0:17f865015626 | 12 | //*****************************************************************************// |
Mario_Galeano | 0:17f865015626 | 13 | // FUNCION AUXILIAR PARA LEER EL COLOR |
Mario_Galeano | 0:17f865015626 | 14 | |
Mario_Galeano | 0:17f865015626 | 15 | int readAux() |
Mario_Galeano | 0:17f865015626 | 16 | { |
Mario_Galeano | 0:17f865015626 | 17 | Timer Tiempo; |
Mario_Galeano | 0:17f865015626 | 18 | int inicial = 0, final = 0, resultado = 0; |
Mario_Galeano | 0:17f865015626 | 19 | |
Mario_Galeano | 0:17f865015626 | 20 | Tiempo.start(); |
Mario_Galeano | 0:17f865015626 | 21 | |
Mario_Galeano | 0:17f865015626 | 22 | while(Out == 1); |
Mario_Galeano | 0:17f865015626 | 23 | while(Out == 0); |
Mario_Galeano | 0:17f865015626 | 24 | while(Out == 1); |
Mario_Galeano | 0:17f865015626 | 25 | |
Mario_Galeano | 0:17f865015626 | 26 | inicial = Tiempo.read_us(); |
Mario_Galeano | 0:17f865015626 | 27 | |
Mario_Galeano | 0:17f865015626 | 28 | while (Out == 0); |
Mario_Galeano | 0:17f865015626 | 29 | |
Mario_Galeano | 0:17f865015626 | 30 | final = Tiempo.read_us(); |
Mario_Galeano | 0:17f865015626 | 31 | |
Mario_Galeano | 0:17f865015626 | 32 | resultado = (final - inicial); |
Mario_Galeano | 0:17f865015626 | 33 | return (resultado); |
Mario_Galeano | 0:17f865015626 | 34 | } |
Mario_Galeano | 0:17f865015626 | 35 | |
Mario_Galeano | 0:17f865015626 | 36 | //*****************************************************************************// |
Mario_Galeano | 0:17f865015626 | 37 | // FUNCION PARA LEER EL COLOR |
Mario_Galeano | 0:17f865015626 | 38 | |
Mario_Galeano | 0:17f865015626 | 39 | int readColor() |
Mario_Galeano | 0:17f865015626 | 40 | { |
Mario_Galeano | 0:17f865015626 | 41 | int rojo = 0, azul = 0, verde = 0; |
Mario_Galeano | 0:17f865015626 | 42 | int color; |
Mario_Galeano | 0:17f865015626 | 43 | |
Mario_Galeano | 0:17f865015626 | 44 | //S0.write(1); |
Mario_Galeano | 0:17f865015626 | 45 | //S1.write(1); |
Mario_Galeano | 0:17f865015626 | 46 | |
Mario_Galeano | 0:17f865015626 | 47 | S2.write(0); |
Mario_Galeano | 0:17f865015626 | 48 | S3.write(0); |
Mario_Galeano | 0:17f865015626 | 49 | rojo = readAux(); |
Mario_Galeano | 0:17f865015626 | 50 | |
Mario_Galeano | 0:17f865015626 | 51 | S2.write(0); |
Mario_Galeano | 0:17f865015626 | 52 | S3.write(1); |
Mario_Galeano | 0:17f865015626 | 53 | azul = readAux(); |
Mario_Galeano | 0:17f865015626 | 54 | |
Mario_Galeano | 0:17f865015626 | 55 | S2.write(1); |
Mario_Galeano | 0:17f865015626 | 56 | S3.write(1); |
Mario_Galeano | 0:17f865015626 | 57 | verde = readAux(); |
Mario_Galeano | 0:17f865015626 | 58 | |
Mario_Galeano | 0:17f865015626 | 59 | if (rojo < azul && verde > azul && rojo < 35) |
Mario_Galeano | 0:17f865015626 | 60 | { color = 1; } |
Mario_Galeano | 0:17f865015626 | 61 | |
Mario_Galeano | 0:17f865015626 | 62 | else if (azul < rojo && azul < verde && verde < rojo) |
Mario_Galeano | 0:17f865015626 | 63 | { color = 2; } |
Mario_Galeano | 0:17f865015626 | 64 | |
Mario_Galeano | 0:17f865015626 | 65 | else if (rojo < azul && azul > verde ) |
Mario_Galeano | 0:17f865015626 | 66 | { color = 3; } |
Mario_Galeano | 0:17f865015626 | 67 | |
Mario_Galeano | 0:17f865015626 | 68 | else |
Mario_Galeano | 0:17f865015626 | 69 | { color = 4; } |
Mario_Galeano | 0:17f865015626 | 70 | |
Mario_Galeano | 0:17f865015626 | 71 | return (color); |
Mario_Galeano | 0:17f865015626 | 72 | |
Mario_Galeano | 0:17f865015626 | 73 | } |