4098Views13Replies
How to use IR remote with Arduino LCD menu? Answered
Does anyone know how to edit an Arduino LCD menu sketch to work with an IR remote control instead of using 4 physical buttons? I'm using this menu but I have troubles in editing the code to use the IR remote control...I'm pretty n00b at programming so I need your help guys... Cheers!
Discussions
#include "IRremote.h"
#include "LiquidCrystal.h"
LiquidCrystal lcd(6,7, 8, 9, 10, 11);
int IRpin = A0;
IRrecv irrecv(IRpin);
decode_results RIR;
void setup () {
irrecv.enableIRIn();
lcd.begin(16, 2);
lcd.setCursor(3, 0);
lcd.print("IR Remote");
lcd.setCursor(5, 1);
lcd.print("Sensor");
delay(2000);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("Gayan Sameera");
lcd.setCursor(5, 1);
lcd.print("4S6GGS");
delay(3500);
lcd.clear();
}
void loop () {
if (irrecv.decode(&RIR)) {
irrecv.resume();
}
lcd.setCursor(2, 0);
lcd.print("IR Remote HEX");
lcd.setCursor(4, 1);
lcd.print(RIR.value,HEX);
delay(700);
lcd.clear();
}
you need to have an ir sensor, and code to read from that.
Take a look here this is how I got mine working :)
+1
Get your ir sensor working separately, then put the two sketches together, whenever IR 'key up' would do something, make it call the button press function of the original lcd sketch.
believe me I've tried to combine the sketches but there is something missing. it's about allocating each code received by the sensor to each of the four buttons... it's not hard but it's killing me inside...
just find the code that would be called when a button is pressed, and call that code.
I just looked at the liquidcrystal library, and it doesnt use any spi, i2c, or pwm's that i could see... the ir library should work just fine, just make sure its not on a pin thats being used by the lcd. start with a working example for both the lcd, and ir... then copy the required libraries from one to the other, and add a chunk of code bit by bit until it stops working... at that point you can see whats causing your problems....
ok it looks like you need to swap our your button read code, with conditional's based on the IR codes you recieve.
so something like
void navigateMenus() {
MenuItem currentMenu=menu.getCurrent();
switch (results){
case irEnter:
if(!(currentMenu.moveDown())){ //if the current menu has a child and has been pressed enter then menu navigate to item below
menu.use();
}else{ //otherwise, if menu has no child and has been pressed enter the current menu is used
menu.moveDown();
}
break;
case irEsc:
menu.toRoot(); //back to main
break;
case irRight:
menu.moveRight();
break;
case irPinLeft:
menu.moveLeft();
break;
}
results=0; //reset the lastButtonPushed variable
}
You wont learn anything if we code this completely for you, so you will need to figure this out a bit.
You'll need to define irX variables I used above instead of the buttonvariables you used.
i know that...I have some project using the IR sensor. Check my instructable about the relay module ;).
ok, then I'd need to see your code to help out more...
the lcd may be using the same interrupts/pins/hardware the ir code you are using does.
typically its as simple as copy/pasting the necessary libraries together and code, and it just works :)
actually there is nothing bad about the code... and about libraries. it's about integration the IR option to the original code. I've altered the original code from that site to work on a PCD8544 display (nokia5110) and it's working well... I've tried something like this:
if (value.results==XXXX)
{
(leftButton,HIGH);
} , but didn't worked...
I think you are going to need to post some code... the code above doesnt make much sense? you are checking value.results against something, then it looks like you are doing a digitalread if this statement is true? I have no idea what you are doing here.
If your project isnt working, the code obviously IS bad. im not trying to be a jerk or anything... but its tough to help without seeing the code.
what pin are you trying to read from for the ir library? (and are you using ken's ir library?)...