Estou usando a função Millis para ligar os leds em um determinado tempo em que eu usuário irei definir. ate esse ponto meu código ta funcionando, o problema  e a segunda fase do meu projeto

é saber o status dos leds se estão ligados ou desligados..

não sei como fazer...

Vou colocar meu código queria uma ajudas de vcs..

Obrigado!!!

#define RELE3 11
#define RELE2 12
#define RELE1 13

// VETORES PARA RECEBER VALORES DIGITADOS
char concs[3] = "";
char concm[3] = "";
char conch[3] = "";
char vet[12] = "";
char vet2[3] = "";
char concR[2] = "";

//VARIAVEIS REFERENTE AO TEMPO
boolean recebido = false;
unsigned long tempos = 0;
unsigned long tempom = 0;
unsigned long tempoh = 0;
unsigned long tempoT = 0;
unsigned long tempo;
unsigned long corrente = 0;
int nums = 0;
int numm = 0;
int numh = 0;

// VARIAVEIS NA CONDICAO DO WHILE PARA VERIFICAR
// SE OS RELES ESTA LIGADO OU DESLIGADO
int verifica = 0;
int condicao = 0;
int cont = 0;
int cont1= 0;
int cont2= 0;
int cont3= 0;


void setup ()
{

pinMode(RELE1,OUTPUT); // Inicia o pino de saida
pinMode(RELE2,OUTPUT); // Inicia o pino de saida
pinMode(RELE3,OUTPUT); // Inicia o pino de saida
Serial.begin(9600);

//Finalizar os vetores
concR [1]='\0';
concs [2]='\0';
conch [2]='\0';
concm [2]='\0';
vet[11]='\0';
vet2[2] ='\0';

Serial.println(" Protocolo de Especificacao");
Serial.println(" [L1:000000] ");
}

