comprei um sensor RGB aqui na loja do ldg...
estou com dificuldades pra fazer o bicho funcionar... 
Alguém ja usou o mesmo???? 

 

Exibições: 477

Responder esta

Respostas a este tópico

Usei um da mesma linha, o ADJD-S371 com 8051 a um tempo, as rotinas ficaram assim:

O projeto não foi pra frente, posso até passar ele inteiro..

#define Gain 0x5

#define cos30 0.8660254
#define sen30 0.5
#define Fator 0.5*0.135847058824
#define CPreto 0
#define CCinza 1
#define CBranco 2
#define CAzul 3
#define CVerde 4
#define CCiano 5
#define CAmarelo 6
#define CLaranja 7
#define CVermelho 8
#define CRoxo 9

void adjd_init(void)
{
int i;
LigaCor=1;
for (i=0; i!=100;i++) PCON|=1;
if (temavago==1)
{
RST =0;
for (i=0; i!=1000;i++);
RSTLecor=1;
for (i=0; i!=5000;i++);
EEPROM_ByteWrite(CAP_RED, 0x02);
EEPROM_ByteWrite(CAP_GREEN, 0x02);
EEPROM_ByteWrite(CAP_BLUE, 0x02);
EEPROM_ByteWrite(CAP_CLEAR, 0x02);

EEPROM_ByteWrite(INT_RED_LO, 0xC4);
EEPROM_ByteWrite(INT_RED_HI, Gain);
EEPROM_ByteWrite(INT_GREEN_LO, 0xC4);
EEPROM_ByteWrite(INT_GREEN_HI, Gain);
EEPROM_ByteWrite(INT_BLUE_LO, 0xC4);
EEPROM_ByteWrite(INT_BLUE_HI, Gain+2);
EEPROM_ByteWrite(INT_CLEAR_LO, 0xC4);
EEPROM_ByteWrite(INT_CLEAR_HI, 0x02);
LigaCor=0;

}
}

void defcor(void)
{ unsigned int i;
i=30*CorR;
i/=400;
CVLum=i;
i=59*CorG;
i/=400;
CVLum+=i;
i=11*CorB;
i/=400;
CVLum+=i;
Brilho=CVLum;
Vx=60 + (CorG*cos30*Fator)- (CorR*cos30*Fator);
Vy= 70-(CorB*Fator)+
(CorR*sen30*Fator)+
(CorG*sen30*Fator);
if (Vy==70.0) Vy=69.0;
VDy=-(Vy-70.0);
VDx=Vx;
VDx-=60.0;
if (VDy==0) VDy=1;
if (VDx==0) VDx=1;
CVAng=(int) (57.29578*atan(VDy/VDx));
if (VDx<0) CVAng=180+CVAng; else
if (VDy<0) CVAng=CVAng+360;
CVMod=(int) (sqrt((VDx*VDx)+(VDy*VDy)));


if (CVMod<6) {
if ((CVLum>0) && (CVLum<81)) CVCor=CPreto;
if ((CVLum>80) && (CVLum<=139)) CVCor=CCinza;
if ((CVLum>140) && (CVLum<=255)) CVCor=CBranco;
}
if (CVMod>=6)
{
if ((CVAng>=0) && (CVAng<=26)) CVCor=CVerde;
if ((CVAng>=27) && (CVAng<=49)) CVCor=CCiano;
if ((CVAng>=50) && (CVAng<=125)) CVCor=CAzul;
if ((CVAng>=126) && (CVAng<=184)) CVCor=CRoxo;
if ((CVAng>=185) && (CVAng<=226)) CVCor=CVermelho;
if ((CVAng>=227) && (CVAng<=254)) CVCor=CLaranja;
if ((CVAng>=255) && (CVAng<=275)) CVCor=CAmarelo;
if ((CVAng>=276) && (CVAng<=360)) CVCor=CVerde; }

}

void adjd_read(void)
{ unsigned char response;
unsigned char l,h;
int i;
LigaCor=1;
for (i=0; i!=10;i++) PCON|=1;
if (temavago==1)
{
EEPROM_ByteWrite(0x00, 1); //Get sensor reading
i=0;
response=1;
while(response!=0)
{
response = EEPROM_ByteRead(0x00);
l=response;
i++;
if (i==150) response=0;
}
if (i>100) adjdok=0; else adjdok=1;
if (adjdok==1) {
//Red
l = EEPROM_ByteRead(DATA_RED_LO);
h = EEPROM_ByteRead(DATA_RED_HI);
CorR=l+256*h;
//Green
l = EEPROM_ByteRead(DATA_GREEN_LO);
h = EEPROM_ByteRead(DATA_GREEN_HI);
CorG=l+256*h;
//Blue
l = EEPROM_ByteRead(DATA_BLUE_LO);
h = EEPROM_ByteRead(DATA_BLUE_HI);
CorB=l+256*h;
//Clear
l = EEPROM_ByteRead(DATA_CLEAR_LO);
h = EEPROM_ByteRead(DATA_CLEAR_HI);
CorC=l+256*h;

}

}
LigaCor=0;

}

Lá no main():

if (mandacor) {adjd_read();
defcor();
txs("$COR,"); mandacor=0;
// if (LigaGeral==1) txs("T"); else txs("t");
// if (gpsligado==1) txs("G"); else txs("g");

switch (CVCor)
{
case CPreto: txs("preto"); break;
case CCinza: txs("cinza"); break;
case CBranco: txs("branco"); break;
case CAzul: txs("azul"); break;
case CVerde: txs("verde"); break;
case CCiano: txs("ciano"); break;
case CAmarelo: txs("amarelo"); break;
case CLaranja: txs("laranja"); break;
case CVermelho: txs("vermelho"); break;
case CRoxo: txs("roxo"); break;
}
tx(',');
while(qmanda!=qguarda);
tx3(CVCor); tx(','); //CVCor
tx4(CorR); tx(','); //CorR
tx4(CorG); tx(',');
tx4(CorB); tx(',');
tx3(CVAng); tx(',');
tx4(CVMod); tx(',');
tx4(CVLum);
txsln("");}

opa muito obrigado... agora vou me divertir aqui....

Segue projeto todo.

Ta em Eagle+SilabsIDE+Keil+Delphi

Anexos

vlw meu amigo....

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço