Tuesday 4 September 2012

Simple Stick User Guide - Working with the IR LED

Simple Stick User Guide - Working with the IR LED

The IR LED on board the Simple Stick lets you generate Remote Control Signals using your Simple Stick. Given the Simple Stick's stick format, this opens up a number of interesting possibilities... " say, you are working on your laptop in a coffee shop.. and you find the program on the television to be boring.. voila! there comes the Simple Stick, program it and zap the channels on the TV ;) " thats the kind of possibilities... (thats just a crazy example! we take no responsibility for the consequences you might end up in as a result of this!) you can take it upto building a 2-way communication system between 2 laptops using Simple Stick!

The IR led is connected to PIN 9 of the Simple Stick which is a PWM pin.

You can use the IRRemote Library [part of the simplestick_demo_code.rar] and program the IR LED to generate remote control signals.

To check, open the IrSendDemo example from under File -> Examples -> IRRemote

Now there are only 2 lines code required,
First creating an IRsend object and then using the IRsendobject.send function

IRsend irsend; // This line creates an IRsend object

irsend.sendSony(0xa90, 12); // This line sends the Power On/Off code of Sony 12bit remote controls


for sending signal using other protocols (NEC, RC5, etc..) the following functions are available

sendNEC(unsigned long data, int nbits)
sendSony(unsigned long data, int nbits)
sendRC5(unsigned long data, int nbits)
sendRC6(unsigned long data, int nbits)
sendPanasonic(unsigned int address, unsigned long data)
sendJVC(unsigned long data, int nbits, int repeat)
sendRaw(unsigned int buf[], int len, int hz)

The IRsend object will automatically use pin 9 on the Simple Stick.
Heres a simple program that sends the sony Power On signal when the push button is being pressed.

IR_Send.ino

#include <IRremote.h>

IRsend irsend;

void setup()
{
  pinMode(11,INPUT_PULLUP);

}

void loop() {
  if (digitalRead(11)==0) {
    for (int i = 0; i < 3; i++) {
      irsend.sendSony(0xa90, 12); // Sony TV power code
      delay(40);
    }
    while(digitalRead(11)==0);
    delay(100);
  }
}

No comments:

Post a Comment