カラーセンサでRGBを判定する

Dependencies:   TCS3472_I2C mbed

Files at this revision

API Documentation at this revision

Comitter:
kagari
Date:
Thu Oct 05 15:30:09 2017 +0000
Commit message:
????????;

Changed in this revision

TCS3472_I2C.lib Show annotated file Show diff for this revision Revisions of this file
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 2c40d2bf0863 TCS3472_I2C.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TCS3472_I2C.lib	Thu Oct 05 15:30:09 2017 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/Allar/code/TCS3472_I2C/#764a98777c11
diff -r 000000000000 -r 2c40d2bf0863 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 05 15:30:09 2017 +0000
@@ -0,0 +1,34 @@
+#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 );
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 2c40d2bf0863 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 05 15:30:09 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/235179ab3f27
\ No newline at end of file