roboforum.ruТехнический форум по робототехнике. |
|
|
byte cam_config [] [2] = (
(0x02, 0x00), / / Set Camera Active
(0x02, 0x40), / / Set Camera Reset
(0x03, 0x00), / / PLL
(0x02, 0x00), / / Set Camera Active
(0x0B, 0x00), / / White Line OFF
(0x58, 0x20), / / Exposure Time
(0x05, 0x80), / / Frame Rate Quarter (00) / Half (40) / Full (80)
(0x1A, 0xFF), / / HCOUNT = 0x3FF = 1023
(0x1B, 0xB3), / / VCOUNT = 0x21B = 539
(0x1C, 0xA1), / /
(0x11, 0x4A), / / Changed b / c of PICSIZE
(0x14, 0x23), / / Changed b / c of PICSIZE
(0x04, 0x0B), / / RGB 160x120 OUT ON
(0x1F, 0x0C), / / SPCOUNT = 0xBC3 = 3011 / / Doesn't match formula?
(0x1E, 0x23), / / SPCOUNT [7:0]
(0x0E, 0x00), / / According to the AppNote it should be 0xAC for this PICSIZE?
);
int i;
for (i = 0; i <sizeof (cam_config) / sizeof (cam_config [0]); i + +) (
Wire.beginTransmission (0x3D);
Wire.send (cam_config [i] [0]); Wire.send (cam_config [i] [1]);
Wire.endTransmission ();
)
if (WireExt.beginReception (0x3E)> = 0) (
unsigned long count;
(
byte header_count = 0;
while (header_count <4) (
buf = WireExt.get_byte ();
* ((Byte *) (& count) + header_count) = buf; / / Little Endian
header_count + +;
)
)
while (count -> 0) (
byte b = WireExt.get_byte ();
/ / Do something with b
)
WireExt.endReception ();
)
byte b_first, b_second;
byte r, g, b;
r = (b_first & 0x1F) <<3;
g = ((b_first & 0xE0)>> 3) | ((b_second & 0x07) <<5);
b = (b_second & 0xF8);
// I2C通信ライブラリを取り込む
#include <Wire.h>
#include <WireExt.h>
// カメラモジュールのアドレス設定
const int configAddress = 0x3D;
const int cameraAddress = 0x3E;
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
int loop_count;
void setup() {
Serial.begin(115200); //シリアル通信開始
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
// I2C通信開始
Wire.begin();
byte cam_config[][2] = {
{0x02, 0x00}, // Set Camera Active
{0x02, 0x40}, // Set Camera Reset
{0x03, 0x00}, // PLL
{0x02, 0x00}, // Set Camera Active
{0x0B, 0x00}, // White Line OFF
// {0x58, 0x20}, // Exposure Time - Original
{0x58, 0x10}, // Exposure Time
{0x6D, 0xA1}, // ABW_SW -> ON
{0x05, 0x80}, // Frame Rate Quarter(00)/Half(40)/Full(80)
{0x0D, 0x01}, // Optional ?
{0x1A, 0xFF}, // HCOUNT = 0x3FF = 1023
{0x1B, 0xB3}, // VCOUNT = 0x21B = 539
{0x1C, 0xA1}, //
{0x11, 0x4A}, // Changed b/c of PICSIZE
{0x14, 0x23}, // Changed b/c of PICSIZE
// {0x04, 0x0B}, // RGB 160x120 OUT ON - Original
{0x04, 0x0C}, // RGB 128x96 OUT ON
{0x1F, 0x0C}, // SPCOUNT = 0xBC3 = 3011 // Doesn't match formula?
{0x1E, 0x23}, // SPCOUNT[7:0]
{0x0E, 0x00}, // According to the AppNote it should be 0xAC for this PICSIZE?
};
int i;
for(i = 0; i < sizeof(cam_config) / sizeof(cam_config[0]); i++){
Wire.beginTransmission(configAddress);
Wire.send(cam_config[i][0]); Wire.send(cam_config[i][1]);
Wire.endTransmission();
}
loop_count = 0;
}
void loop() {
byte buf = 0;
if(loop_count < 4){
// 4枚は捨てる
if(WireExt.beginReception(cameraAddress) >= 0){
WireExt.endReception();
}
loop_count++;
return;
}
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
return;
}
if(WireExt.beginReception(cameraAddress) >= 0){
unsigned long count=0;
{
byte header_count = 0;
while(header_count < 4){
buf = WireExt.get_byte();
*((byte *)(&count) + header_count) = buf; // Little Endian
header_count++;
}
}
count/=2;
while(count-- > 0){
byte b_first, b_second;
b_first = WireExt.get_byte();
b_second = WireExt.get_byte();
byte r, g, b;
r = (b_first & 0x1F) << 3;
g = ((b_first & 0xE0) >> 3) | ((b_second & 0x07) << 5);
b = (b_second & 0xF8);
Serial.write(r);
Serial.write(g);
Serial.write(b);
}
WireExt.endReception();
}
// 処理のために少し待つ
//delay(1000);
}
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 11