Pages: [1]   Go Down
Author Topic: IR Remote Serial Messaging System  (Read 648 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been experimenting with Ken Shirriff's IR remote library and created a lot of totally pointless IR-controlled gadgets. This is probably the best one. It enables you to send messages to the serial port via your TV remote, or other IR remote (as long as it has enough keys). I like to use it with the serial reader that I created with Processing, which displays data in random colors rather than the boring black of the one in the SDK. I have enclosed images of the system as well as the serial terminal, and code for both.
Arduino code:
Code:
include <IRremote.h>
const int irPin = A0; //IR in pin
IRrecv irrecv (irPin); //Create IR receiving
decode_results results; //object on irPin (A0)
char alphabet[27] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ' '};
int alphabetCodes[27] = {
  2708389951, //Values for certain
  2708344051, //keys that are assigned
  2708387911, //to certain letters.
  2708355271, //Replace these with
  2708359351, //values from your remote.
  2708382811,
  2708342011,
  2708396071,
  2708374651,
  2708350171,
  2708376691,
  2708346091,
  2708399131,
  2708380771,
  2708397091,
  2708364451,
  2708398111,
  2708352211,
  2708368531,
  2708384851,
  2708360371,
  2708357311,
  2708373631,
  2708340991,
  2708393011,
  2708343541,
  2708396581
};
int oldVal = 0; //These two variables store
int val = 0; //numbers decoded from the remote
void setup () {
  Serial.begin (9600);
  irrecv.enableIRIn (); //enable decoding
}
void loop () {
  if (irrecv.decode (&results)) { //check if IR data is received
    val = results.value; //If so, set val to decoded data
    irrecv.resume (); //keep receiving
  }
  if (val != oldVal) { //make sure a single key is not being held down
    for (int i = 0; i < 27; i++) {
      if (val == alphabetCodes[i]) { //check if val is equal to the code for a certain character
        Serial.print (alphabet[i]); //If so, print out the appropriate character to the Serial Monitor
      }
    }
  }
  oldVal = val;
}

Processing code for serial terminal:
Code:
import processing.serial.*;
String data = "";
int pos = 10;
void setup () {
  size (1280, 760);
  background (0);
  fill (0, 150, 75);
  smooth ();
  Serial input = new Serial (this, Serial.list ()[0], 9600);
}
void draw () {
  fill (random (255), random (255), random (255));
}
void serialEvent (Serial input) {
  data = input.readString ();
  if (data != null) {
    data = trim (data);
    text (data, pos, 20);
    pos += 8;
  }
}
I hope everyone likes this.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, I forgot the images.


* Serial terminal.png (8.54 KB, 380x74 - viewed 64 times.)
Logged

Pages: [1]   Go Up
Jump to: