ir control with button pad
hi, i`m setting 20 key button pad , infrared transmitter using library`s irlib.h , keypad.h control devices. seems working have keep pushing buttons volume , volume down on button pad. there way hold them down volume keep changing until release button. code is: buttons are u , d down @ bottom of code. thanks
code: [select]
#include <keypad.h>
#include <irlib.h>
irsend my_sender;
const byte rows = 5;
const byte cols = 4;
// define keymap
char keys[rows][cols] = {
{'f','g','#','*'},
{'1','2','3','u'},
{'4','5','6','d'},
{'7','8','9','b'},
{'<','0','>','e'}
};
// connect keypad row4, row3, row2 row1 , row0 these arduino pins.
byte rowpins[rows] = {4, 5, 6, 7, 8};
// connect keypad col0, col1, col2 , col3 these arduino pins.
byte colpins[cols] = {13, 12, 11, 10};
// create keypad
keypad kpd = keypad( makekeymap(keys), rowpins, colpins, rows, cols );
void setup()
{
serial.begin(9600);
}
void loop()
{
char key = kpd.getkey();
if(key) // check valid key.
{
switch (key)
{
case '1':
my_sender.send(nec,0xff6897, 32);
break;
case '2':
my_sender.send(nec,0xff9867, 32);
break;
case '3':
my_sender.send(nec,0xffb04f, 32);
break;
case '4':
my_sender.send(nec,0xff30cf, 32);
break;
case '5':
my_sender.send(nec,0xff18e7, 32);
break;
case '6':
my_sender.send(nec,0xff7a85, 32);
break;
case '7':
my_sender.send(nec,0xff10ef, 32);
break;
case '8':
my_sender.send(nec,0xff38c7, 32);
break;
case '9':
my_sender.send(nec,0xff5aa5, 32);
break;
case '0':
my_sender.send(nec,0xff4ab5, 32);
break;
case '*':
my_sender.send(nec,551489775, 32); //tv power button
break;
case '#':
my_sender.send(nec,0xff52ad, 32);
break;
case 'f':
my_sender.send(nec,0xff629d, 32); //up button on remote
break;
case 'g':
my_sender.send(nec,0xffa857, 32); //down button on remote
break;
case '<':
my_sender.send(nec,0xff22dd, 32); //left button on remote
break;
case '>':
my_sender.send(nec,0xffc23d, 32); //right button on remote
break;
case 'e':
my_sender.send(nec,0xff02fd, 32); //ok button on remote
break;
case 'u':
my_sender.send(nec,551502015, 32); //tv volume up
break;
case 'd':
my_sender.send(nec,551534655, 32); //tv volume down
}
{
serial.println(key);
}
}
}
some remotes send same code on , over. some send special 'repeat' code. you might need figure out original remote does.
to repeat key, try:
to repeat key, try:
code: [select]
void loop()
{
char key = kpd.getkey();
if(key) // check valid key.
{
while (kpd.ispressed(key)) {
switch (key)
{
Arduino Forum > Using Arduino > Programming Questions > ir control with button pad
arduino
Comments
Post a Comment