Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of colorSensor by
main.cpp@2:6692f0d33ca2, 2013-09-04 (annotated)
- Committer:
 - OGA
 - Date:
 - Wed Sep 04 02:40:18 2013 +0000
 - Revision:
 - 2:6692f0d33ca2
 - Parent:
 - 1:86532e86498d
 
jum---
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| akudohune | 0:7269a89e1d57 | 1 | #include "mbed.h" | 
| akudohune | 0:7269a89e1d57 | 2 | #include "ColorSensor.h" | 
| akudohune | 0:7269a89e1d57 | 3 | |
| yusuke_robocup | 1:86532e86498d | 4 | ColorSensor color(p20, p17, p18, p19, 10); | 
| akudohune | 0:7269a89e1d57 | 5 | //ColorSensor color = ColorSensor(); | 
| akudohune | 0:7269a89e1d57 | 6 | Serial pc(USBTX, USBRX); // tx, rx | 
| akudohune | 0:7269a89e1d57 | 7 | |
| OGA | 2:6692f0d33ca2 | 8 | DigitalOut led[4] = {LED1,LED2,LED3,LED4}; | 
| OGA | 2:6692f0d33ca2 | 9 | DigitalOut air[2]={p21,p22}; | 
| OGA | 2:6692f0d33ca2 | 10 | |
| akudohune | 0:7269a89e1d57 | 11 | int main() | 
| akudohune | 0:7269a89e1d57 | 12 | { | 
| akudohune | 0:7269a89e1d57 | 13 | unsigned R, G, B; | 
| yusuke_robocup | 1:86532e86498d | 14 | double color_sum; | 
| yusuke_robocup | 1:86532e86498d | 15 | double redp,greenp,bluep; | 
| akudohune | 0:7269a89e1d57 | 16 | //pc.baud(115200); | 
| OGA | 2:6692f0d33ca2 | 17 | air[0] = 0; air[1] = 1; | 
| OGA | 2:6692f0d33ca2 | 18 | |
| akudohune | 0:7269a89e1d57 | 19 | while(1) | 
| akudohune | 0:7269a89e1d57 | 20 | { | 
| akudohune | 0:7269a89e1d57 | 21 | color.getRGB(R, G, B); | 
| yusuke_robocup | 1:86532e86498d | 22 | |
| yusuke_robocup | 1:86532e86498d | 23 | color_sum = (R * 0.65) + G + (B * 1.3); | 
| yusuke_robocup | 1:86532e86498d | 24 | |
| yusuke_robocup | 1:86532e86498d | 25 | redp = (double)(R * 0.65)/color_sum * 100; | 
| yusuke_robocup | 1:86532e86498d | 26 | greenp = (double)G/color_sum * 100; | 
| yusuke_robocup | 1:86532e86498d | 27 | bluep = (double)(B * 1.3)/color_sum * 100; | 
| yusuke_robocup | 1:86532e86498d | 28 | |
| OGA | 2:6692f0d33ca2 | 29 | pc.printf("R:%lf G:%lf B:%lf\n", redp, greenp, bluep); | 
| OGA | 2:6692f0d33ca2 | 30 | |
| OGA | 2:6692f0d33ca2 | 31 | |
| OGA | 2:6692f0d33ca2 | 32 | if(redp >= 55){ | 
| OGA | 2:6692f0d33ca2 | 33 | led[0] = 1; led[1] = 1; led[2] = 1; led[3] = 1; | 
| OGA | 2:6692f0d33ca2 | 34 | air[0] = 1; air[1] = 0; | 
| OGA | 2:6692f0d33ca2 | 35 | wait(0.5); | 
| OGA | 2:6692f0d33ca2 | 36 | led[0] = 0; led[1] = 0; led[2] = 0; led[3] = 0; | 
| OGA | 2:6692f0d33ca2 | 37 | air[0] = 0; air[1] = 1; | 
| OGA | 2:6692f0d33ca2 | 38 | wait(2); | 
| OGA | 2:6692f0d33ca2 | 39 | }else{ | 
| OGA | 2:6692f0d33ca2 | 40 | led[0] = 0; led[1] = 0; led[2] = 0; led[3] = 0; | 
| OGA | 2:6692f0d33ca2 | 41 | } | 
| OGA | 2:6692f0d33ca2 | 42 | |
| OGA | 2:6692f0d33ca2 | 43 | |
| akudohune | 0:7269a89e1d57 | 44 | /* | 
| akudohune | 0:7269a89e1d57 | 45 | switch(color.judge()){ | 
| akudohune | 0:7269a89e1d57 | 46 | case RED: pc.printf("RED\n"); break; | 
| akudohune | 0:7269a89e1d57 | 47 | case GREEN: pc.printf("GREEN\n"); break; | 
| akudohune | 0:7269a89e1d57 | 48 | case BLUE: pc.printf("BLUE\n"); break; | 
| akudohune | 0:7269a89e1d57 | 49 | default: break; | 
| akudohune | 0:7269a89e1d57 | 50 | } | 
| akudohune | 0:7269a89e1d57 | 51 | */ | 
| yusuke_robocup | 1:86532e86498d | 52 | //wait_ms(5); | 
| akudohune | 0:7269a89e1d57 | 53 | } | 
| akudohune | 0:7269a89e1d57 | 54 | } | 
