Oi gente, vou direto ao ponto. Tenho um par de módulos de RF, e dois arduinos. Essa semana fiz os dois se comunicarem e usando char tudo ocorreu bem, enviei uma mensagem e consegui receber sem problemas. Mas o problema é o seguinte não consigo comparar os valores que recebo para ligar um led por exemplo.!
código do meu transmissor!
#include <VirtualWire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round
int poten1=4;
int ptvalor1;
int poten2=5;
int ptvalor2;
int pt1,pt2=0;
char buff[6];
char buf[6];
void setup()
{
// Initialise the IO and ISR
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_set_tx_pin(13);
pinMode(poten1, INPUT);
pinMode(poten2, INPUT);
}
void loop()
{
ptvalor1=analogRead(poten1);
ptvalor2=analogRead(poten2);
int msgk = ptvalor1; // numero de teste
int msd=ptvalor2;
itoa(msgk, buff, 10);
itoa(msd, buf, 10);
const char *msg = buff ; // this is your message to send
const char *ms=buf;
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait for message to finish
vw_send((uint8_t *)ms, strlen(ms));
vw_wait_tx();
delay(50);
}
Como vocês podem ver, eu pego os valores de dois potenciômetros, transformo em char e envio.
CODIGO DO RECEPTOR
#include <VirtualWire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round
void setup()
{
Serial.begin(9600);
// Initialise the IO and ISR
// vw_set_ptt_inverted(true);
vw_setup(2000);
vw_set_rx_pin(11 );
vw_rx_start();
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
{
int i;
for (i = 0; i < buflen; i++)
{
Serial.print(buf);
}
Serial.println("");
}
}
Minha pergunta é: como comparar os valores que recebo com alguma coisa ?
tipo:
if(valorrecebido=="t"){
digitalWrite(led,HIGH);
}
Muito obrigado pelas respostas.