Ryo Ogata
/
jumpROBO3_1
jumozisan
Fork of colorSensor by
Diff: main.cpp
- Revision:
- 1:86532e86498d
- Parent:
- 0:7269a89e1d57
- Child:
- 2:6692f0d33ca2
--- a/main.cpp Thu Aug 29 13:50:59 2013 +0000 +++ b/main.cpp Mon Sep 02 13:09:42 2013 +0000 @@ -1,18 +1,27 @@ #include "mbed.h" #include "ColorSensor.h" -ColorSensor color(p17, p18, p19, p20, 10); +ColorSensor color(p20, p17, p18, p19, 10); //ColorSensor color = ColorSensor(); Serial pc(USBTX, USBRX); // tx, rx int main() { unsigned R, G, B; + double color_sum; + double redp,greenp,bluep; //pc.baud(115200); while(1) { color.getRGB(R, G, B); - pc.printf("%4d %4d %4d\n", R, G, B); + + color_sum = (R * 0.65) + G + (B * 1.3); + + redp = (double)(R * 0.65)/color_sum * 100; + greenp = (double)G/color_sum * 100; + bluep = (double)(B * 1.3)/color_sum * 100; + + pc.printf("%lf %lf %lf\n", redp, greenp, bluep); /* switch(color.judge()){ case RED: pc.printf("RED\n"); break; @@ -21,6 +30,6 @@ default: break; } */ - wait_ms(500); + //wait_ms(5); } } \ No newline at end of file