Dependencies: mbed TCS3472_I2C
Revision 0:1bf2fc8e5f8e, committed 2019-04-22
- Comitter:
- m211080
- Date:
- Mon Apr 22 21:25:37 2019 +0000
- Commit message:
- Here is the working Color recognition code. Works 10/10 times.
Changed in this revision
diff -r 000000000000 -r 1bf2fc8e5f8e TCS3472_I2C.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TCS3472_I2C.lib Mon Apr 22 21:25:37 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/karlmaxwell67/code/TCS3472_I2C/#6d5bb4ad7d6e
diff -r 000000000000 -r 1bf2fc8e5f8e colort.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/colort.cpp Mon Apr 22 21:25:37 2019 +0000 @@ -0,0 +1,62 @@ +#include "mbed.h" +#include "TCS3472_I2C.h" + +TCS3472_I2C rgb_sensor( p9, p10 ); // Establish RGB sensor object +Serial pc(USBTX,USBRX); // Establish serial connection with computer + +PwmOut myled1(LED1); +PwmOut myled2(LED2); +PwmOut myled3(LED3); + +int main() +{ + rgb_sensor.enablePowerAndRGBC(); // Enable RGB sensor + rgb_sensor.setIntegrationTime(100); // Set integration time of sensor + + //pc.baud(921600); // Set Baud rate of serial connection + int rgb_data[4]; // declare a 4 element array to store RGB sensor readings + float PWMbrightness = 1.0; // float specifying brightness of LED (between 0.0 and 1.0) + + + rgb_sensor.enablePowerAndRGBC(); // Enable RGB sensor + rgb_sensor.setIntegrationTime(100); // Set integration time of sensor + rgb_sensor.getAllColors( rgb_data ); +// read the sensor to get red, green, and blue color data along with overall brightness + + while(1) { + + + rgb_sensor.enablePowerAndRGBC(); // Enable RGB sensor + rgb_sensor.setIntegrationTime(100); // Set integration time of sensor + rgb_sensor.getAllColors( rgb_data ); +// read the sensor to get red, green, and blue color data along with overall brightness + + // Print data to serial port + pc.printf( "unfiltered: %d, red: %d, green: %d, blue: %d \n\r", rgb_data[0], rgb_data[1], rgb_data[2], rgb_data[3]); + +//code for turning on leds coresponding to the color it is over + + + if((3000<rgb_data[0])&&(1000<rgb_data[2])){ + myled1 = 0; + myled2 = 1; + myled3 = 0; + printf("Green\n"); + + }else if((470>rgb_data[3])&&(rgb_data[2]<1000)){ + myled1 = 1; + myled2 = 0; + myled3 = 0; + printf("Red\n"); + + }else{ + myled1 = 0; + myled2 = 0; + myled3 = 1; + printf("Blue\n"); + } + + wait(0.1); + + }// end while +}// end main \ No newline at end of file
diff -r 000000000000 -r 1bf2fc8e5f8e mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Apr 22 21:25:37 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187 \ No newline at end of file