LusoRobótica - Robótica em Português
Sistemas específicos => Arduino / AVR => Tópico iniciado por: joaopedrocmp em 27 de Dezembro de 2011, 21:58
-
Boas pessoal, tou com uma duvida nestas funções
#include <IRremote.h>
int RECV_PIN = 2;
char stringone[11];
IRrecv irrecv(RECV_PIN);
decode_results results;
char valor[11];
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
irrecv.decode(&results);
if (irrecv.decode(&results)) { //se o receptor IR recebeu um valor,...
if (results.value == 1103032335){ //se esse valor for...
itoa(results.value,valor,10); // convert results.value para string
if (valor.startsWith("103", 1)) { // se "valor" começa com 103 no segundo caracter...
Serial.println("Right"); }
}
}
Serial.println(results.value);
irrecv.resume(); // Receive the next value
}
não sei se o valor esta bem convertido, ou se nao estou a usar bem o startswith
-
result.value retorna um int?
Faz o seguinte:
Onde: if (valor.startsWith("103", 1)) { // se "valor" começa com 103 no segundo caracter...
Serial.println("Right"); }
Substitui por Serial.println(results.value);
-
Boas, quando li a resposta ja tinha arranjado uma solução :)
Obrigado. fica assim:
void loop() {
irrecv.decode(&results);
if (irrecv.decode(&results)) { //se o receptor IR recebeu um valor,...
if (results.value == 1103032335){ //se esse valor for...
String teste= results.value;
if (teste.startsWith("303",3)) {
//faz isto....
}
a função itoa nao era necessaria :)