#include <IRremote.h> //gebruikt timer2
class IrRemote{
public:
IrRemote(int irPin); // This is the constructor
long check();
private:
IRrecv *irrecv;
decode_results *results;
};
// Member functions definitions including constructor
IrRemote::IrRemote(int irPin) {
irrecv = new IRrecv(irPin);
results = new decode_results;
irrecv->enableIRIn(); // Start the receiver
}
long IrRemote::check(){
while(irrecv->decode(&&results)){
irrecv->resume(); // Receive the next value
long data = results->value;
Serial.print("Irdata: ");
Serial.println(data);
return data;
}
}//end check
IrRemote irRemote(39);
void setup() {Wh
Serial.begin(9600);
}
void loop() {
unsigned long irData = irRemote.check();
if (irData >0){
//Serial.println(irData);
}
}
the decode_results seems to be a pointer, so i create a pointer to a pointer? then i should call it like &&results? Arduino IDE says not.. What am i doing wrong?
Does that mean i have to declare the ir object outside of the class? i would like to do it within the class
In the meanwhile i found a solution. Don't know why it works, but its does:
* return val van GET:
* 99 = power
* 1 t/m 9 = 1t/m9
* 0 = 10
* 20 = UP
* 21 = DOWN
* 22 = LEFT
* 23 = RIGHT
*
*
*
*/
#include <IRremote.h> //gebruikt timer2
class IrRemote{
public:
IrRemote(int irPin); // This is the constructor
long check();
void init();
long get();
private:
IRrecv *irrecv;
decode_results *results;
};
// Member functions definitions including constructor
IrRemote::IrRemote(int irPin) {
irrecv = new IRrecv(irPin);
results = new decode_results;
}
void IrRemote::init(){
irrecv->enableIRIn(); // Start the receiver
}
long IrRemote::check(){
while(irrecv->decode(results)){
irrecv->resume(); // Receive the next value
return results->value;
}
return 0; //if no data send then retrun 0
}//end check
long IrRemote::get(){
long val = check();
if(val >0){
switch (val){
case 1587673095:
return 99;
break;
case 1587636375:
return 1;
break;
case 1587643260:
return 2;
break;
case 1587652695:
return 3;
break;
case 1587671055:
return 4;
break;
case 1587648615:
return 5;
break;
case 1587620565:
return 6;
break;
case 1587610620:
return 7;
break;
case 1587615975:
return 8;
break;
case 9:
return 9;
break;
case 1587667230:
return 10;
break;
case 1587657030:
return 20;
break;
case 1587624390:
return 21;
break;
case 1587673350:
return 22;
break;
case 1587640710:
return 23;
break;
}
}
return 0;
}
IrRemote irRemote(39);
void setup() {
Serial.begin(9600);
irRemote.init();
}
void loop() {
long irData = irRemote.get();
if (irData >0){
Serial.println(irData);
}
delay(150);
with irRemote.get() i can check if there is a new command from the remote. it returns ether a button nr or 0 if nothing.
Your original post didn't include the actual compiler errors. And this one doesn't explain what part you don't understand. So, kind of hard to provide any meaningful help.