If all we need to do is move the mouse around and click it using the left click button then you really only need to assign five buttons on your remote to the up, down, left, and right mouse movement functions and the click function. Most remotes have a series of four arrow keys with a select button in the center that can be used for clicking. We however are going to go above and beyond and assign as many functions as we can to the Adafruit Mini Remote Control. We are also going to define two different modes of use: one of them for mouse commands and the other for a limited set of keyboard commands mostly arrow keys. The full source code can be found in the next page of this tutorial.

Using the Adafruit Mini Remote Control

Here is an illustration of the commands that we are assigning to the 21 buttons available on our remote. Some of the commands are duplicated in both mouse mode and keyboard mode. You switch modes by pressing the "8" button which is at the lower center of the remote.

If you are using a different remote, you will need to come up with your own layout assigning buttons to functions. You may not want to assign all the buttons we have assigned or you may come up with additional ones that you would like to use.

Below is a section of the code we will use. It defines the 32-bit hex values that are transmitted by the various buttons on the remote. A complete source code listing is given on the last page of the tutorial.

//Codes used by both mouse and arrow modes
#define CodeAlt   0xfd00ff //Vol-
#define CodeCtrl 0xfd807f //Play/Pause
#define CodeShift 0xfd40bf //Vol+
#define CodeRls   0xfda857 //5
#define CodeMode 0xfd9867 //8
//Used by mouse and arrow but have different meanings
#define CodeUp 0xfda05f //Up arrow
#define CodeDown 0xfdb04f //Down arrow
#define CodeLeft 0xfd10ef //Left arrow
#define CodeRight 0xfd50af //Right arrow
//Used only in mouse mode
#define CodeUpLf 0xfd20df //Set up
#define CodeUpRt 0xfd609f //Stop/mode
#define CodeLfClk 0xfd906f //Enter/save
#define CodeDnLf 0xfd30cf //0 10+
#define CodeDnRt 0xfd708f //Repeat
#define CodeLfDrag 0xfd08f7 //1
#define CodeRtDrag 0xfd8877 //2
#define CodeRtClk 0xfd48b7 //3
#define CodeFaster  0xfd28d7 //4
#define CodeScrUp 0xfd6897 //6
#define CodeSlower 0xfd18e7 //7
#define CodeScrDn 0xfd58a7 //9
//Arrow mode only
#define CodeHome 0xfd20df //Set up
#define CodePgUp 0xfd609f //Stop/mode
#define CodeEnter 0xfd906f //Enter/save
#define CodeEnd 0xfd30cf //0 10+
#define CodePgDn 0xfd708f //Repeat
#define CodeGUI 0xfd08f7 //1
#define CodeInsert 0xfd8877 //2
#define CodeDelete 0xfd48b7 //3
#define CodeBkSp 0xfd28d7 //4
#define CodeSpace 0xfd6897 //6
#define CodeEsc 0xfd18e7 //7
#define CodeTab 0xfd58a7 //9

Five of the buttons are available in both mouse and keyboard modes. The three buttons across the top are toggle keys for the Alt, Control, and Shift keys. When you press them once, it holds that modifier key until you press again. You can also press "5" marked "Rls" for "Release". It releases all of the toggle keys as well as releasing any held down mouse buttons for dragging. In addition to the three modifier keys and the release button, the mode switch button "8" is also available in both modes.

Because the keys are toggle keys, I found it easy to forget whether I left the shift key held or not. That's why we need the NeoPixels. The first NeoPixel tells you which mode you are in. If the pixel is off you are in mouse mode. If it is green you are in keyboard mode. If it is red you are holding or dragging the left mouse button. If it is blue you are holding or dragging the right mouse button.

The second NeoPixel indicates key modifier status. Red means Alt is being held. Green means Control is being held. Blue means Shift is being held. If you are familiar with how RGB colors are mixed you can also keep track of multiple conditions. For example if the second pixel is cyan (a mixture of green and blue) you know that both control and shift are being pressed.

The arrow keys are used by both mouse and keyboard. Their function is obvious. In mouse mode we can also move the mouse diagonally using the "Set Up", "Stop/Mode", "Enter/Save", and "0 10+" buttons. In keyboard mode these correspond to Home, End, Page Up and Page Down functions. There are special buttons to change the speed of the mouse. You can scroll the mouse wheel up and down. You can click using left click, right-click or you can drag using left drag or right drag.

Determining Your Own Codes

If you're using a different remote then we are, you will have to determine the codes for your particular remote. In the IRLib "examples" folder is a sketch called "IRrecvDump". You can load that sketch, point your remote at the receiver, and get a dump of the codes zero serial monitor.

If I point my Sony DVD remote at the receiver and press the up arrow button I will get a dump of the raw data. I really only need to be concerned with the top line which reads:

Decoded Sony(2): Value:42BCA (20 bits)
This tells me that I'm using "Sony" protocol. It is the 20 bit variety. The code received was the hex value 0x42bca. You will have to repeat this for every button on your remote that you want to use. Edit the values into the table at the beginning of the IRmouse sketch. For example change the:

#define CodeUp 0xfda05f //Up arrow

to read

#define CodeUp 0x42bca //Up arrow

You also need to change the type of decoder you're using. For example at approximately line 63 change the line:

IRdecodeNEC myDecoder;

to read

IRdecodeSony myDecoder;

Once you have changed all of the codes to suit your remote, you can upload the IRmouse sketch to your device.

This guide was first published on Apr 14, 2015. It was last updated on Apr 14, 2015.

This page (Configuring the Device) was last updated on Mar 09, 2015.

Text editor powered by tinymce.