shik kamo
/
color
a
Revision 0:3c7374cb5c3c, committed 2015-04-03
- Comitter:
- kamoshik
- Date:
- Fri Apr 03 15:10:03 2015 +0000
- Commit message:
- a
Changed in this revision
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 3c7374cb5c3c main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Apr 03 15:10:03 2015 +0000 @@ -0,0 +1,89 @@ +#include "mbed.h" + +#define ADDR 0x2A + + +DigitalOut myled(LED1); +DigitalOut myled2(LED2); +I2C i2c( p28, p27 ); +Serial pc(USBTX, USBRX); // tx, rx +//Serial device(p9, p10); // tx, rx + +unsigned int red = 0; +unsigned int green = 0; +unsigned int blue = 0; +unsigned int ir = 0; + + +void callback() { + // Note: you need to actually read from the serial to clear the RX interrupt + printf("%c\n", pc.getc()); + myled2 = !myled2; +} + +void GetRGB(){ + int databuf =0; + char cmd[2]; + char dat[8]; + int a =0; + /* //manual exposure mode + setManualtGain(100); + Wire.beginTransmission(device_address); + Wire.write(control_reg); + Wire.write(0x84); // ADC reset LowGain wakeup + Wire.endTransmission(false); + Wire.beginTransmission(device_address); + Wire.write(control_reg); + Wire.write(0x04); //start + Wire.endTransmission(true); + */ + + //preset gain mode exposure time (each color ch) + // 00 = 87.5us + // 01= 1.4ms + // 10= 22.4ms + // 11= 179.2ms + cmd[0] = 0x00; + cmd[1] = 0x8A; + // i2c.start(); + a = i2c.write(ADDR , cmd , 2); + cmd[0] = 0x00; + cmd[1] = 0x0A; + i2c.write(ADDR , cmd , 2); +// printf("b=%d",a); + + wait(0.1); + + cmd[0] = 0x03; + //i2c.start(); + a = i2c.write(ADDR , cmd , 1); + i2c.read(ADDR , dat , 8);//引数trueでNACK出力 + + + red = dat[0]<<8 | dat[1]; + green = dat[2]<<8 | dat[3]; + blue = dat[4]<<8 | dat[5]; + ir = dat[6]<<8 | dat[7]; + + +} + +int main() +{ + i2c.frequency(100000); + + //pc.attach(&callback); + pc.baud(115200); + // device.baud(115200); + while(1) { + myled = 1; + wait(0.25); + myled = 0; + wait(0.25); + + GetRGB(); + + pc.printf("R=%5d G=%5d B=%5d I=%5d\n",red,green,blue,ir); +// device.printf("12345\n"); + } +}
diff -r 000000000000 -r 3c7374cb5c3c mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Apr 03 15:10:03 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0 \ No newline at end of file