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.
Diff: main.cpp
- Revision:
- 0:1eada136b388
- Child:
- 1:d481b2912c2a
diff -r 000000000000 -r 1eada136b388 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Nov 19 02:13:11 2013 +0000 @@ -0,0 +1,73 @@ +#include "mbed.h" +#include "m3pi.h" + +DigitalOut sensorLED(p8); +I2C colorSensor(p28, p27); +//Serial bt(p13, p14); // tx, rx + +const int addr = 0x74; + +int main() { + + m3pi m3pi; + sensorLED = 1; + char cmd[1]; + + while(1) { + char result_low; + char result_high; + + //Red + cmd[0] = 0x40; + colorSensor.write(addr,cmd,1); + colorSensor.read(addr, cmd,1); + result_low = cmd[0]; + + cmd[0] = 0x41; + colorSensor.write(addr,cmd,1); + colorSensor.read(addr, cmd,1); + result_high = cmd[0]; + + int red = (result_high << 8) + result_low; + + //Green + cmd[0] = 0x42; + colorSensor.write(addr,cmd,1); + colorSensor.read(addr, cmd,1); + result_low = cmd[0]; + + cmd[0] = 0x43; + colorSensor.write(addr,cmd,1); + colorSensor.read(addr, cmd,1); + result_high = cmd[0]; + + int green = (result_high << 8) + result_low; + + //Blue + cmd[0] = 0x44; + colorSensor.write(addr,cmd,1); + colorSensor.read(addr, cmd,1); + result_low = cmd[0]; + + cmd[0] = 0x45; + colorSensor.write(addr,cmd,1); + colorSensor.read(addr, cmd,1); + result_high = cmd[0]; + + int blue = (result_high << 8) + result_low; + + // Print for debugging + + //bt.printf("R:%d",red); + //bt.printf("G:%d",green); + //bt.printf("B:%d",blue); + + m3pi.printf("R:%d",red); + wait(1.5); + m3pi.printf("G:%d",green); + wait(1.5); + m3pi.printf("B:%d",blue); + wait(1.5); + + } +}