Dependencies:   ColorSensor mbed

Files at this revision

API Documentation at this revision

Comitter:
ryuna
Date:
Thu Sep 19 05:32:01 2013 +0000
Commit message:
colorsensor ver.1

Changed in this revision

ColorSensor.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 f07bfab0732b ColorSensor.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ColorSensor.lib	Thu Sep 19 05:32:01 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/ryuna/code/ColorSensor/#51fc088353e7
diff -r 000000000000 -r f07bfab0732b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 19 05:32:01 2013 +0000
@@ -0,0 +1,99 @@
+#include "mbed.h"
+#include "ColorSensor.h"
+
+void rivisedate ();
+void colordate ();
+void ptm(unsigned sum );
+
+
+unsigned short RGB[3],time1 = 20 ;
+unsigned rgb[3];
+double R,G,B,colorsum;
+double rir,rib ;
+
+DigitalOut led1(p21);
+DigitalOut led2(p22);
+DigitalOut led3(p23);
+ColorSensor color(p20,p17,p18,p19,time1);
+//ColorSensor color = ColorSensor();
+Serial pc(USBTX, USBRX); //tx,rx
+
+
+
+int main() {
+    short act = 0 , i = 0;    
+    while(1) {
+        i++;
+        led1 = 1;
+        if(act == 0){
+         rivisedate();
+         act = 1 ; 
+        }else if(act == 1){
+         colordate();
+         
+         pc.printf(" R %d  G %d  B %d  |||  %lf  %lf  %lf    %d\n",rgb[0],rgb[1],rgb[2],R,G,B,time1);
+        }
+        
+       /*if(i<=50){
+        led1 = 1;
+        led2 =0 ,led3 =0 ;
+       }else if((i>50)&&(i<=100)){
+        led2 = 1;
+        led1 =0 ,led3 =0 ;
+       }else if((i>100)&&(i<=150)) {
+        led3 = 1;
+        led1 =0 ,led2 =0 ; 
+       }else{
+        i=0;
+       }*/
+    }
+}
+
+void rivisedate (){
+    unsigned long red = 0,green = 0,blue =0;
+    unsigned short i ;
+    unsigned sum ;
+    for (i=0;i<=20;i++){
+     color.timenow(time1);
+     color.getRGB(RGB);
+     sum = RGB[0]+RGB[1]+RGB[2];
+     ptm(sum);
+     red += RGB[0] ;
+     green += RGB[1] ;
+     blue += RGB[2] ;
+     pc.printf(" %d  %d\n",time1,sum);
+    }
+    rir = (double)green/ red ;
+    rib = (double)green/ blue ;
+    
+}
+void colordate (){
+    color.getRGB(RGB) ;
+    colorsum = RGB[0]*rir + RGB[1] + RGB[2]*rib ;
+    R = RGB[0]*rir*100 / colorsum ;
+    G = RGB[1]*100 /colorsum ;
+    B = RGB[2]*rib*100 / colorsum ;
+    color.checkRGB(rgb[0],rgb[1],rgb[2]);      
+}
+ 
+ 
+ void ptm(unsigned sum){
+    //光の強度によって時間を決める
+    if( sum  <=500){
+        time1+= 8 ;
+    }else if((sum>500)&&(sum<=800)){
+        time1+= 5 ;
+    }else if((sum>800)&&(sum<=1300)){
+        time1+= 1 ;
+    }else if((sum>3000)&&(sum<=5000)){
+        time1-= 5 ;
+    }else if((sum>5000)&&(sum<=8000)){
+        time1-= 10 ;
+    }else if((sum>8000)&&(sum<=15000)){
+        time1-= 15 ;
+    }if(time1>=40){
+        time1-=20;
+    }else if(time1<=5){
+        time1+=5;
+    } 
+ }
\ No newline at end of file
diff -r 000000000000 -r f07bfab0732b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Sep 19 05:32:01 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9c8f0e3462fb
\ No newline at end of file