カラーセンサでRGBを判定する
Dependencies: TCS3472_I2C mbed
main.cpp
- Committer:
- kagari
- Date:
- 2017-10-05
- Revision:
- 0:2c40d2bf0863
File content as of revision 0:2c40d2bf0863:
#include "mbed.h" #include "TCS3472_I2C.h" TCS3472_I2C rgb_sensor( D4, D5 );//pins for I2C communication (SDA, SCL) int main() { rgb_sensor.enablePowerAndRGBC(); rgb_sensor.setIntegrationTime( 240 ); int rgb_readings[4]; while(1) { rgb_sensor.getAllColors( rgb_readings ); // // int R = (red_value / (float)clear_value) * 255; // int G = (green_value / (float)clear_value) * 255; // int B = (blue_value / (float)clear_value) * 255; // // pc.printf("AClear (%d), Red (%d), Green (%d), Blue (%d)\r\n", clear_value, R, G, B); int r = rgb_readings[1]; int g = rgb_readings[2]; int b = rgb_readings[3]; if( r > g && r > b){ printf("赤"); }else if(g > r && g > b){ printf("緑"); }else{ printf("青"); } printf( "red: %d, green: %d, blue: %d, clear: %d \r\n", rgb_readings[1], rgb_readings[2], rgb_readings[3], rgb_readings[0] ); wait_ms( 100 ); } }