UNPKG

1.91 kBJavaScriptView Raw
1// Any copyright is dedicated to the Public Domain.
2// http://creativecommons.org/publicdomain/zero/1.0/
3
4/*********************************************
5This infrared module example transmits the
6power signal sequence of an Insignia brand
7television every three seconds, while also
8listening for (and logging) any incoming
9infrared data.
10*********************************************/
11
12var tessel = require('tessel');
13var infraredlib = require('../');
14var infrared = infraredlib.use(tessel.port['A']); // Replace '../' with 'ir-attx4' in your own code
15
16// When we're connected
17infrared.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
39infrared.on('data', function(data) {
40 console.log("Received RX Data: ", data);
41});