1 | // Any copyright is dedicated to the Public Domain.
|
2 | // http://creativecommons.org/publicdomain/zero/1.0/
|
3 |
|
4 | /*********************************************
|
5 | This infrared module example transmits the
|
6 | power signal sequence of an Insignia brand
|
7 | television every three seconds, while also
|
8 | listening for (and logging) any incoming
|
9 | infrared data.
|
10 | *********************************************/
|
11 |
|
12 | var tessel = require('tessel');
|
13 | var infraredlib = require('../');
|
14 | var infrared = infraredlib.use(tessel.port['A']); // Replace '../' with 'ir-attx4' in your own code
|
15 |
|
16 | // When we're connected
|
17 | infrared.on('ready', function() {
|
18 | if (!err) {
|
19 | console.log("Connected to IR!");
|
20 | // Start sending a signal every three seconds
|
21 | setInterval(function() {
|
22 | // Make a buffer of on/off durations (each duration is 16 bits)
|
23 | var powerBuffer = new Buffer([0x22,0xc4,0xee,0xd0,0x2,0x58,0xfe,0xc,0x2,0x8a,0xf9,0xf2,0x2,0x8a,0xf9,0xc0,0x2,0x58,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x8a,0xfe,0x3e,0x2,0x8a,0xfe,0x3e,0x2,0x8a,0xf9,0xc0,0x2,0x58,0xf9,0xc0,0x2,0x8a,0xfe,0x3e,0x2,0x8a,0xf9,0xc0,0x2,0x58,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x8a,0xfe,0x3e,0x2,0x8a,0xf9,0xc0,0x2,0x58,0xf9,0xc0,0x2,0x8a,0xf9,0xf2,0x2,0x8a,0xf9,0xc0,0x2,0x58,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x8a,0xfe,0x3e,0x2,0x8a,0xfe,0x3e,0x2,0x8a,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x58,0xfe,0xc,0x2,0x58,0xf9,0xc0,0x2,0x8a,0xf9,0xc0,0x2,0x58,0xf9,0xc0,0x2,0x58,0xf9,0xc0,0x2,0x58]);
|
24 | // Send the signal at 38 kHz
|
25 | infrared.sendRawSignal(38, powerBuffer, function(err) {
|
26 | if (err) {
|
27 | console.log("Unable to send signal: ", err);
|
28 | } else {
|
29 | console.log("Signal sent!");
|
30 | }
|
31 | });
|
32 | }, 3000); // Every 3 seconds
|
33 | } else {
|
34 | console.log(err);
|
35 | }
|
36 | });
|
37 |
|
38 | // If we get data, print it out
|
39 | infrared.on('data', function(data) {
|
40 | console.log("Received RX Data: ", data);
|
41 | });
|