Hi all!
I am trying to make a project (for my son that loves photography) to rotate a camera a certain amount of degrees and triger it, the goal is to make 360 deg. photos.
To avoid a keyboard I am trying to use a IRremote command to interface with the machine.
Now, my problem is the following:
I am using the IRremote library and try to use " (irrecv.decode(&results))" as function, because, I need also to work with the display and stepping motor, but I get a few errors. Can I use this as a function or I must include the remaining code after close the ' if ' bracket ' } '. The code is below:
Thanks in adbance for your help.
Manuel
#include <DogLcd.h>
// initialize the library with the numbers of the interface pins
DogLcd lcd(9, 10, 11, 12);
#include <IRremote.h>
int receiver = 8; // Conectar IR Receiver na porta digital 8
IRrecv irrecv(receiver); // Criar objeto 'irrecv'
decode_results results;
void setup()
{
lcd.begin(DOG_LCD_M163,0x28);
lcd.clear();
delay(100);
// Serial.begin(9600); // for serial monitor output
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
for(;;)
{
IR_code();
}
IR_code()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
//lcd.print(results.value, DEC); // Imprimir na porta serial o valor do controle
switch(results.value)
{
case 59: lcd.print(" Menu "); break;
case 2107: lcd.print(" Menu "); break;
case 32: lcd.print(" up "); break;
case 2080: lcd.print(" up "); break;
case 33: lcd.print(" down "); break;
case 2081: lcd.print(" down "); break;
case 16: lcd.print(" right "); break;
case 2064: lcd.print(" right "); break;
case 17: lcd.print(" left "); break;
case 2065: lcd.print("left "); break;
case 37: lcd.print(" OK/Enter "); break;
case 2085: lcd.print("OK/Enter "); break;
case 55: lcd.print(" Exit "); break;
case 2103: lcd.print(" Exit "); break;
case 2049: lcd.print(" 1 "); break;
case 1: lcd.print(" 1 "); break;
case 2: lcd.print(" 2 "); break;
case 2050: lcd.print(" 2 "); break;
case 3: lcd.print(" 3 "); break;
case 2051: lcd.print(" 3 "); break;
case 4: lcd.print(" 4 "); break;
case 2052: lcd.print(" 4 "); break;
case 5: lcd.print(" 5 "); break;
case 2053: lcd.print(" 5 "); break;
case 6: lcd.print(" 6 "); break;
case 2054: lcd.print(" 6 "); break;
case 7: lcd.print(" 7 "); break;
case 2055: lcd.print(" 7 "); break;
case 8: lcd.print(" 8 "); break;
case 2056: lcd.print(" 8 "); break;
case 9: lcd.print(" 9 "); break;
case 2057: lcd.print(" 9 "); break;
case 0: lcd.print(" zero "); break;
case 2048: lcd.print(" zero "); break;
default: lcd.print(" other button ");
}
delay(500);
irrecv.resume(); // receive the next value
} // Your loop can do other things while waiting for an IR command
}
}
The error codes it gives are the following:
.cpp: In function 'void loop()':
:64: error: 'IR_code' was not declared in this scope
:65: error: 'IR_code' was not declared in this scope
:70: error: expected ';' before '{' token
:118 error: expected '}' at the end of input
Blocks of code are ended with the opposing curly bracket '}'.
IR_code();
}
What are you trying to do here?
} // Closes the switch
delay(500);
irrecv.resume(); // receive the next value
} // Closes the if
} // Closes the function
} // Not supposed to be here.
#include <DogLcd.h>
// initialize the library with the numbers of the interface pins
DogLcd lcd(9, 10, 11, 12);
#include <IRremote.h>
int receiver = 8; // Conectar IR Receiver na porta digital 8
IRrecv irrecv(receiver); // Criar objeto 'irrecv'
decode_results results;
void setup()
{
lcd.begin(DOG_LCD_M163,0x28);
lcd.clear();
delay(100);
// Serial.begin(9600); // for serial monitor output
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
IR_code();
}
void IR_code()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
//lcd.print(results.value, DEC); // Imprimir na porta serial o valor do controle
switch(results.value)
{
case 59:
lcd.print(" Menu ");
break;
case 2107:
lcd.print(" Menu ");
break;
case 32:
lcd.print(" up ");
break;
case 2080:
lcd.print(" up ");
break;
case 33:
lcd.print(" down ");
break;
case 2081:
lcd.print(" down ");
break;
case 16:
lcd.print(" right ");
break;
case 2064:
lcd.print(" right ");
break;
case 17:
lcd.print(" left ");
break;
case 2065:
lcd.print("left ");
break;
case 37:
lcd.print(" OK/Enter ");
break;
case 2085:
lcd.print("OK/Enter ");
break;
case 55:
lcd.print(" Exit ");
break;
case 2103:
lcd.print(" Exit ");
break;
case 2049:
lcd.print(" 1 ");
break;
case 1:
lcd.print(" 1 ");
break;
case 2:
lcd.print(" 2 ");
break;
case 2050:
lcd.print(" 2 ");
break;
case 3:
lcd.print(" 3 ");
break;
case 2051:
lcd.print(" 3 ");
break;
case 4:
lcd.print(" 4 ");
break;
case 2052:
lcd.print(" 4 ");
break;
case 5:
lcd.print(" 5 ");
break;
case 2053:
lcd.print(" 5 ");
break;
case 6:
lcd.print(" 6 ");
break;
case 2054:
lcd.print(" 6 ");
break;
case 7:
lcd.print(" 7 ");
break;
case 2055:
lcd.print(" 7 ");
break;
case 8:
lcd.print(" 8 ");
break;
case 2056:
lcd.print(" 8 ");
break;
case 9:
lcd.print(" 9 ");
break;
case 2057:
lcd.print(" 9 ");
break;
case 0:
lcd.print(" zero ");
break;
case 2048:
lcd.print(" zero ");
break;
default:
lcd.print(" other button ");
}
delay(500);
irrecv.resume(); // receive the next value
} // Your loop can do other things while waiting for an IR command
}
I apologise because, it may be stupid a question, but, I have very litle knowledge of C++ and I do not know where I insert the remaining code? This sketch is has a lot of code that is not familiar to me.
I only know write the very basic code.
I just fixed your code based on what Arrch found and posted the whole thing again. You could replace your code with my post and it probably will compile (if I not forgot another bug).
You have at least two options: replace or extend the lcd.print(...) statements by a function call to do whatever you like. Or you may just set some status variable and react later in the loop() function to it.
Thanks for your inputs now and for some other times that you helped me. I am going to include more function calls in the loop. What I want is to get from this function the key pressed, in the IR command, display it and use it to do other stuff, like get the number of degrees to run the motor, etc.