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.
main.cpp
- Committer:
- TaintedTruth
- Date:
- 2013-11-19
- Revision:
- 0:1eada136b388
- Child:
- 1:d481b2912c2a
File content as of revision 0:1eada136b388:
#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); } }