I have a camera and i wana program it , but i don't understand very well the code so can you explain me this ?
/* Linksprite : the name of camera */
#include <NewSoftSerial.h>
byte incomingbyte; // what is this ?
NewSoftSerial mySerial(4,5); //Configure pin 4 and 5 as soft serial port , so for arduino leonardo i have to write "mySerial(0,1)" because tx>pin 0 and rx>pin 1
int a=0x0000,j=0,k=0,count=0; //Read Starting address , what is this to ?
uint8_t MH,ML; // what is this ?
boolean EndFlag=0; // this is for test no ?
void SendResetCmd(); // this is functions who is declared in <NewSoftSerial.h> ?
void SendTakePhotoCmd(); // what's their functions ?
void SendReadDataCmd();
void StopTakePhotoCmd();
void setup()
{
Serial.begin(19200); // can i write "Serial.begin(9600);" ?
mySerial.begin(38400);
}
void loop()
{
SendResetCmd();
delay(4000); //After reset, wait 2-3 second to send take picture command
SendTakePhotoCmd();
while(mySerial.available()>0)
{
incomingbyte=mySerial.read();
}
byte a[32]; // what does that mean ?
while(!EndFlag) // what does that mean ?
{
j=0;
k=0;
count=0;
SendReadDataCmd();
delay(25);
while(mySerial.available()>0)
{
incomingbyte=mySerial.read();
k++;
if((k>5)&&(j<32)&&(!EndFlag))
{
a[j]=incomingbyte;
if((a[j-1]==0xFF)&&(a[j]==0xD9)) //Check if the picture is over
EndFlag=1;
j++;
count++;
}
}
for(j=0;j<count;j++)
{ if(a[j]<0x10)
Serial.print("0");
Serial.print(a[j],HEX);
Serial.print(" ");
} //Send jpeg picture over the serial port
Serial.println();
}
while(1);
}
//Send Reset command
void SendResetCmd()
{
mySerial.print(0x56, BYTE);
mySerial.print(0x00, BYTE);
mySerial.print(0x26, BYTE);
mySerial.print(0x00, BYTE);
}
//Send take picture command
void SendTakePhotoCmd()
{
mySerial.print(0x56, BYTE);
mySerial.print(0x00, BYTE);
mySerial.print(0x36, BYTE);
mySerial.print(0x01, BYTE);
mySerial.print(0x00, BYTE);
}
//Read data
void SendReadDataCmd()
{
MH=a/0x100;
ML=a%0x100;
mySerial.print(0x56, BYTE);
mySerial.print(0x00, BYTE);
mySerial.print(0x32, BYTE);
mySerial.print(0x0c, BYTE);
mySerial.print(0x00, BYTE);
mySerial.print(0x0a, BYTE);
mySerial.print(0x00, BYTE);
mySerial.print(0x00, BYTE);
mySerial.print(MH, BYTE);
mySerial.print(ML, BYTE);
mySerial.print(0x00, BYTE);
mySerial.print(0x00, BYTE);
mySerial.print(0x00, BYTE);
mySerial.print(0x20, BYTE);
mySerial.print(0x00, BYTE);
mySerial.print(0x0a, BYTE);
a+=0x20; //address increases 32£¬set according to buffer size
}
void StopTakePhotoCmd()
{
mySerial.print(0x56, BYTE);
mySerial.print(0x00, BYTE);
mySerial.print(0x36, BYTE);
mySerial.print(0x01, BYTE);
mySerial.print(0x03, BYTE);
}
PS : i know that BYTE is not supported so i hate to change for example mySerial.print(0x56, BYTE); to mySerial.write(0x56);
Please help me i have to finish this project quickly .
Thanks.