void loop()
{
tempo = millis();

if(Serial.available() > 0)
{
recebido = true;

for (int i=0; i<11; i++)
{
//Armazena na string (array de char)
vet[i] = Serial.read();
delay(10);
}
Serial.println(vet);

// Entrada da Hora
conch [0] = vet[4];
conch [1] = vet[5];
//converte string em inteiro
numh = atoi(conch);
tempoh = numh;
Serial.print(tempoh);
Serial.print(":");
//Entrada do Minuto
concm [0] = vet[6];
concm [1] = vet[7];
//converte string em inteiro
numm = atoi(concm);
tempom = numm;
Serial.print(tempom);
Serial.print(":");

// Entrada do Segundo
concs [0] = vet[8];
concs [1] = vet[9];
// converte string em inteiro
nums = atoi(concs);
tempos = nums;
Serial.println(tempos);
tempoh *= 3600;
tempom *= 60;

tempoT = tempoh + tempom +tempos;
tempoT *= 1000;
Serial.println(tempoT);
corrente = millis();
}

// ****************************************************//
// processamento dos dados recebidos para ligar ou desligar
// os RELES
if(recebido == true)
{
// Condiçoes para de entrada para ligar os RELES
// e verificação dos comandos digitados.
if( vet[1]== 'L')
{
if(vet[2] == '1')
{
if(tempo - corrente == tempoT)
{
Serial.println(tempo - corrente);
digitalWrite(RELE1,HIGH);
recebido = false;
}
}

if(vet[2] == '2')
{
if(tempo - corrente == tempoT)
{
Serial.println(tempo - corrente);
digitalWrite(RELE2,HIGH);
recebido = false;
}

}

if(vet[2] == '3')
{
if(tempo - corrente == tempoT)
{
Serial.println(tempo - corrente);
digitalWrite(RELE3,HIGH);
recebido = false;
}

}
// condiçao para ligar todos os reles
if(vet[2] == '4')
{
if(tempo - corrente == tempoT)
{
Serial.println(tempo - corrente);
digitalWrite(RELE1,HIGH);
digitalWrite(RELE2,HIGH);
digitalWrite(RELE3,HIGH);
recebido = false;
}
}

// condiçao para ligar o rele 1 e 2
if(vet[2] == '5')
{
if(tempo - corrente == tempoT)
{
digitalWrite(RELE1,HIGH);
digitalWrite(RELE2,HIGH);
recebido = false;
}
}

// condiçao para ligar o rele 1 e 3
if(vet[2] == '6')
{
if(tempo - corrente == tempoT)
{
digitalWrite(RELE1,HIGH);
digitalWrite(RELE3,HIGH);
recebido = false;
}
}
// Condiçao para ligar o rele 2 e 3
if(vet[2] == '7')
{
if(tempo - corrente == tempoT)
{
digitalWrite(RELE2,HIGH);
digitalWrite(RELE3,HIGH);
recebido = false;
}
}
}
/************ FIM DO IF LIGAR ***********************/
// Condiçoes para de entrada para desligar os RELES
// e verificação dos comandos digitados.
if( vet[1] == 'D')
{
if(vet[2] == '1')
{
if(tempo - corrente == tempoT)
{
digitalWrite(RELE1,LOW);
recebido = false;
}

}
if(vet[2] == '2')
{
if(tempo - corrente == tempoT)
{
digitalWrite(RELE2,LOW);
recebido = false;
}

}
if(vet[2] == '3')
{
if(tempo - corrente == tempoT)
{
digitalWrite(RELE3,LOW);
recebido = false;
}
}

// condiçao para ligar todos os reles
if(vet[2] == '4')
{
if(tempo - corrente == tempoT)
{
digitalWrite(RELE1,LOW);
digitalWrite(RELE2,LOW);
digitalWrite(RELE3,LOW);
recebido = false;
}
}
// condiçao para ligar o rele 1 e 2
if(vet[2] == '5')
{
if(tempo - corrente == tempoT)
{
digitalWrite(RELE1,LOW);
digitalWrite(RELE2,LOW);
recebido = false;
}
}

// condiçao para ligar o rele 1 e 3
if(vet[2] == '6')
{
if(tempo - corrente == tempoT)
{
digitalWrite(RELE1,LOW);
digitalWrite(RELE3,LOW);
recebido = false;
}
}
// Condiçao para ligar o rele 2 e 3
if(vet[2] == '7')
{
if(tempo - corrente == tempoT)
{
digitalWrite(RELE2,LOW);
digitalWrite(RELE3,LOW);
recebido = false;
}
}
}
/************** FIM DO IF DESLIGAR ***************/

// Verificacao do status do RELE
if(vet[1] == 'R')
{

if(vet[2] == '1')
{
cont1 = digitalRead(RELE1);
if(cont == 1)
Serial.println("Relay 1 Ligado");
else
Serial.println("Relay 1 Desligado");
recebido = false;
}

if(vet[2] == '2')
{
cont2 = digitalRead(RELE2);
if(cont2 == 1)
Serial.println("Relay 2 Ligado");
else
Serial.println("Relay 2 Desligado");
}

if(vet[2] == '3')
{
cont3 = digitalRead(RELE3);
if(cont3 == 1)
Serial.println("Relay 3 Ligado");
else
Serial.println("Relay 3 Desligado");
recebido = false;
}
if(vet[2] == '4')
{
cont1 = digitalRead(RELE1);
if(cont1 == 1)
Serial.println("Relay 1 Ligado");
else
Serial.println("Relay 1 Desligado");

cont2 = digitalRead(RELE2);
if(cont2 == 1)
Serial.println("Relay 2 Ligado");
else
Serial.println("Relay 2 Desligado");

cont3 = digitalRead(RELE3);
if(cont3 == 1)
Serial.println("Relay 3 Ligado");
else
Serial.println("Relay 3 Desligado");
recebido = false;
}
}
}
/**************** FIM DO IF TRUE ******************/

}

Exibições: 265

Responder esta

Respostas a este tópico

A melhor forma é armazenar o estado dos LEDs em variáveis.

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço