CatPot 2015-2016
/
Pr034_S11059
S11059-02DT
Diff: main.cpp
- Revision:
- 2:059b9459d344
- Parent:
- 1:eabfa27c9374
- Child:
- 3:7fd72fb29c34
--- a/main.cpp Tue Apr 14 07:28:02 2015 +0000 +++ b/main.cpp Tue Apr 14 09:10:39 2015 +0000 @@ -5,7 +5,7 @@ Serial pc(USBTX,USBRX); I2C Sensor(p28,p27); -#define DEVICE_ADDRESS 0x2A +#define DEVICE_ADDRESS 0x2A << 1 #define CONTROL_REG 0x00 #define TIMING_REG_H 0x01 #define TIMING_REG_L 0x02 @@ -22,9 +22,7 @@ ,TIMING_REG_L }; char ord[2]={}; -char data[2]={}; -char data_h[1]={}; -char data_l[1]={}; +char data[8]={}; void led_blink(){ Led=1; @@ -69,109 +67,39 @@ // 10= 22.4ms // 11= 179.2ms - /* - Sensor.start(); - - Val = Sensor.write(address&0xFE); - Val = Sensor.write(0x00); - Val = Sensor.write(0x84); - Sensor.stop(); - - Sensor.start(); + ord[0]=0x00; + ord[1]=0x89; + Val = !Sensor.write(address&0xFE, ord, 2, true); - Val = Sensor.write(address&0xFE); - Val = Sensor.write(0x00); - Val = Sensor.write(0x04); - - Sensor.stop(); + ord[0]=0x00; + ord[1]=0x09; + Val = !Sensor.write(address&0xFE, ord, 2); - wait_ms(180*4); //total exposure time - */ - - Sensor.start(); - - Val = Sensor.write(address&0xFE); - Val = Sensor.write(0x00); - Val = Sensor.write(0x89); - - //Sensor.stop(); - - Sensor.start(); - - Val = Sensor.write(address&0xFE); - Val = Sensor.write(0x00); - Val = Sensor.write(0x09); - - Sensor.stop(); - - - - - - Sensor.start(); - - Val = Sensor.write(address&0xFE); - Val = Sensor.write(0x03); - Val = Sensor.write(0x00); - - //Sensor.stop(); - - Sensor.start(); - - Val = Sensor.write(address&0xFE); - Val = Sensor.write(0x04); - Val = Sensor.write(0x00); - - Sensor.stop(); - - //wait_ms(5.6*4); //total exposure time + wait_ms(5.6*4); //total exposure time + //wait_ms(180*4); //total exposure time led_blink(); - - Sensor.start(); - - Val = Sensor.write(address&0xFE); - Val = Sensor.write(0x03); - - //Sensor.stop(); - - Sensor.start(); - - Val = Sensor.write(address|0x01); - //read data - data_h[0] = Sensor.read(false); - data_l[0] = Sensor.read(false); - - red = (uint8_t)(data_h[0])<<8 | (uint8_t)(data_l[0]); + ord[0]=0x03; + Val = !Sensor.write(address&0xFE, ord, 1, true); - data_h[0] = Sensor.read(false); - data_l[0] = Sensor.read(false); - - green = (uint8_t)(data_h[0])<<8 | (uint8_t)(data_l[0]); + Val = !Sensor.read(address|0x01, data, 8, true); - data_h[0] = Sensor.read(false); - data_l[0] = Sensor.read(false); - - blue = (uint8_t)(data_h[0])<<8 | (uint8_t)(data_l[0]); - - data_h[0] = Sensor.read(false); - data_l[0] = Sensor.read(true); - - IR = (uint8_t)(data_h[0])<<8 | (uint8_t)(data_l[0]); - - Sensor.stop(); + red = (uint8_t)(data[0])<<8 | (uint8_t)(data[1]); + green = (uint8_t)(data[2])<<8 | (uint8_t)(data[3]); + blue = (uint8_t)(data[4])<<8 | (uint8_t)(data[5]); + IR = (uint8_t)(data[6])<<8 | (uint8_t)(data[7]); return; } int main() { - //Sensor.frequency(10000); + Sensor.frequency(100000); Led=0; led_blink();